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.
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
DTM — Distributed Transaction Manager for Microservices
A cross-language distributed transaction framework supporting Saga, TCC, XA, and two-phase message patterns for reliable microservice coordination.
WatermelonDB — Reactive Database for React Native Apps
A high-performance reactive database framework for React Native and React web apps, built on top of SQLite with lazy loading and sync primitives.
Dexie.js — Minimalist IndexedDB Wrapper for the Web
A lightweight wrapper around IndexedDB that provides a clean Promise-based API for client-side storage in web applications.