Gradio is a Python library that allows you to quickly create customizable UI components around your machine learning models. In this blog post, we'll show you how to build a Gradio Docker image and deploy it publicly in 3 minutes.
The deployment will give you a public URL (similar to
xx.modelz.live) for your model that anyone can use without installing anything on their computer.
After that, you can share your model with others and get feedback on it!
Gradio is a great tool for building machine learning models, but it can be difficult to deploy them. You need to set up a server, install dependencies, and configure everything just right. This process is time-consuming and error-prone. With Docker, you can easily package your model into a container that contains all the necessary dependencies and configuration files. This makes it easy to deploy your model on any machine with Docker installed.
It's easy to create a Gradio app. You can follow the official tutorial to create a Gradio app. Here is an example:
import gradio as gr
return "Hello " + name + "!"
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
After creating a Gradio app, you can build a Gradio Docker image. We provide a
Dockerfile for CPU deployment and a
Dockerfile.gpu for GPU. You can use them directly.
Dockerfile is very simple:
ADD requirements.txt main.py /workspace/
RUN pip install -r /workspace/requirements.txt
CMD ["python", "/workspace/main.py"]
You just need to update the
main.py to your own. Then you could run the command to push it to the Docker Hub:
docker build -t docker.io/USER/IMAGE .
docker push docker.io/USER/IMAGE
After building the Gradio Docker image, you can deploy it. You could pick up a VM from any cloud provider, such as AWS, GCP, Azure, etc. Then you could run the command to deploy it:
$ pip install openmodelz
$ mdz start <your public ip>
$ mdz deploy --image docker.io/USER/IMAGE --port 7860
Then you will get a public URL for your model via
mdz list, such as
xx.modelz.live. OpenModelZ takes care of the rest for you!
In this blog post, we showed you how to build a Gradio Docker image and deploy it publicly in 3 minutes. We hope that this will help you get started with Gradio and make your models more accessible to others. If you have any questions or feedback, please let us know in our Discord server!