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

Interface is Gradio's main high-level class that allows you to create a web-based GUI/demo around a machine learning model (or any Python function) in a few lines of code.

## Constructor

```python theme={null}
gr.Interface(
    fn,
    inputs,
    outputs,
    examples=None,
    cache_examples=None,
    cache_mode=None,
    examples_per_page=10,
    example_labels=None,
    preload_example=0,
    live=False,
    title=None,
    description=None,
    article=None,
    flagging_mode=None,
    flagging_options=None,
    flagging_dir=".gradio/flagged",
    flagging_callback=None,
    analytics_enabled=None,
    batch=False,
    max_batch_size=4,
    api_visibility="public",
    api_name=None,
    api_description=None,
    allow_duplication=False,
    concurrency_limit="default",
    additional_inputs=None,
    additional_inputs_accordion=None,
    submit_btn="Submit",
    stop_btn="Stop",
    clear_btn="Clear",
    delete_cache=None,
    show_progress="full",
    fill_width=False,
    time_limit=30,
    stream_every=0.5,
    deep_link=None,
    validator=None
)
```

### Parameters

<ParamField path="fn" type="Callable" required>
  The function to wrap an interface around. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
</ParamField>

<ParamField path="inputs" type="str | Component | Sequence[str | Component] | None" required>
  A single Gradio component, or list of Gradio components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. The number of input components should match the number of parameters in fn. If set to None, then only the output components will be displayed.
</ParamField>

<ParamField path="outputs" type="str | Component | Sequence[str | Component] | None" required>
  A single Gradio component, or list of Gradio components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. The number of output components should match the number of values returned by fn. If set to None, then only the input components will be displayed.
</ParamField>

<ParamField path="examples" type="list[Any] | list[list[Any]] | str | None" default="None">
  Sample inputs for the function; if provided, appear below the UI components and can be clicked to populate the interface. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component. A string path to a directory of examples can also be provided.
</ParamField>

<ParamField path="cache_examples" type="bool | None" default="None">
  If True, caches examples in the server for fast runtime in examples. If "lazy", then examples are cached (for all users of the app) after their first use. Note that examples are cached separately from Gradio's queue() so certain features will not be displayed in Gradio's UI for cached examples.
</ParamField>

<ParamField path="cache_mode" type="Literal['eager', 'lazy'] | None" default="None">
  If "lazy", examples are cached after their first use. If "eager", all examples are cached at app launch.
</ParamField>

<ParamField path="examples_per_page" type="int" default="10">
  If examples are provided, how many to display per page.
</ParamField>

<ParamField path="example_labels" type="list[str] | None" default="None">
  A list of labels for each example. If provided, the length of this list should be the same as the number of examples, and these labels will be used in the UI instead of rendering the example values.
</ParamField>

<ParamField path="preload_example" type="int | Literal[False]" default="0">
  If an integer is provided, the example at that index in the examples list will be preloaded when the Gradio app is first loaded. If False, no example will be preloaded.
</ParamField>

<ParamField path="live" type="bool" default="False">
  Whether the interface should automatically rerun if any of the inputs change.
</ParamField>

<ParamField path="title" type="str | I18nData | None" default="None">
  A title for the interface; if provided, appears above the input and output components in large font. Also used as the tab title when opened in a browser window.
</ParamField>

<ParamField path="description" type="str | None" default="None">
  A description for the interface; if provided, appears above the input and output components and beneath the title. Accepts Markdown and HTML content.
</ParamField>

<ParamField path="article" type="str | None" default="None">
  An expanded article explaining the interface; if provided, appears below the input and output components. Accepts Markdown and HTML content.
</ParamField>

<ParamField path="flagging_mode" type="Literal['never', 'auto', 'manual'] | None" default="None">
  One of "never", "auto", or "manual". If "never" or "auto", users will not see a button to flag an input and output. If "manual", users will see a button to flag. If "auto", every input the user submits will be automatically flagged.
</ParamField>

<ParamField path="flagging_options" type="list[str] | list[tuple[str, str]] | None" default="None">
  If provided, allows user to select from the list of options when flagging.
