API/predict

#11
by Yosun - opened

Hi! Awesome space... Can you please expose the API? Can make super awesome Unity apps with this... Thanks :)

{
"error": "This app has no endpoint /api/predict/."
}

Hi @Yosun Thanks for the suggestion. I've just updated the Space.

hysts changed discussion status to closed

cool thanks for the quick response! btw what is the base URL for the returned results in data->name ? (And would this base URL change?)

{
    "data": [
        {
            "name": "/tmp/gradio/b2a340c9cc58d722018bb9565557bc584d027ae2/tmpxestxnwx.glb",
            "data": null,
            "is_file": true
        }
    ],
    "is_generating": false,
    "duration": 5.956872224807739,
    "average_duration": 9.312528014183044
}
Yosun changed discussion status to open

Chrome inspected... Just to confirm the base URL would always be: https://hysts-shap-e.hf.space/file=

@Yosun
Hmm, sorry, I'm not sure if I understand what you mean.
Are you using REST API? I thought that the REST API had been removed, but maybe it has just been deprecated but is still available.
From what I understand, the REST API doesn't respect the queue and could cause GPU OOM and crash the Space, so I'd appreciate it if you could avoid using it even if it's still available.

The recommended way to use a Space as an API is to use gradio_client like this:

from gradio_client import Client

client = Client('hysts/Shap-E')
result = client.predict('a penguin', 0, 15, 75, api_name='/text-to-3d')

By doing this, the result .glb file will be downloaded to your local environment, and this result will be its file path. e.g. '/tmp/tmpiba0rayhhkpw6fvt.glb'

The Space name hysts/Shap-E might be changed in the future, for example, if the paper authors want us to transfer this Space to their organization. But the URL will work by redirecting, so I guess it will work even after doing so.
(BTW, the GPU grant will probably be removed when the usage rate dropped, like in a few months maybe?, so it might be the bigger issue for your app than the URL.)

I notice that some requests take much longer, especially when there is a queue. Can you add a REST endpoint that immediately returns a callback URL and status that can be checked at a later time for the results?:

{"status": "running", "callback": "[callback url]"}

Ooh I was just told that all HF gradio spaces have a REST API as an option... I did not know that the API access does not follow a queue and could crash the system..

So I'm still running it as a REST API...

https://hysts-shap-e.hf.space/run/text-to-3d/submit doesn't seem to work but https://hysts-shap-e.hf.space/run/text-to-3d/ does - how do i call the status endpoint from the REST API?

@Yosun Sorry. I don't know how. Maybe you can ask it in the discussions on GitHub or on Discord.

hysts changed discussion status to closed

Sign up or log in to comment