Deploying Gradio Apps
From instant sharing with a public URL to permanent deployment on Hugging Face Spaces - learn every way to get your Gradio app in front of users.
Instant Sharing with share=True
The fastest way to share your Gradio app is with a single parameter:
demo.launch(share=True) # Output: # Running on local URL: http://127.0.0.1:7860 # Running on public URL: https://abc123.gradio.live # This share link expires in 72 hours.
Hugging Face Spaces
For permanent, free hosting, deploy to Hugging Face Spaces:
-
Create a Space
Go to
huggingface.co/new-space, select "Gradio" as the SDK, and choose a name. -
Add Your Files
Push your
app.pyandrequirements.txtto the Space repository. -
Automatic Deployment
Hugging Face builds and deploys your app automatically on every git push.
# Clone your Space git clone https://huggingface.co/spaces/YOUR_USERNAME/my-app cd my-app # Add your files cp ../app.py . cp ../requirements.txt . # Push to deploy git add . && git commit -m "Initial deploy" && git push
API Access
Every Gradio app automatically exposes a REST API:
from gradio_client import Client # Connect to a running Gradio app client = Client("https://your-space.hf.space") # Call the API result = client.predict( "Hello, world!", # input text api_name="/predict" ) print(result)
curl -X POST https://your-space.hf.space/api/predict \ -H "Content-Type: application/json" \ -d '{"data": ["Hello, world!"]}'
Authentication
# Simple username/password demo.launch(auth=("admin", "password")) # Multiple users demo.launch(auth=[("user1", "pass1"), ("user2", "pass2")]) # Custom auth function def auth_fn(username, password): return username == "admin" and password == os.environ["APP_PASSWORD"] demo.launch(auth=auth_fn)
Docker Deployment
FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 7860 CMD ["python", "app.py"]
# Bind to 0.0.0.0 for Docker demo.launch(server_name="0.0.0.0", server_port=7860)
What's Next?
In our final lesson, we will cover best practices for building production-quality Gradio applications.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX