英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论