Introducing Gradio Clients

Watch

New to Gradio? Start here: Getting Started

See the Release History

Interface

gradio.Interface(···)

Description

Interface is Gradio's main high-level class, and allows you to create a web-based GUI / demo around a machine learning model (or any Python function) in a few lines of code. You must specify three parameters: (1) the function to create a GUI for (2) the desired input components and (3) the desired output components. Additional parameters can be used to control the appearance and behavior of the demo.

Example Usage

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()

Initialization

Parameters

Demos

import gradio as gr def greet(name): return "Hello " + name + "!" demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox") if __name__ == "__main__": demo.launch()

Methods

launch

gradio.Interface.launch(···)

Description

Launches a simple web server that serves the demo. Can also be used to create a public link used by anyone to access the demo from their browser by setting share=True. <br>

Example Usage

import gradio as gr
def reverse(text):
    return text[::-1]
demo = gr.Interface(reverse, "text", "text")
demo.launch(share=True, auth=("username", "password"))
Parameters

load

gradio.Interface.load(block, ···)

Description

This listener is triggered when the Interface initially loads in the browser.

Parameters

from_pipeline

gradio.Interface.from_pipeline(pipeline, ···)

Description

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.

Example Usage

import gradio as gr
from transformers import pipeline
pipe = pipeline("image-classification")
gr.Interface.from_pipeline(pipe).launch()
Parameters

integrate

gradio.Interface.integrate(···)

Description

A catch-all method for integrating with other libraries. This method should be run after launch()

Parameters

queue

gradio.Interface.queue(···)

Description

By enabling the queue you can control when users know their position in the queue, and set a limit on maximum number of events allowed.

Example Usage

demo = gr.Interface(image_generator, gr.Textbox(), gr.Image())
demo.queue(max_size=20)
demo.launch()
Parameters

Guides