Gradio — Build ML Demos & AI Apps in Python
Python library for building interactive ML demos and AI web apps. Chat interfaces, file upload, image/audio/video I/O. Share with public link. 42K+ stars.
Ready-to-run agent install
This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.
npx -y tokrepo@latest install b30caf4b-a9a8-4379-b1c6-bc8f5cf5cce3 --target codexRun after dry-run confirms the install plan.
What it is
Gradio is the standard Python library for building interactive ML demos and AI web applications. You create chat interfaces, image generators, audio processors, and data tools with a few lines of Python -- no frontend code required. It automatically generates a web UI and an optional public share link.
ML engineers and researchers who need a quick web interface for their models are the primary users. Gradio is used extensively on Hugging Face Spaces and by teams that want to demonstrate model capabilities without building a full frontend.
How it saves time or tokens
Without Gradio, turning a Python model into a web demo requires building HTML/CSS/JS frontend code, setting up a web server, and handling file upload/download logic. Gradio replaces all of this with a single function call. The gr.Interface class maps Python function inputs/outputs to UI components automatically.
The share=True flag generates a public URL through Gradio's tunnel service, eliminating the need to deploy to a server for sharing demos with stakeholders.
How to use
- Install Gradio:
pip install gradio
- Create a simple interface:
import gradio as gr
def greet(name):
return f'Hello, {name}!'
gr.Interface(fn=greet, inputs='text', outputs='text').launch()
- Open
http://localhost:7860in your browser. Addshare=Trueto get a public URL.
Example
A chat interface with streaming responses:
import gradio as gr
def chat(message, history):
response = ''
for char in f'You said: {message}':
response += char
yield response
gr.ChatInterface(fn=chat, type='messages').launch()
This creates a full chat UI with message history, streaming token display, and a text input box -- all from seven lines of Python.
Related on TokRepo
- Coding Tools -- Developer tools for building and testing AI applications
- AI Tools for Research -- Research tools that pair with demo interfaces
Common pitfalls
- Gradio's default server binds to
0.0.0.0, making it accessible on your network. Useserver_name='127.0.0.1'for local-only access when working with sensitive models. - Share links expire after 72 hours. For permanent deployments, host on Hugging Face Spaces or deploy behind a reverse proxy.
- Large file uploads can time out with the default settings. Increase
max_sizein the component configuration for applications that process large videos or datasets.
Frequently Asked Questions
Yes. Gradio is framework-agnostic. It wraps any Python function, so it works with PyTorch, TensorFlow, scikit-learn, Hugging Face Transformers, or plain Python. The interface only cares about the function's inputs and outputs.
The most common approach is Hugging Face Spaces, which hosts Gradio apps for free. You can also deploy using Docker, run behind Nginx as a reverse proxy, or use any ASGI server since Gradio is built on FastAPI internally.
Yes. Gradio uses a queue system for handling concurrent requests. You can configure the queue size, concurrency limit, and timeout settings. For CPU-bound models, set max_threads appropriately to avoid resource exhaustion.
Gradio supports text, images, audio, video, files, dataframes, JSON, markdown, code, sliders, dropdowns, checkboxes, and many more. The Blocks API lets you compose custom layouts with rows, columns, tabs, and accordions.
Gradio automatically creates a REST API alongside the UI. However, for high-throughput production APIs, dedicated frameworks like FastAPI are more appropriate. Gradio is optimized for demos, internal tools, and moderate-traffic applications.
Citations (3)
- Gradio GitHub— Gradio is a Python library for building interactive ML demos
- Gradio Documentation— Gradio is built on FastAPI internally
- Hugging Face Spaces— Hugging Face Spaces hosts Gradio apps
Related on TokRepo
Source & Thanks
Created by Gradio. Licensed under Apache 2.0. gradio-app/gradio — 42,000+ GitHub stars
Discussion
Related Assets
Streamlit — Build Data Apps in Pure Python in Minutes
Streamlit is the fastest way to build and share data applications. Write a Python script with Streamlit commands and get an interactive web app with widgets, charts, and real-time updates — no frontend experience needed.
Kedro — Production-Ready ML Pipeline Framework for Python
Kedro is an open-source Python framework by McKinsey QuantumBlack that applies software engineering best practices to data science and ML pipelines. It provides a standardized project structure, data catalog, and pipeline abstraction that makes experimental code production-ready.
FastHTML — Build AI Web Apps in Pure Python
Modern Python web framework that generates HTML from Python functions. No JavaScript, no templates. Perfect for building AI tool dashboards and agent UIs rapidly.
Weights & Biases — ML Experiment Tracking
W&B tracks, visualizes, and manages ML experiments and LLM apps. 10.9K+ GitHub stars. Experiment tracking, model versioning, Weave for LLMs. MIT.