Gradio Agents & MCP Hackathon
WinnersGradio Agents & MCP Hackathon
WinnersGradio is a fantastic open-source Python library that allows you to build and share machine learning apps and demos with just a few lines of code. While Gradio offers free hosting on Hugging Face Spaces, you might want to deploy your app on your own server for more control, or to integrate it with other services.
This tutorial will guide you through deploying a Gradio application on your own server using Disco, an open-source platform that simplifies the deployment process. With Disco, you can enjoy the benefits of self-hosting without the usual complexities of server setup and maintenance. By the end, you'll have a working Gradio app deployed on your own server with automatic HTTPS and continuous deployment from GitHub.
Before you begin, make sure you have the following:
First, you'll need a server to host your Gradio app. Choose a provider and create a new server with Ubuntu 24.04 as the operating system.
Once your server is up and running, take note of its IP address. You'll need it for the next step.
Before going further, you need to set up two domain names. Go to your domain registrar's DNS management panel and add these records:
disco.example.com
).gradio.example.com
).For the server domain, create an A record pointing to your server's IP address:
<your_server_ip_address>
For the application domain, create a CNAME record pointing to your server domain:
disco.example.com
DNS changes can take a few minutes to propagate. You can verify that your server domain is resolving to the correct IP address by running ping disco.example.com
Now that your DNS is set up, let's test the SSH connection to your server from your local machine. This ensures you can access it before we hand things over to Disco.
# Replace with your server domain
ssh root@disco.example.com
If the connection is successful, great! This is the last time you'll need to SSH into this server manually. Now, exit the SSH session to return to your local machine. This is a crucial step!
exit
Important: From this point forward, all commands should be run from your local machine's terminal. You will not need to SSH into your server again.
Let's install the Disco command-line interface (CLI) on your local machine. This is the tool you'll use to manage your deployments.
curl https://cli-assets.letsdisco.dev/install.sh | sh
After the installation is complete, verify it's working by running:
disco --version
Now, from your local machine, let's set up Disco on your server using the domain you configured.
# Replace with your server domain
disco init root@disco.example.com
This command will:
Disco will automatically try to use your default SSH keys. If you use a non-standard key, you can specify the path with the -i
flag, like so: disco init -i /path/to/your/ssh/key root@disco.example.com
For this tutorial, we'll use an example Gradio application. Go to this example Gradio app repository on GitHub and click the "Fork" button to create a copy of it in your own GitHub account.
To allow Disco to deploy your application from GitHub, you need to connect your GitHub account. Run the following command on your local machine:
disco github:apps:add
This command will open a browser window where you can authorize Disco with GitHub. You'll need to:
example-gradio-site
).Now you're ready to deploy your Gradio app. We'll use the projects:add
command on your local machine. Below, replace <your_github_username>
with your GitHub username and gradio.example.com
with the application domain you configured earlier.
disco projects:add \
--name gradio-app \
--github <your_github_username>/example-gradio-site \
--domain gradio.example.com
Disco will automatically pull your code from GitHub, build the Docker container, deploy it to your server, and set up HTTPS with Let's Encrypt for your domain.
Once the deployment is complete, open your web browser and navigate to your application's domain: https://gradio.example.com
. You should see your Gradio app running live!
One of the best features of Disco is automatic deployment. Whenever you push changes to your GitHub repository, Disco will detect them, rebuild your application, and deploy it automatically.
To test this, modify the app.py
file in your forked repository, then commit and push the changes to GitHub. Within seconds, your deployed app will be updated.
Congratulations! You have successfully deployed a Gradio application on your own server using Disco. You now have a fully managed deployment pipeline with automatic HTTPS, fast deployments triggered by Git pushes, and complete control over your server and application.
This setup provides the best of both worlds: the flexibility and cost-effectiveness of self-hosting combined with the convenience of a platform-as-a-service. For more advanced configurations and features, be sure to check out the Disco documentation and the Gradio documentation.