CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-gradio

Python library for easily interacting with trained machine learning models

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

core-applications.mddocs/

Core Applications

Foundation classes for building different types of Gradio applications, from simple function wrappers to complex multi-component interfaces with custom layouts and interactions.

Capabilities

Interface

High-level wrapper that automatically creates a web interface for a single Python function, handling input/output types, validation, and UI generation.

class Interface:
    def __init__(
        self,
        fn,
        inputs,
        outputs,
        examples=None,
        *,
        cache_examples=None,
        cache_mode=None,
        examples_per_page=10,
        example_labels=None,
        preload_example=False,
        live=False,
        title=None,
        description=None,
        article=None,
        theme=None,
        flagging_mode=None,
        flagging_options=None,
        flagging_dir=".gradio/flagged",
        flagging_callback=None,
        analytics_enabled=None,
        batch=False,
        max_batch_size=4,
        show_api=True,
        api_name="predict",
        api_description=None,
        _api_mode=False,
        allow_duplication=False,
        concurrency_limit="default",
        css=None,
        css_paths=None,
        js=None,
        head=None,
        head_paths=None,
        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,
        allow_flagging=None,
        time_limit=30,
        stream_every=0.5,
        deep_link=None,
        **kwargs
    ):
        """
        Create an interface for a function.

        Parameters:
        - fn: The function to create an interface for
        - inputs: List of input components or strings
        - outputs: List of output components or strings  
        - examples: Example inputs for the interface
        - cache_examples: Whether to cache examples for fast runtime
        - cache_mode: When to cache examples ("eager" or "lazy")
        - examples_per_page: Number of examples to display per page
        - example_labels: Custom labels for examples
        - preload_example: Index of example to preload on startup
        - live: Whether to run function on every input change
        - title: Title displayed at the top of the interface
        - description: Description displayed below the title
        - article: Extended article content below interface
        - theme: Theme object or string name for styling
        - flagging_mode: Flagging behavior ("never", "auto", "manual")
        - flagging_options: List of flagging options
        - flagging_dir: Directory to save flagged data
        - flagging_callback: Custom flagging callback
        - analytics_enabled: Whether to enable analytics
        - batch: Whether to batch process multiple inputs
        - max_batch_size: Maximum batch size for processing
        - show_api: Whether to show API in documentation
        - api_name: Name for the API endpoint
        - api_description: Description for API endpoint
        - allow_duplication: Whether to allow duplication on HF Spaces
        - concurrency_limit: Maximum concurrent executions
        - css: Custom CSS string for styling
        - css_paths: Paths to CSS files for styling
        - js: Custom JavaScript string for functionality
        - head: Custom HTML head content
        - head_paths: Paths to HTML head files
        - additional_inputs: Extra input components in accordion
        - additional_inputs_accordion: Accordion for additional inputs
        - submit_btn: Submit button configuration
        - stop_btn: Stop button configuration
        - clear_btn: Clear button configuration
        - delete_cache: Cache deletion settings
        - show_progress: Progress display mode ("full", "minimal", "hidden")
        - fill_width: Whether to expand horizontally
        - allow_flagging: Deprecated - use flagging_mode instead
        - time_limit: Stream time limit in seconds
        - stream_every: Stream chunk frequency in seconds
        - deep_link: Deep linking configuration
        """

    def launch(
        self,
        inline=None,
        inbrowser=None,
        share=None,
        debug=None,
        max_threads=40,
        auth=None,
        auth_message=None,
        prevent_thread_lock=False,
        show_error=False,
        server_name=None,
        server_port=None,
        height=500,
        width="100%",
        favicon_path=None,
        ssl_keyfile=None,
        ssl_certfile=None,
        ssl_keyfile_password=None,
        ssl_verify=True,
        quiet=False,
        show_api=True,
        allowed_paths=None,
        blocked_paths=None,
        root_path=None,
        app_kwargs=None,
        **kwargs
    ):
        """
        Launch the interface.

        Parameters:
        - share: Whether to create a public link
        - debug: Whether to run in debug mode
        - auth: Authentication credentials (tuple or callable)
        - server_name: Server hostname
        - server_port: Server port number
        - inbrowser: Whether to open in browser automatically
        - show_api: Whether to show API documentation
        - quiet: Whether to suppress output
        """

    def integrate(self, comet_ml=None, wandb=None, mlflow=None): ...
    def predict(self, *args, **kwargs): ...
    def close(self): ...

