Beginner

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:

Terminal
# 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:

Python - app.py
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()
Terminal
# Run the demo
python app.py

# Output:
# Running on local URL: http://127.0.0.1:7860
Hot reload: Run 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:

Python
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

Project Layout
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
Note: Gradio creates a 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.