Installing Gradio
Get Gradio up and running in minutes. We will install the library, create a virtual environment, and build your first interactive demo.
Installation
Gradio requires Python 3.8+ and installs with pip:
# Create a virtual environment python -m venv gradio-env source gradio-env/bin/activate # Windows: gradio-env\Scripts\activate # Install Gradio pip install gradio # Verify installation python -c "import gradio; print(gradio.__version__)"
Your First Demo
Create a file called app.py and add this code:
import gradio as gr def greet(name, intensity): return "Hello, " + name + "!" * int(intensity) demo = gr.Interface( fn=greet, inputs=["text", gr.Slider(1, 10, value=1)], outputs="text", title="Greeting Generator", description="Enter your name and select excitement level." ) demo.launch()
# Run the demo python app.py # Output: # Running on local URL: http://127.0.0.1:7860
gradio app.py instead of python app.py to enable automatic reloading when you save changes to your file.Launch Configuration
The launch() method accepts several useful parameters:
demo.launch( server_name="0.0.0.0", # Listen on all interfaces server_port=8080, # Custom port share=True, # Create public URL auth=("user", "pass"), # Basic authentication show_error=True, # Show full errors in UI favicon_path="icon.png", # Custom favicon )
Project Structure
my-gradio-app/ app.py # Main Gradio app requirements.txt # Dependencies models/ # ML model files assets/ # Images, CSS, etc. flagged/ # User-flagged data (auto-created) README.md # For HF Spaces deployment
flagged/ directory by default to store user-flagged examples. You can disable this with allow_flagging="never" in gr.Interface().What's Next?
Now that Gradio is installed, let's dive into gr.Interface() - the fastest way to build ML demos with automatic UI generation.
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