Usage example:

import gradio as gr

def classify_image(image):
    # Image classification logic
    return {"cat": 0.8, "dog": 0.2}

interface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=3),
    title="Pet Classifier",
    description="Upload an image to classify pets"
)

interface.launch()

Blocks

Core application framework for creating multi-component interfaces with custom layouts, complex interactions, and full control over the user interface design.

class Blocks:
    def __init__(
        self,
        theme=None,
        analytics_enabled=None,
        mode="blocks",
        title="Gradio",
        css=None,
        js=None,
        head=None,
        fill_height=False,
        delete_cache=None,
        **kwargs
    ):
        """
        Create a Blocks interface.

        Parameters:
        - theme: Theme object or string name for styling
        - analytics_enabled: Whether to enable analytics
        - mode: Interface mode ("blocks" or "interface")
        - title: Page title displayed in browser tab
        - css: Custom CSS string for styling
        - js: Custom JavaScript string for functionality
        - head: Custom HTML head content
        - fill_height: Whether to fill viewport height
        - delete_cache: Cache deletion settings
        """

    def __enter__(self):
        """Enter context manager for component definition."""

    def __exit__(self, exc_type, exc_val, exc_tb):
        """Exit context manager."""

    def launch(self, **kwargs):
        """Launch the Blocks interface with same parameters as Interface.launch()."""

    def load(self, fn, inputs=None, outputs=None, **kwargs): ...
    def queue(self, **kwargs): ...
    def integrate(self, comet_ml=None, wandb=None, mlflow=None): ...
    def close(self): ...

Usage example:

import gradio as gr

def process_data(text, number):
    return f"Processed: {text} x {number}"

with gr.Blocks() as demo:
    gr.Markdown("# Data Processor")
    
    with gr.Row():
        with gr.Column():
            text_input = gr.Textbox(label="Text Input")
            num_input = gr.Number(label="Number Input")
            submit_btn = gr.Button("Process")
        
        with gr.Column():
            output = gr.Textbox(label="Result")
    
    submit_btn.click(
        fn=process_data,
        inputs=[text_input, num_input],
        outputs=output
    )

demo.launch()

ChatInterface

Specialized interface for chat and conversation applications with built-in message history, user input handling, and conversational UI patterns.

