1

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.

Ya.
  • 1,671
  • 4
  • 27
  • 53

1 Answers1

1

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
Ya.
  • 1,671
  • 4
  • 27
  • 53
  • Thanks ! It's so awful that it is not documented anywhere, and the Gradio python client is returning a JSON file path instead of a python dict or JSON string... Hopefully we can still do HTTP requests manually. – Grum Aug 10 '23 at 13:17