All guides

Share a Gradio Page and Check Who Can Access It

Use launch(share=True) for a temporary public link, add auth password protection, test access from an unrelated device, check expiry, then stop the service.

AINavWritten / Updated Sources checked
On this page

At a glance

share=True makes the link publicly reachable. Without authentication, anyone holding it can use the app. With auth configured, visitors must authenticate before running the function. This guide shares an authenticated synthetic demo.

Workflow

  1. Exposure layer

    share=True makes the link publicly reachable. Without authentication, anyone holding it can use the app. With auth configured, visitors must authenticate before running the function. This guide shares an authenticated synthetic demo.

  2. Gate layer

    Confirm launch(auth=...) is set, so an unauthenticated visitor sees a login page and not the demo itself.

  3. Expiry and exit layer

    Confirm the link expires after about a week, stops working once your process ends, and that /logout signs a user out.

Each stage cites official sources.

Before you start

  • A working Python environment with Gradio installed.
  • A simple demo function that reads no local files, holds nothing sensitive and changes nothing on your machine.
  • A script file such as share_demo.py, plus a different device or browser for verification.
  • A throwaway username and password for testing only; do not reuse the password of a real account.

1. Decide what the function could expose

Open share_demo.py and read what the function does, line by line. The documentation warns that share links are public, so the function should not expose sensitive information or allow critical changes on your device. Remove anything that reads or writes files or runs commands before sharing.

2. Write the function and run it locally first

Wrap the function with gr.Interface and run it once without any share argument. The default share=False means the server is reachable only on your machine. Confirm input and output behave correctly in your own browser before moving on. After the local input/output check, stop the original local server in its terminal.

3. Turn on sharing and a password together

Change the launch line to demo.launch(share=True, auth=("username", "password")). share=True generates a public link, and auth takes a single account as a tuple; pass a list of tuples for several accounts. The terminal prints the link, which usually looks something like https://07ff8706ab.gradio.live. Save the edited launch line and restart the script. Use the newly generated share link for subsequent checks, then stop this restarted shared process at completion.

4. Verify the gate from another device

Send the printed link to your own second device or a knowing tester. Without logging in, confirm a login page appears; then enter the placeholder credentials and confirm the function works. Authentication needs third-party cookies, which Safari and Chrome Incognito block by default, so if login keeps failing, check that first.

5. Check the data and time boundaries

Processing happens on your device, so your machine must stay on with the script running for others to use the page; the documentation says the share servers are only a proxy and do not store data sent through the app. Also note that the link expires after about a week; if you need longer, consider your own share server or another deployment.

6. Test logout and stop sharing

In a logged-in browser, add /logout after the app address and confirm you are signed out; by default this ends all sessions. When testing is done, interrupt the script in its terminal, then open the old link again and confirm it no longer works. If only specific people need access, the documentation also mentions SSH port-forwarding as an alternative.

Original example

A fully synthetic sample with no real data; the password is a placeholder to replace:

python
import gradio as gr

def greet(name):
    return "Hello " + name + "!"

demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
demo.launch(share=True, auth=("demo_user", "replace-with-temp-password"))

Run it, copy the public link the terminal prints, and open it on another device. You should first see a login page; after entering demo_user and your temporary password, type "Lin" in the textbox and expect "Hello Lin!". Then add /logout to the link to sign out, interrupt the script in the terminal, and refresh the link; it should no longer work. The exact link and page appearance depend on your own run.

Completion checks

  • Without a share argument, the page opens only on your own machine.
  • With share=True, a second device that has not logged in sees a login page.
  • The correct placeholder credentials let the function return a result.
  • /logout ends the login; add all_session=false to sign out only the current session.
  • After the script stops, the old link is dead, and the function touches no local files or sensitive data.
  • Save the edited launch line and restart the script. Use the newly generated share link for subsequent checks, then stop this restarted shared process at completion.

Limits

  • This covers only the temporary share=True link and built-in auth; hosting on HF Spaces, embedding, mounting in FastAPI, OAuth login, MCP servers, rate limits and PWAs are outside this flow.
  • The documentation states built-in authentication is basic access control only, with no multi-factor authentication, rate limiting or automatic lockout, so it does not suit strict access requirements.
  • A hard-coded plain-text password suits short tests only, as in the documentation's example; judge longer use separately, since this guide draws no security conclusion for you.
  • The link lasts about a week and depends on your device staying up; this guide promises no availability, speed or concurrency.

Verification scope

This guide is based on reading the official documentation. I did not log in, install Gradio, run the sample code, execute any product API, upload files or produce generated output; the code is an illustrative sample written to follow the documented pattern and has not been run.

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. Gradio · Official sources
    View details