ConfigsMar 31, 2026·2 min read

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.

TL;DR
Gradio builds interactive ML demos and AI web apps with chat interfaces, file upload, and shareable public links in a few lines of Python.
§01

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.

§02

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.

§03

How to use

  1. Install Gradio:
pip install gradio
  1. Create a simple interface:
import gradio as gr

def greet(name):
    return f'Hello, {name}!'

gr.Interface(fn=greet, inputs='text', outputs='text').launch()
  1. Open http://localhost:7860 in your browser. Add share=True to get a public URL.
§04

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.

§05

Related on TokRepo

§06

Common pitfalls

  • Gradio's default server binds to 0.0.0.0, making it accessible on your network. Use server_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_size in the component configuration for applications that process large videos or datasets.

Frequently Asked Questions

Does Gradio work with any ML framework?+

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.

How do I deploy a Gradio app to production?+

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.

Can Gradio handle multiple concurrent users?+

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.

What UI components does Gradio support?+

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.

Is Gradio suitable for production APIs?+

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)
🙏

Source & Thanks

Created by Gradio. Licensed under Apache 2.0. gradio-app/gradio — 42,000+ GitHub stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets