> ## Documentation 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

> Learn how to create simple UIs with Gradio's high-level Interface class

The `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:

1. The function to wrap (`fn`)
2. The input components (`inputs`)
3. The output components (`outputs`)

Gradio automatically generates the UI, handles user interactions, and displays results.

## Basic usage

Here's the simplest possible Interface:

```python theme={null}
import gradio as gr

def greet(name):
    return "Hello " + name + "!"

demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox")
demo.launch()
```

This creates a complete web interface with:

* 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:

```python theme={null}
import gradio as gr

def image_classifier(img):
    return {'cat': 0.3, 'dog': 0.7}

demo = gr.Interface(
    fn=image_classifier,
    inputs="image",
    outputs="label"
)
demo.launch()
```

For more control, use component objects:

```python theme={null}
import gradio as gr

demo = gr.Interface(
    fn=image_classifier,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=3)
)
```

## Multiple inputs and outputs

You can pass lists of components for multiple inputs or outputs:

```python theme={null}
import gradio as gr

def process_data(text, temperature, enable_feature):
    result = f"Text: {text}, Temp: {temperature}, Feature: {enable_feature}"
    return result, temperature * 2

demo = gr.Interface(
    fn=process_data,
    inputs=[
        gr.Textbox(label="Input Text"),
        gr.Slider(0, 100, label="Temperature"),
        gr.Checkbox(label="Enable Feature")
    ],
    outputs=[
        gr.Textbox(label="Result"),
        gr.Number(label="Double Temperature")
    ]
)
```

<Note>
  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.
</Note>

## Key parameters

### Title and description

Add metadata to make your Interface more informative:

```python theme={null}
demo = gr.Interface(
    fn=greet,
    inputs="textbox",
    outputs="textbox",
    title="Greeting Generator",
    description="Enter your name to receive a personalized greeting."
)
```

### Examples

Provide example inputs to help users get started:

```python theme={null}
demo = gr.Interface(
    fn=greet,
    inputs="textbox",
    outputs="textbox",
    examples=[["Alice"], ["Bob"], ["Charlie"]]
)
```

### Additional inputs

Use `additional_inputs` to add optional parameters that appear in a collapsible accordion:

```python theme={null}
demo = gr.Interface(
    fn=process_text,
    inputs="textbox",
    outputs="textbox",
    additional_inputs=[
        gr.Slider(0, 100, value=50, label="Max Length"),
        gr.Dropdown(["formal", "casual"], label="Style")
    ],
    additional_inputs_accordion="Advanced Options"
)
```

### Live mode

Set `live=True` to automatically update outputs when inputs change (no submit button needed):

```python theme={null}
demo = gr.Interface(
    fn=lambda x: x.upper(),
    inputs="textbox",
    outputs="textbox",
    live=True
)
```

## Working with state

For stateful applications, you can use the special `"state"` component:

```python theme={null}
import gradio as gr

def increment(count, state):
    state = state + 1
    return f"Count: {state}", state

demo = gr.Interface(
    fn=increment,
    inputs=["textbox", "state"],
    outputs=["textbox", "state"]
)
```

<Warning>
  When using state, there must be exactly one state input and one state output.
</Warning>

## Loading from pipelines

The `Interface.from_pipeline()` class method creates an Interface from Hugging Face transformers pipelines:

```python theme={null}
import gradio as gr
from transformers import pipeline

pipe = pipeline("image-classification")
demo = gr.Interface.from_pipeline(pipe)
demo.launch()
```

Gradio automatically determines the appropriate input and output components based on the pipeline type.

## API endpoints

Every Interface automatically generates API endpoints. Control their visibility:

```python theme={null}
demo = gr.Interface(
    fn=greet,
    inputs="textbox",
    outputs="textbox",
    api_name="greet_user",  # Custom endpoint name
    api_visibility="public"  # "public", "private", or "undocumented"
)
```

## Comparison with Blocks

`Interface` is ideal for:

* Quick prototypes and demos
* Single-function applications
* Simple input-output workflows

Use `Blocks` instead when you need:

* Custom layouts and multi-page apps
* Multiple interconnected functions
* Complex event handling and data flows

## See also

* [Blocks](/concepts/blocks) - For more complex layouts and workflows
* [ChatInterface](/concepts/chat-interface) - Specialized interface for chatbots
* [Components](/concepts/components) - Available input/output components
* [Events](/concepts/events) - Understanding event listeners


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.