Cannot POST /spaces/[myusername]/test/predict

I am very new at this so my terminology might not be up to par. Please, bare with me :wink:

I have setup a space with Gradio

I am also running Gradio locally:

The UI’s seem to worknicely.

I want to access Gradio via the API.

Locally this works fine:

curl -X POST http://127.0.0.1:7860/api/predict \
     -H "Content-Type: application/json" \
     -d '{"data": ["A sunset over a mountain", "", 0, true, 512, 512, 7.5, 5]}'

But when I try to call the API on the Hugging Space like this:

curl -X POST https://huggingface.co/spaces/[myusername]/[spacename]/api/predict \
     -H "Authorization: Bearer [my-hf-token]" \
     -H "Content-Type: application/json" \
     -d '{"data": ["A sunset over a mountain", "", 0, true, 512, 512, 7.5, 25]}'

The following is returned:

<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /spaces/[myusername]/[spacename]/run</pre>
</body>
</html>

I tried all kinds of changes to the app.py file but nothing seems to work.

Any tips?

Try this.