Skip to main content

Module 8 — Temporary share link

The single most-used feature of Gradio, after the interface itself, is a magic string that turns a local server into a public URL: share=True. It is what makes a colleague on another continent try your demo two minutes after you finish writing it. That convenience deserves a module of its own, because the same magic exposes your laptop to the internet, and the details are worth understanding before pointing a link at your production model.

When you launch with share=True, Gradio opens a reverse SSH tunnel from your machine to gradio.live, a public relay service run by Gradio's team. That relay accepts HTTPS traffic on a random *.gradio.live subdomain and forwards every request back through the tunnel to your local server, which processes the request and returns the response through the same channel.

import gradio as gr

def echo(text):
return text[::-1]

gr.Interface(fn=echo, inputs="text", outputs="text").launch(share=True)

The console prints two URLs when you run this snippet:

Running on local URL:  http://127.0.0.1:7860
Running on public URL: https://abc123xyz.gradio.live

This share link expires in 72 hours.

That "72 hours" is the second sentence to internalize. The tunnel is temporary by design. It stays up as long as your Python process stays up, and the URL is rotated after three days regardless. Restart the app and you get a fresh subdomain, so a share link is not a stable address to hand around a Slack channel; it is a demo passcode.

What is exposed, and what is not

The tunnel forwards HTTP traffic to your Gradio process. Everything the Gradio server exposes — the /api/predict endpoints, the file-upload endpoints, static assets, the /?view=api documentation page — is reachable by anyone who has the URL. Anyone with the link can hit your model as many times as they want, subject only to your queue.

The tunnel does not expose the rest of your machine: files outside your working directory, other local ports, SSH, or anything on your LAN that Gradio does not serve. Gradio confines itself to its port. The risk profile is therefore about the demo, not about the whole computer, and the mitigations are three in number: keep the URL private, add authentication, and shut the server down when the demo ends.

Anything you upload lives briefly on the internet

Files uploaded to a shared demo are stored in Gradio's temporary directory, which is served back to the world through the same tunnel. If your demo returns file paths for images or audio, those paths are downloadable by anyone with the URL for as long as the server runs. That is fine for a public model, but do not run a shared demo that processes private user data unless you can explain the retention and access story.

Simple authentication

For a demo you plan to share only with a small group, the auth parameter of launch adds HTTP basic authentication. Pass a tuple (username, password) or a list of tuples for multiple users, or a callable that returns True for authenticated combinations.

gr.Interface(fn=echo, inputs="text", outputs="text").launch(
share=True,
auth=("client-preview", "9v!nR2fLp4qX"),
auth_message="Enter the credentials from the email.",
)

That is enough to keep a demo out of a random crawler's reach. It is not enough for a production application: HTTP basic auth is not resistant to replay attacks over an intercepted connection, and Gradio does not rotate the credential. For anything more serious than a private preview, put a real reverse proxy in front — Traefik, nginx or Cloud Run's IAM — or host the demo on a Space with member-only access, which module 9 shows.

The server_name and server_port companions

Two other launch parameters shape how the demo is exposed. server_name="0.0.0.0" binds Gradio to every network interface instead of 127.0.0.1, which is what you want inside a container or a VM. server_port=7860 picks the port; change it if 7860 is taken.

demo.launch(server_name="0.0.0.0", server_port=8080, share=False)

server_name="0.0.0.0" and share=True together are a common mistake: the demo becomes reachable both on the local network and through the public tunnel, with no authentication. On a shared corporate Wi-Fi, that is more exposure than most people intended. Pick one channel of publication at a time.

When not to use share=True

The share link is a great tool for the wrong four use cases, and it is worth naming them explicitly.

Long-lived public demos. If your demo needs to stay up for weeks and hold a stable URL, publish it to a Space (module 9). The share link expires and rotates, and requires the Python process to stay running on your machine — a laptop that closes for the weekend takes the demo down.

Sensitive data. Anything a user uploads passes through Gradio's tunnel and lands in a temporary directory. That is acceptable for a public model on public data, unacceptable for medical images, legal contracts or customer PII. Host such demos on infrastructure you control and audit.

High traffic. The tunnel is not sized for a viral tweet. A Space or a proper cloud deployment scales; a share link does not.

A demo you plan to hand to a client. The three-day expiry and the random subdomain look unprofessional. Buy or subdomain a real hostname, host on a Space or a small VM, and give the client a stable URL. The share link is for iteration between engineers, not for the pitch.

A checklist before sharing

Two minutes of pre-flight save hours of embarrassment later. Before you hit share=True and send the link:

  • Confirm the demo does not print API keys or paths that reveal your directory structure — check the console and the ?view=api page.
  • Set a title, description and, if relevant, a short article explaining what the demo is and is not.
  • Add clear examples (module 6) so first-time visitors do not click submit on empty inputs.
  • Rate-limit or cap the queue (max_size from module 7) so a viral link does not run your electricity bill up.
  • Decide when you will close the tunnel, and put a reminder on your calendar.

In summary

  • share=True opens a reverse tunnel through gradio.live and returns a random subdomain that expires in 72 hours.
  • The URL exposes only what Gradio serves — not your whole machine — but that includes every uploaded file for the lifetime of the process.
  • Add auth=(user, pass) for a private preview; use a proper reverse proxy or a Space for anything production-grade.
  • Avoid the share link for long-lived demos, sensitive data, high traffic, or client-facing URLs; each of those has a better answer.

Next module: publishing the demo to a Hugging Face Space, where the URL is stable and the hardware is configurable.