Skip to content

Use_webapi #224

Description

@hcscysh

from gradio_client import Client, file
import os
SERVER_URL = "http://192.168.9.58:7860/" # <--- 在这里填入您的服务器 IP 地址
IMAGE_PATH = "./Janus/temp.png" # <--- 在这里填入您的图片路径
QUESTION = "请详细描述这张图片里的内容。"

def call_image_to_text_api(server_url, image_path, question):
if not os.path.exists(image_path):
print(f"❌ 错误:无法找到图片文件,请检查路径是否正确: {image_path}")
return
client = Client(server_url)
image_arg = file(image_path) # 图片文件,使用 file() 包装
question_arg = question # 问题文本
seed_arg = 42 # Seed 值 (与服务器默认值保持一致)
top_p_arg = 0.95 # Top_p 值 (与服务器默认值保持一致)
temperature_arg = 0.1 # Temperature 值 (与服务器默认值保持一致)
result = client.predict(
image_arg,
question_arg,
seed_arg,
top_p_arg,
temperature_arg,
fn_index=0 # 0 对应 multimodal_understanding
)
print(result)

if name == "main":
call_image_to_text_api(SERVER_URL, IMAGE_PATH, QUESTION)

I want to use the code to calling the web_api, but failed, can you supply any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions