Search code examples
pythonrestpostmangradio

How can I call with Postman a RESTful API deployed with Gradio?


I'm following the basic Gradio interface from the Gradio documentation:

import gradio as gr

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

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

demo.launch()

The interface is:

enter image description here

I believe this deploys a RESTful API, since it says "Use via API" in the footer of the interface:

enter image description here

How can I call that RESTful API with Postman?

I tried:

enter image description here

but as the screenshot shows, I'm getting the error message:

{"detail":"Not Found"}

The page that the "Use via API" points to indicate:

enter image description here

but I don't want to use the Gradio client.


Update: using the endpoint http://localhost:7861/api/predict seems to work better, but I am still trying to figure out what the name of the key is:

enter image description here

I tried to add a body but that doesn't work either:

enter image description here


Solution

  • I found the answer on https://github.com/aiplaybookin/gradio-demo:

    Use https://hoppscotch.io or https://www.postman.com/

    In my case:

    enter image description here

    JSON payload:

    {"data": ["test"]}