Spaces:
Sleeping
Using Gradio API with curl.exe on Windows
This guide explains how to interact with any Gradio app as an API using curl.exe from Windows PowerShell. It covers both public Hugging Face Spaces and local Gradio apps.
Prerequisites
- Windows with PowerShell
curl.exe(included in Windows 10+)- The URL of your Gradio app (public or local, e.g., http://127.0.0.1:7860/)
Step 1: Prepare Your Input
Create a file named payload.json in your working directory. For a local MCP Gradio app, the payload might look like:
{
"data": [
"https://mcp.composio.dev/composio/server/ca1477ae-dffb-404c-9021-ef25ff440221/mcp",
"SALESFORCE_RETRIEVE_LEAD_BY_ID",
"{\"id\": \"00QgK0000005yjVUAQ\"}"
]
}
Step 2: Make the POST Request (Local Gradio)
Send your input to the local Gradio API endpoint using this command:
curl.exe -X POST http://127.0.0.1:7860/gradio_api/call/predict -s -H "Content-Type: application/json" -d '@payload.json'
This returns a JSON response with an event_id, e.g.:
{"event_id":"YOUR_EVENT_ID"}
Step 3: Fetch the Result (Local Gradio)
Use the event_id from the previous step to fetch the result:
curl.exe -N http://127.0.0.1:7860/gradio_api/call/predict/YOUR_EVENT_ID
You will see output like:
event: complete
data: [ ... ]
Example for Public Gradio Apps
For public Spaces, use the /call/predict endpoint and adjust the payload as needed:
curl.exe -X POST "https://abidlabs-en2fr.hf.space/call/predict" -H "Content-Type: application/json" -d '@payload.json'
Then fetch the result as above, replacing the URL and event ID.
Notes
- For Gradio apps with multiple inputs, adjust the
dataarray inpayload.jsonaccordingly. - For private Spaces, add your Hugging Face token with
-H "Authorization: Bearer YOUR_TOKEN"to both requests. - For file inputs, use a dictionary with a
pathkey pointing to a file URL. - If authentication is required, first POST to
/loginand use the returned cookies in subsequent requests.
Troubleshooting
- Always use single quotes around
@payload.jsonin PowerShell to avoid variable expansion errors. - If you get JSON errors, check your
payload.jsonformatting. - If you get a 404 or "Not Found" error, check the endpoint path (e.g.,
/gradio_api/call/predictfor local apps).
This guide is based on the official Gradio documentation and adapted for both public and local Windows PowerShell use cases.