class ChatInterface:
    def __init__(
        self,
        fn,
        *,
        multimodal=False,
        type=None,
        chatbot=None,
        textbox=None,
        additional_inputs=None,
        additional_inputs_accordion=None,
        additional_outputs=None,
        editable=False,
        examples=None,
        example_labels=None,
        example_icons=None,
        run_examples_on_click=True,
        cache_examples=None,
        cache_mode=None,
        title=None,
        description=None,
        theme=None,
        flagging_mode=None,
        flagging_options=("Like", "Dislike"),
        flagging_dir=".gradio/flagged",
        css=None,
        css_paths=None,
        js=None,
        head=None,
        head_paths=None,
        analytics_enabled=None,
        autofocus=True,
        autoscroll=True,
        submit_btn=True,
        stop_btn=True,
        concurrency_limit="default",
        delete_cache=None,
        show_progress="minimal",
        fill_height=True,
        fill_width=False,
        api_name="chat",
        api_description=None,
        show_api=True,
        save_history=False,
        **kwargs
    ):
        """
        Create a ChatInterface for conversational applications.

        Parameters:
        - fn: Function that processes messages and chat history
        - multimodal: Whether to support text + file inputs
        - type: Message format ("messages" or "tuples")
        - chatbot: Custom Chatbot component instance
        - textbox: Custom Textbox/MultimodalTextbox instance
        - additional_inputs: Extra input components
        - additional_inputs_accordion: Accordion for additional inputs
        - additional_outputs: Extra output components
        - editable: Whether users can edit past messages
        - examples: Example messages or multimodal inputs
        - example_labels: Labels for examples
        - example_icons: Icons for examples
        - run_examples_on_click: Whether examples run immediately
        - cache_examples: Whether to cache examples
        - cache_mode: When to cache ("eager" or "lazy")
        - title: Interface title
        - description: Interface description
        - theme: Theme object or string
        - flagging_mode: Flagging behavior ("never" or "manual")
        - flagging_options: Available flagging options
        - flagging_dir: Directory for flagged data
        - css: Custom CSS string
        - css_paths: Paths to CSS files
        - js: Custom JavaScript
        - head: Custom HTML head content
        - head_paths: Paths to HTML head files
        - analytics_enabled: Whether to enable analytics
        - autofocus: Whether to auto-focus input
        - autoscroll: Whether to auto-scroll to bottom
        - submit_btn: Submit button configuration
        - stop_btn: Stop button configuration
        - concurrency_limit: Maximum concurrent executions
        - delete_cache: Cache deletion settings
        - show_progress: Progress display mode
        - fill_height: Whether to expand vertically
        - fill_width: Whether to expand horizontally
        - api_name: API endpoint name
        - api_description: API endpoint description
        - show_api: Whether to show in API docs
        - save_history: Whether to persist chat history
        """

    def launch(self, **kwargs):
        """Launch the chat interface with same parameters as Interface.launch()."""

    def queue(self, **kwargs): ...
    def close(self): ...

The chat function should have this signature:

def chat_fn(message: str, history: list) -> str:
    """
    Chat function for ChatInterface.

    Parameters:
    - message: Current user message
    - history: List of [user_message, bot_response] pairs

    Returns:
    - response: Bot response string
    """

Usage example:

import gradio as gr

def simple_chat(message, history):
    return f"You said: {message}"

chat = gr.ChatInterface(
    fn=simple_chat,
    title="Simple Chatbot",
    description="A basic echo chatbot"
)

chat.launch()

TabbedInterface

Multi-tab interface container for organizing multiple Interface instances into a single application with tabbed navigation.

class TabbedInterface:
    def __init__(
        self,
        interface_list,
        tab_names,
        title=None,
        theme=None,
        analytics_enabled=None,
        css=None,
        js=None,
        **kwargs
    ):
        """
        Create a tabbed interface from multiple interfaces.

        Parameters:
        - interface_list: List of Interface objects
        - tab_names: List of strings for tab labels
        - title: Overall title for the tabbed interface
        - theme: Theme object or string name
        - analytics_enabled: Whether to enable analytics
        - css: Custom CSS string
        - js: Custom JavaScript string
        """

    def launch(self, **kwargs):
        """Launch the tabbed interface with same parameters as Interface.launch()."""

    def close(self): ...

Usage example:

import gradio as gr

def text_analyzer(text):
    return len(text)

def image_classifier(image):
    return "cat"

text_interface = gr.Interface(
    fn=text_analyzer,
    inputs="text",
    outputs="number"
)

image_interface = gr.Interface(
    fn=image_classifier,
    inputs="image",
    outputs="text"
)

tabbed = gr.TabbedInterface(
    [text_interface, image_interface],
    ["Text Analysis", "Image Classification"],
    title="Multi-Tool App"
)

tabbed.launch()

Utility Functions

close_all

def close_all():
    """Close all running Gradio interfaces."""

Types

class Component:
    """Base class for all Gradio components."""
    
    def __init__(self, **kwargs): ...
    def change(self, fn, inputs=None, outputs=None, **kwargs): ...
    def select(self, fn, inputs=None, outputs=None, **kwargs): ...

Install with Tessl CLI

npx tessl i tessl/pypi-gradio

docs

components.md

core-applications.md

events.md

external-integration.md

index.md

layouts.md

themes.md

utilities.md

tile.json