TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/gradio-app/gradio/llms.txt
Use this file to discover all available pages before exploring further.
Interface class is Gradio’s main high-level abstraction for creating web-based UIs around Python functions. It provides a simple way to wrap any function with input and output components, making it ideal for quick demos and prototypes.
What is an Interface?
An Interface allows you to create a web-based GUI around a machine learning model (or any Python function) in just a few lines of code. You specify three main parameters:- The function to wrap (
fn) - The input components (
inputs) - The output components (
outputs)
Basic usage
Here’s the simplest possible Interface:- An input textbox for entering a name
- A submit button
- An output textbox showing the greeting
Using component shortcuts
You can specify components using string shortcuts (like"textbox", "image", "label") or instantiate them explicitly:
Multiple inputs and outputs
You can pass lists of components for multiple inputs or outputs:The number of function parameters must match the number of input components, and the number of return values must match the number of output components.
Key parameters
Title and description
Add metadata to make your Interface more informative:Examples
Provide example inputs to help users get started:Additional inputs
Useadditional_inputs to add optional parameters that appear in a collapsible accordion:
Live mode
Setlive=True to automatically update outputs when inputs change (no submit button needed):
Working with state
For stateful applications, you can use the special"state" component:
Loading from pipelines
TheInterface.from_pipeline() class method creates an Interface from Hugging Face transformers pipelines:
API endpoints
Every Interface automatically generates API endpoints. Control their visibility:Comparison with Blocks
Interface is ideal for:
- Quick prototypes and demos
- Single-function applications
- Simple input-output workflows
Blocks instead when you need:
- Custom layouts and multi-page apps
- Multiple interconnected functions
- Complex event handling and data flows
See also
- Blocks - For more complex layouts and workflows
- ChatInterface - Specialized interface for chatbots
- Components - Available input/output components
- Events - Understanding event listeners