Say I have a demo web API that serves product data, like from an online store or something. Each product has customer-entered reviews that I want to do sentiment analysis on so I can say if the review was positive or negative. I want my API to make a fetch request to a service out there somewhere, submit the review sentence and get back the sentiment. I thought I could use Spaces for that. But it seems that Spaces only allows me to host a frontend website.
Does Spaces expose an endpoint that allows HTTP POST requests? How do I access it?
1 Like
For API-like uses, using a dedicated endpoint is more reliable, but it is possible to use Gradio spaces as an API.
1 Like
@John6666 Thanks so much for the response. I read thru them and implemented like so:
demo = gr.Interface(fn=predict, inputs='text', outputs='label')
demo.launch(strict_cors=False, share=True)
The log of my Space then says …
/usr/local/lib/python3.10/site-packages/gradio/blocks.py:2597: UserWarning: Setting share=True is not supported on Hugging Face Spaces
warnings.warn(
To create a public link, set `share=True` in `launch()`.
This is super confusing. It looks like Hugging Face doesn’t allow API access to Spaces. What am I missing?
1 Like
Yea. The warning is confusing, but it’s actually usable, so don’t worry about it. In the case of Private, there are occasional bugs, so it’s better to test with a Public mockup.