Gradio, a Python library for creating interactive web applications for machine learning models, offers developers a variety of options for presenting and using their projects. In addition to local execution and free hosting on Hugging Face Spaces, Gradio also allows applications to run in Docker containers on your own hardware. This option provides additional flexibility and control over the deployment environment.
Using Docker for Gradio applications offers several advantages:
Dockerizing a Gradio application is straightforward. A simple example illustrates the necessary steps:
app.py
) contains the code of the Gradio application.docker build
and docker run
commands. The application is then accessible via the specified port.There are a few things to keep in mind when running Gradio applications in Docker:
GRADIO_SERVER_NAME
must be set to 0.0.0.0
to allow connections from outside the container. Port 7860 must be exposed in the Dockerfile (EXPOSE 7860
).sessionAffinity: ClientIP
) is important to ensure that all requests from a user are directed to the same instance. This is necessary for the correct processing of events in Gradio.Every Gradio application can serve as an API endpoint for downstream processes. Information about the available endpoints and their parameters can be obtained via the application's API documentation, which is accessible via a link in the application's footer. The endpoints can be accessed with various clients, such as Python or JavaScript.
Docker integration and API functionality significantly expand the possible uses of Gradio. Developers can flexibly deploy their AI applications on their own hardware, integrate them into existing systems, and thus optimally utilize the advantages of Docker, such as consistency, portability, and scalability. The easy creation of API endpoints also enables seamless integration of the applications into complex workflows.
Bibliographie: https://www.gradio.app/guides/deploying-gradio-with-docker https://www.gradio.app/guides/using-hugging-face-integrations https://huggingface.co/docs/hub/spaces-sdks-gradio https://www.gradio.app/guides/sharing-your-app https://huggingface.co/docs/hub/spaces-sdks-docker https://discuss.huggingface.co/t/deploy-gradio-app-on-my-own-server-machine-fails/41808 https://blog.runpod.io/run-huggingface-spaces-on-runpod/ https://huggingface.co/learn/cookbook/enterprise_cookbook_gradio ```