Making POST requests from Gradio

#1
by ola13 - opened

Hi, I wonder if it's possible to achieve similar results with querying an external server with a POST request, but using the Gradio backend. I've attempted a simple implementation of that, but all the requests seem to be timing out.

Thanks!

Templates org

It should be possible to make HTTP requests to an external server. That's what we make for the bloom demo for example - https://huggingface.co/spaces/huggingface/bloom_demo/blob/main/app.py#L18-L22. It's a Gradio app making a POST request to another backend

@ola13 It could be a separate issue, but external requests are timed out at 60 seconds. If you have a long-running action in the external server that takes more than a minute to respond, the solution is:

  • Send a POST request to the server and either have it send a response immediately (if you control the server) or have your Space continue without waiting for the response
  • Keeping sending request to the server at intervals to check status of action and continue accordingly
Templates org

Gradio is not limited to 60 seconds if you enable queue though

I've looked into Gradio timeouts and enabled queuing explicitly (althouhg docs say it's on by default for Spaces?) and I don't think this is the issue.

The server I'm testing is running on my GCP instance, it's not an existing external website. The interesting part is that if I run the Gradio app locally on a (different) GCP instance, then the connection with my server is fine, and everything goes as planned. When I run the Gradio app from huggingface spaces though, I get timeouts. Trying to debug this now - let me know if you have any ideas.

Templates org

Feel free to share a colab with this, that way we can play a bit with it and see what might be the issue :)

Templates org

You can add debug=True in the Gradio demo as well to get logs of the errors.

After a debugging session with @osanseviero and other amazing folks at Hugging Face it turned out that the issue was with the port I was exposing for my server - if anyone finds themselves in the same position here's a note on networking constraints https://huggingface.co/docs/hub/spaces-overview#networking :)

ola13 changed discussion status to closed
Templates org

thanks for documenting @ola13 !

and @NimaBoscarino too :) <3

Sign up or log in to comment