Gradio's signature: a Python function becomes a UI
Define a function. Wrap it with gr.Interface or compose with gr.Blocks. Gradio inspects the signature, auto-builds inputs/outputs, and serves a web UI. demo.launch() starts a local server; on Spaces, the runtime calls launch() automatically.
Two layouts
gr.Interface(fn, inputs, outputs)— one function, one UI. Best for single-task demos.gr.Blocks()— explicit layout. Multiple inputs/outputs, tabs, custom CSS, conditional visibility. Use when Interface is too rigid.
Streaming and ChatInterface
For chat models, gr.ChatInterface handles message history and streaming with a generator-based handler. The same pattern works with InferenceClient or local models.