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 (Production)
For the production Gradio Space, use the following endpoint and adjust the payload as needed:
curl.exe -X POST https://boardflare-mcp-client.hf.space/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"}
Then fetch the result with:
curl.exe -N https://boardflare-mcp-client.hf.space/gradio_api/call/predict/YOUR_EVENT_ID
You will see output like:
event: complete
data: [ ... ]
Notes
- For Gradio apps with multiple inputs, adjust the
data
array inpayload.json
accordingly. - 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
path
key pointing to a file URL. - If authentication is required, first POST to
/login
and use the returned cookies in subsequent requests.
Troubleshooting
- Always use single quotes around
@payload.json
in PowerShell to avoid variable expansion errors. - If you get JSON errors, check your
payload.json
formatting. - If you get a 404 or "Not Found" error, check the endpoint path (e.g.,
/gradio_api/call/predict
for local apps).
This guide is based on the official Gradio documentation and adapted for both public and local Windows PowerShell use cases.