Build ML web UIs in Python · Interface / Blocks / ChatInterface · verified against Gradio 6.x (2026)

Gradio cheat sheet

Gradio turns any Python function into a shareable web app — no HTML/JS. Wrap a function with gr.Interface for an instant demo, compose a custom layout with gr.Blocks + event listeners, or ship a chatbot with gr.ChatInterface. Everything is a Python component (Textbox, Image, Audio, Chatbot…); .launch() serves it locally and share=True gives a public link in seconds. Targets Gradio 6.x, Python 3.10+.

interface components & layout interactivity chat launch & deploy gotcha most common

Verified 2026-08-31 against the official docs at gradio.app/docs (Gradio 6.x; latest 6.20.0, released 2026-08-24). Import convention: import gradio as gr. Apps run on a local server (default port 7860) and can tunnel a temporary public share link.

Outline

Interface for a one-function demo; Blocks when you need custom layout & wiring; ChatInterface for chatbots. Same components everywhere.

Getting started

  1. 1Install & Interface
  2. 2Interface options

Components & layout

  1. 3Components
  2. 4Blocks — custom apps
  3. 5Layout & theming

Interactivity

  1. 6Event listeners
  2. 7State & sessions
  3. 8Streaming & progress

Chat

  1. 9ChatInterface

Launch & deploy

  1. 10Launch, share & auth
  2. 11gradio_client & API
  3. 12Deploy & ecosystem

Getting Started

Wrap a function and launch — a working web UI in a handful of lines.

1Install & Interfacehello world
2Interface optionspolish the demo

Components & Layout

Components are the inputs/outputs; Blocks lets you arrange them however you like.

3Componentsinputs & outputs
4Blocks — custom appsfull control
5Layout & themingarrange & style

Interactivity

Wire events, keep per-user state, and stream results as they compute.

6Event listenerswire it up
7State & sessionsper-user memory
8Streaming & progressshow progress

Chat

A full chatbot UI — history, streaming, retries — from one function.

9ChatInterfacechatbots

Launch & Deploy

Serve locally, share a link, call it as an API, or host it on Spaces.

10Launch, share & auth.launch()
11gradio_client & APIcall it in code
12Deploy & ecosystemhost it

Worth memorizing

import gradio as grfn -> web UI, no HTML/JS
gr.Interfacefn + inputs + outputs, instant demo
gr.Blockswith-block + explicit event wiring
gr.ChatInterfacefn(message, history) -> chatbot
componentsTextbox/Image/Audio/Slider/Chatbot/...
.click/.change/.submitevent(fn, inputs, outputs)
gr.update()change an output's props, not just value
gr.Stateper-session memory (not module globals!)
yieldstream partial outputs / LLM tokens
Row/Column/Tablayout; theme= to style
launch(share=True)public link in seconds
gradio_clientevery app is also an API (api_name=)