huggingface 期望的输入格式

huangapple go评论92阅读模式
英文:

huggingface expected input format

问题

import gradio as gr
from gradio_client import Client

def greet(name):
    return "Hello " + name + "!!"

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()

client = Client("https://toromanow-test2.hf.space/")
result = client.predict("John", api_name="/predict")
print(result)
英文:

I'm trying to invoke my test hello huggingface app via API:

import gradio as gr

def greet(name):
    return "Hello " + name + "!!"

iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()

I'm able to do this by using the gradio client API:

from gradio_client import Client

client = Client("https://toromanow-test2.hf.space/")
result = client.predict(
"John", # str representing input in 'name' Textbox component
api_name="/predict"
)
print(result)

But I'm unable to invoke it by submitting the POST request directly:

curl -d '{ "data": "John"}' -H "Content-Type: application/json" -X POST https://toromanow-test2.hf.space/api/predict

Errors out with:

{"detail":[{"loc":["body","data"],"msg":"value is not a valid list","type":"type_error.list"}]}

I've experimented with diferent formats but can't figure out the one what works.

答案1

得分: 2

The correct format appears to be: { "data": ["John"] }

curl -d '{ "data": ["John"]}' -H "Content-Type: application/json" -X POST https://toromanow-test2.hf.space/api/predict

英文:

In case it helps someone: the correct format seems to be: { "data": ["John"] }

curl -d '{ "data":  ["John"]}' -H "Content-Type: application/json" -X POST https://toromanow-test2.hf.space/api/predict

huangapple
  • 本文由 发表于 2023年5月11日 07:30:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76223210.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定