This repo is a fork of the Fast Reverse Proxy (FRP) implementation that is running on Gradio's Share Server to enable Gradio's Share links.
When you create a Gradio app and launch it with share=True
like this:
import gradio as gr
app = gr.Interface(lambda x: x, "image", "image")
app.launch(share=True)
you get a share link like: https://07ff8706ab.gradio.live
, and your Gradio app is now accessible to anyone through the Internet (for up to 72 hours).
How does this happen? Your Gradio app runs on a Python server locally, but we use FRP to expose the local server to the Internet. FRP consists of two parts:
- FRP Client: this runs on your machine. We package binaries for the most common operating systems, and the FRP Client for your system is downloaded the first time you create a share link on your machine)
- FRP Server: this runs on Gradio's Share Server, but since the FRP Server is open-source, you can run it on your own server as well!
You might want to run your own server for several reasons:
- Custom domains: Instead of
*.gradio.live
, you can use any domain your heart desires and that you actually own - Longer links: when you run your own Share Server, you don't need to restrict share links from expiring after 72 hours
- Security / privacy: by setting up your own Share Server in your virtual private cloud, you can make your information security team happy
Its also quite straightforward. In your Gradio app, the only change you'll make is passing in the IP address to your share server, as the share_server_address
parameter in launch()
:
import gradio as gr
app = gr.Interface(lambda x: x, "image", "image")
app.launch(share=True, share_server_address="44.237.78.176:7000")
And voila!
Running on your Share Server: https://07f56cd0f87061c8a1.yourorganization.com
- Have a server (e.g. EC2 machine on AWS) that is running Linux and connected to the Internet. Most servers (e.g. a
t2-small
) should do, we recommend having at least 2 GB of RAM and 8 GB of disk space.
If you are running Ubuntu, you can do this by running these commands sequentially in the terminal:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
sudo apt install docker-ce
Confirm that you Docker has been installed and you are running version 20.10
or higher by running: docker version
in the terminal. You should see something like:
Client: Docker Engine - Community
Version: 24.0.6
...
git clone [email protected]:huggingface/frp.git
cd frp
Note: you may need sudo
permissions for these commands:
docker build -f dockerfiles/Dockerfile-for-frps -t frps:0.2 .
docker run --log-opt max-size=100m --memory=1G --cpus=1 --name frps3 -d --restart unless-stopped --network host -v ~/frp/scripts:/etc/frp frps:0.2 -c /etc/frp/frps.ini
In order to
That's it! You now have your own little Share Server! As mentioned earlier, you can use it by passing the IP address and FRPS port as the share_server_address
parameter in launch()
like this:
import gradio as gr
app = gr.Interface(lambda x: x, "image", "image")
app.launch(share=True, share_server_address="44.237.78.176:7000")
Once you've set up your Share Server, you can