Gradio
A Python library for wrapping any function in a shareable web UI. The default way to demo HuggingFace models.
Category
Visualization
Difficulty
Beginner
When to use
You want the fastest path from a Python function to a clickable demo, especially for ML models with image, audio, or text I/O.
When not to use
You need a multi-page app with rich state — Streamlit or a real frontend fits better.
Alternatives
Streamlit Panel FastAPI + simple HTML
At a glance
| Field | Value |
|---|---|
| Category | ML demo UI |
| Difficulty | Beginner |
| When to use | Model demos, quick interactive tests |
| When not to use | Multi-page apps; rich stateful UIs |
| Alternatives | Streamlit, Panel, custom frontend |
What it is
Gradio wraps a Python function in a web UI where each argument gets an input widget and each return value gets an output widget. It has first-class support for image, audio, video, and file inputs, which is why it’s the standard demo format on HuggingFace Spaces.
When we reach for it at Ephizen
- Demos of image, audio, or multimodal models where the input types are more than text.
- Publishing a demo to HuggingFace Spaces with near-zero effort.
- Side-by-side comparisons of two model versions via
gr.Interfacewith two outputs. - Giving a labeler or domain expert a simple interface to interact with a model.
Getting started
import gradio as gr
def classify(image):
return {"cat": 0.8, "dog": 0.2}
demo = gr.Interface(
fn=classify,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=2),
title="Cat or Dog?",
)
demo.launch()
Gotchas
- The built-in
share=Truemode creates a public tunnel — fine for quick demos, a security problem for anything sensitive. - Blocks API gives you more layout control than
Interface, at the cost of being less terse. - Gradio versions change the component API regularly. Pin the version when embedding in a larger app.