</ParamField>

<ParamField path="flagging_dir" type="str" default="'.gradio/flagged'">
  Path to the directory where flagged data is stored.
</ParamField>

<ParamField path="flagging_callback" type="FlaggingCallback | None" default="None">
  Either None or an instance of a subclass of FlaggingCallback which will be called when a sample is flagged.
</ParamField>

<ParamField path="analytics_enabled" type="bool | None" default="None">
  Whether to allow basic telemetry. If None, will use GRADIO\_ANALYTICS\_ENABLED environment variable if defined, or default to True.
</ParamField>

<ParamField path="batch" type="bool" default="False">
  If True, then the function should process a batch of inputs.
</ParamField>

<ParamField path="max_batch_size" type="int" default="4">
  The maximum number of inputs to batch together if this is called from the queue.
</ParamField>

<ParamField path="api_visibility" type="Literal['public', 'private', 'undocumented']" default="'public'">
  Controls the visibility of the prediction endpoint. Can be "public" (shown in API docs and callable), "private" (hidden from API docs and not callable), or "undocumented" (hidden from API docs but callable).
</ParamField>

<ParamField path="api_name" type="str | None" default="None">
  Defines how the prediction endpoint appears in the API docs. Can be a string or None.
</ParamField>

<ParamField path="api_description" type="str | None | Literal[False]" default="None">
  Description of the API endpoint. Can be a string, None, or False.
</ParamField>

<ParamField path="allow_duplication" type="bool" default="False">
  If True, then will show a 'Duplicate Spaces' button on Hugging Face Spaces.
</ParamField>

<ParamField path="concurrency_limit" type="int | None | Literal['default']" default="'default'">
  If set, this is the maximum number of this event that can be running simultaneously.
</ParamField>

<ParamField path="additional_inputs" type="str | Component | Sequence[str | Component] | None" default="None">
  A single Gradio component, or list of Gradio components. These components will be rendered in an accordion below the main input components.
</ParamField>

<ParamField path="submit_btn" type="str | Button" default="'Submit'">
  The button to use for submitting inputs.
</ParamField>

<ParamField path="stop_btn" type="str | Button" default="'Stop'">
  The button to use for stopping the interface.
</ParamField>

<ParamField path="clear_btn" type="str | Button | None" default="'Clear'">
  The button to use for clearing the inputs.
</ParamField>

<ParamField path="delete_cache" type="tuple[int, int] | None" default="None">
  A tuple corresponding \[frequency, age] both expressed in number of seconds.
</ParamField>

<ParamField path="show_progress" type="Literal['full', 'minimal', 'hidden']" default="'full'">
  How to show the progress animation while event is running.
</ParamField>

<ParamField path="fill_width" type="bool" default="False">
  Whether to horizontally expand to fill container fully.
</ParamField>

<ParamField path="time_limit" type="int | None" default="30">
  The time limit for the stream to run. Default is 30 seconds.
</ParamField>

<ParamField path="stream_every" type="float" default="0.5">
  The latency (in seconds) at which stream chunks are sent to the backend.
</ParamField>

<ParamField path="deep_link" type="str | DeepLinkButton | bool | None" default="None">
  A string or gr.DeepLinkButton object that creates a unique URL you can use to share your app.
</ParamField>

<ParamField path="validator" type="Callable | None" default="None">
  A function that takes in the inputs and can optionally return a gr.validate() object for each input.
</ParamField>

## Class Methods

### from\_pipeline

```python theme={null}
gr.Interface.from_pipeline(pipeline, **kwargs)
```

Class method that constructs an Interface from a Hugging Face transformers.Pipeline or diffusers.DiffusionPipeline object. The input and output components are automatically determined from the pipeline.

<ParamField path="pipeline" type="Pipeline | DiffusionPipeline" required>
  The pipeline object to use.
</ParamField>

<ResponseField name="returns" type="Interface">
  A Gradio Interface object from the given Pipeline.
</ResponseField>

## Example

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

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

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


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