Professional Documents
Culture Documents
Manual de Gradio
Manual de Gradio
<§, gradio =
New to Gradio? Start here: Getting Started See the Release History
C h a tIn te rfa ce
Interface
Description
In terface is G ra d io 's m a in h ig h -le v e l cla ss, a n d a llo w s yo u to cre a te a w e b -b a s e d
A d d it io n a l p a ra m e te rs can be u se d to c o n tro l th e a p p e a ra n c e a n d b e h a v io r o f th e
dem o.
Exampíe Usage
import gradio as gr
def image_classifier(inp):
demo.launch()
Initiaíization
Parameter Description
component.
str | Component |list[str | com ponents. Com ponents can either be passed as
be displayed.
str | Component |list[str | com ponents. Com ponents can either be passed as
be displayed.
list[Any] | list[list[Any]] |str | None below the UI com ponents and can be clicked to
corresponding inputs.
elsewhere is False.
int page.
default: 10
default: False
str 1None the input and output com ponents in large font.
browser window.
Parameter Description
str | None above the input and output com ponents and
displayed.
default: None
Theme |str | None a string, w ill look for a built-in theme with that
Default theme.
default: None
Literal['never'] | Literal['auto'] | "auto", users w ill not see a button to flag an input
Literal['m anual'] | None and output. If "manual", users w ill see a button to
Parameter Description
default: None flag. If "auto", every input the user subm its w ill be
"manual".
str stored.
default: "flagged"
Default to None.
Parameter Description
default: 4 batch=True)
str 1Literal[False] |None Can be a string, None, or False. If set to a string, the
default: "predict" endpoint will be exposed in the API docs with the
event.
default: False
default).
str I Component | list[str | com ponents. Com ponents can either be passed as
displayed.
Parameter Description
a g r .A c c o r d io n ( la b e l= " A d d itio n a l
default: "Submit" v a ria n t= "p rim a ry "). This parameter does not
customization).
customization).
Demos
import gradio as gr
def greet(name) :
demo.launch()
Loading...
Methods
launch
gradio.Interface.launch(^••)
Description
L a u n c h e s a s im p le w e b s e rv e r t h a t se rv e s th e d e m o . C an a ls o be u sed to
Exampíe Usage
import gradio as gr
def reverse(text):
return text[::-1]
Agruments
Parameter Description
default: False
GRADIO_SHARE=True.
(currently 40).
list[tuple[str, str]] | None app. Can also provide function that takes
valid login.
Parameter Description
default: None
default: False True, the gradio app w ill not block and the
script finishes.
use "127.0.0.1".
default: 500
default: "100%"
str | None it w ill be used as the favicon for the web page.
default: None
default: None
default: True
bool
default: False
show _api If True, shows the api docs in the footer of the
default: True
Parameter Description
of your app.
"https://example.com/myapp", the
information.
default: None not authorized to access the app (they w ill see
load
gradio.Interface.load(block, •••)
Description
T h is lis te n e r is trig g e re d w h e n th e Interface in it ia lly lo a d s in th e b row ser.
Agruments
Parameter Description
b lo c k
Block 1None
required
output component.
default: None
default: None
default: False
Parameter Description
'hidden')]
default: "full"
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
from_pipeline
gradio. Interface.from_pipeline(pipeline, •••)
Description
C la s s m e th o d t h a t c o n s tru c ts an In terface fro m a H u g g in g Face
Exampíe Usage
import gradio as gr
pipe = pipeline("image-classification")
gr.Interface.from_pipeline(pipe).launch()
Agruments
Parameter Description
Pipeline | DiffusionPipeline
required
integrate
gradio.Interface.integrate(•••)
Description
A c a tc h -a ll m e th o d fo r in te g ra tin g w ith o th e r lib ra rie s . T h is m e th o d s h o u ld
Agruments
Parameter Description
<class 'inspect._empty'> w ill intégrate with the experim ent and appear
default: None
queue
Description
By e n a b lin g th e q u e u e y o u can c o n tro l w h e n u se rs k n o w t h e ir p o s itio n in
th e q u e u e , a n d s e t a lim it on m a x im u m n u m b e r o f e v e n ts a llo w e d .
Exampíe Usage
demo.queue(max_size=20)
demo.launch()
Agruments
Parameter Description
of seconds.
default: None full, new events w ill not be added and a user
gr.Interface(concurrency_limit=10). If
Quickstart
Key Features
Interface State
Reactive Interfaces
C h a tIn te rfa ce
gradio Status X O
Custom Components GalleryNEW Explore
gradio =
New to Gradio? Start here: Getting Started See the Release History
^ G ro u p C o m p o n e n ts
Accordion
gradio.Accordion(•••)
Description
A c c o rd io n is a la y o u t e le m e n t w h ic h can be to g g le d to s h o w /h id e th e c o n ta in e d
c o n te n t.
Exampíe Usage
gr.Markdown("lorem ipsum")
Initiaíization
Parameter Description
str | None
default: None
bool
default: True
v is ib le
Parameter Description
bool
default: True
str | None com ponent in the HTML DOM. Can be used for
list[str] 1str 1None assigned as the class of this com ponent in the
default: None HTML DOM. Can be used for targeting CSS styles.
^ G ro u p C o m p o n e n ts
0 . gradio Status
Custom Components GalleryNEW Explore
<§, gradio
New to Gradio? Start here: Getting Started See the Release History
^ Components Audio
AnnotatedImage
gradio.AnnotatedImage(•••)
0 Annotated Image
buildings
Description
Creates a component to displays a base image and colored annotations on top of
that image. Annotations can take the from of rectangles (e.g. object detection) or
masks (e.g. image segmentation). As this component does not accept user input,
it is rarely used as an input component.
Behavior
As input component: Passes its value as a tupie consisting of a s tr filepath to a
base image and l i s t of annotations. Each annotation itself is tupie of a mask (as
a s tr filepath to image) and a s tr label.
def predict(
return value
Initiaiization
Parameter Description
tuple[np.ndarray | pairs.
PIL.Image.Image |str,
Parameter Description
list[tuple[np.ndarray | tuple[int,
default: None
default: "webp" parameter only takes effect when the base image is
bool
default: True
default: None
to.
.load_event attribute.
bool 1None
default: None
default: True
respected first.
bool
default: True
Parameter Description
list[str] 1str 1None classes of this component in the HTML DOM. Can
component later.
Shortcuts
Interface String
Class imtialization
Shortcut
Demos
image_segmentation
import gradio as gr
▲
import numpy as np
import random
1
with gr.Blocks() as demo:
section_labels = [
"apple",
"banana",
"carrot",
donut",
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
default: "ful!"
component.
allowed to finish.
event is complete.
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Components Audio
$ gradio Status X o
Custom Components GalleryNEW Explore
<§, gradio =
New to Gradio? Start here: Getting Started See the Release History
^ AnnotatedImage BarPlot
Audio
gradio.Audio(•••)
<f3 Audio
t!_i
i_
Coloque el audio aquí
-o -
Haga click para cargar
& #
Description
Creates an audio component that can be used to upload/record audio (as an
input) or display audio (as an output).
Behavior
As input component: passes audio as one of these formats (depending on t y p e ):
def predict(
return value
Initiaiization
Parameter Description
str |Path | tuple[int, np.ndarray] | (sample rate in Hz, audio data as a float or int
Callable |None numpy array) for the default value that Audio
default: None first element in the list w ill be used as the default
True.
Parameter Description
to.
.load_event attribute.
bool 1None
default: None
default: True
default: None
Parameter Description
respected first.
bool | None file. If False, can only be used to play audio. If not
bool
default: True
list[str] Istr I None classes of this component in the HTML DOM. Can
component later.
Literal[('wav', ’mp3')] 'mp3'. wav files are lossless but will tend to be
default: False w ill not autoplay audio files if the user has not
components.
default: True
int |None user can pass into the prediction function. If None,
int 1None user can pass into the prediction function. If None,
these options.
Shortcuts
Interface String
Class Initialization
Shortcut
Uses sources=
g r a d i o . M ic r o p h o n e "microphone"
["microphone"]
Demos
generate_tone reverse_audio
import numpy as np
import gradio as gr
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
sr = 48000
duration = int(duration)
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
default: False
’hidden’)]
default: "hidden"
bool |None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
Parameter Description
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
^ Annotatedlmage BarPlot
0 gradio Status X o
Custom Components GalleryNEW Explore
<§, gradio
New to Gradio? Start here: Getting Started See the Release History
^ Audio Button
BarPlot
gradio.BarPlot(•••)
Loading...
Description ¿¡P
Creates a bar plot component to display data from a pandas DataFrame (as
output). As this component does not accept user input, it is rarely used as an
input component.
Behavior
As input component: (Rarely used) passes the data displayed in the bar plot as
value: AltairPlotData
return value
Initiaiization
Parameter Description
default: None the function w ill be called whenever the app loads
str 1None
default: None
str 1None
default: None
default: None
Parameter Description
default: None
str 1None
default: None
default: None
default: None
default: None
default: None
Literal[('left', 'right', 'top', 'none' is passed, this legend is omitted. For other
default: None
default: None
str 1None
default: None
Parameter Description
default: None
bool | None
default: None
c o n t a in e r
bool
default: True
s c a le
int I None
default: None
m in _ w id t h
int
default: 160
.load_event attribute.
bool
default: True
list[str] 1str 1None classes of this component in the HTML DOM. Can
component later.
Literal[('x ', 'y, '-x', '-y')] |None y". If None, no sorting is applied.
default: None
default: False
Shortcuts
Interface String
Class initialization
Shortcut
Demos
bar_plot
▲
import gradio as gr
import pandas as pd
I
import random
simple = pd.DataFrame(
"a": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
"b": [28, 55, 43, 91, 81, 53, 19, 87, 52],
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Supported Event Listeners
The B a r P lo t component supports the following event listeners. Each
event listener takes the same parameters, which are listed in the Event
Arguments table below.
Listener Description
Event Arguments
Parameter Description
output component.
default: None
Parameter Description
default: None
bool completion
default: False
default: "ful!"
bool 1None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Audio Button -
^ gradio Status O
Custom Components GalleryNEW Explore
gradio =
New to Gradio? Start here: Getting Started See the Release History
^ T a b b e d In te rfa c e R ow
Blocks
with gradio.Blocks():
Description
B lo c k s is G ra d io 's lo w -le v e l API t h a t a llo w s yo u to cre a te m o re c u s to m w e b
ta b s.
dem o.
Exampíe Usage
import gradio as gr
def update(name) :
with gr.Row():
out = gr.Textbox()
btn = gr.Button("Run")
demo.launch()
Initiaíization
Parameter Description
Theme |str | None a string, w ill look for a built-in theme with that
Default theme.
default: "Gradio"
Parameter Description
default: None
default: False expansion occurs when the scale value of the child
Demos
blocks helio b lo c k s _ flip p e r b lo c k s _ k in e m a tic s
import gradio as gr
def welcome(name):
g r .Markdown(
# Hello World!
.. )
Loading...
Methods
launch
gradio.Blocks.launch(•••)
Description
L a u n c h e s a s im p le w e b s e rv e r t h a t se rv e s th e d e m o . C an a ls o be u sed to
Exampíe Usage
import gradio as gr
def reverse(text):
return text[::-1]
button = gr.Button(value="Reverse")
Agruments
Parameter Description
default: False
GRADIO_SHARE=True.
(currently 40).
list[tuple[str, str]] | None app. Can also provide function that takes
valid login.
default: None
default: False True, the gradio app w ill not block and the
script finishes.
use "127.0.0.1".
default: 500
default: "100%"
str 1None it w ill be used as the favicon for the web page.
default: None
default: None
default: True
bool
default: False
show _api If True, shows the api docs in the footer of the
default: True
of your app.
"https://example.com/myapp", the
information.
default: None not authorized to access the app (they w ill see
queue
gradio.Blocks.queue(- ••)
Description
By e n a b lin g th e q u e u e y o u can c o n tro l w h e n u se rs k n o w th e ir p o s itio n in
th e q u e u e , a n d s e t a lim it on m á x im u m n u m b e r o f e v e n ts a llo w e d .
Exampíe Usage
())
demo.queue(max_size=10)
demo.launch()
Agruments
Parameter Description
of seconds.
default: None full, new events w ill not be added and a user
gr.Interface(concurrency_limit=10). If
intégrate
gradio.Blocks.integrate(•••)
Description
A c a tc h -a ll m e th o d fo r in te g ra tin g w ith o th e r lib ra rie s . T h is m e th o d s h o u ld
Agruments
Parameter Description
<class 'inspect._empty'> w ill integrate with the experim ent and appear
default: None
load
gradio.Blocks.load(block, •••)
Description
T h is lis te n e r is trig g e re d w h e n th e B lo c k s in it ia lly lo a d s in th e b row ser.
Agruments
Parameter Description
b lo c k
Block I None
required
output component.
default: None
default: None
default: False
'hidden')]
Parameter Description
default: "full"
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
unload
gradio.Blocks.unload(fn, •••)
Description
T h is lis te n e r is trig g e re d w h e n th e u se r c lo s e s o r re fre sh e s th e ta b , e n d in g
th e u se r s e ssio n . It is u se fu l fo r c le a n in g u p re s o u rce s w h e n th e a p p is
c lo se d .
Exampíe Usage
import gradio as gr
gr.Markdown("# When you close the tab, helio will be printed to the cons
ole")
demo.unload(lambda: print("hello"))
demo.launch()
Agruments
Parameter Description
Guides
Controlling Layout
State In Blocks
T a b b e d In te rfa c e R ow
$ gradio Status X O
Custom Components GalleryNEW Explore
<§, gradio
New to Gradio? Start here: Getting Started See the Release History
^ BarPlot Chatbot
Button
gradio.Button(•••)
Run
Description
Creates a button that can be assigned arbitrary .clickO events. The value (label) of
the button can be used as an input to the function (rarely used) or set via the
output of a function.
Behavior
As input component: (Rarely used) the s tr corresponding to the button label
def predict( cP
value: str | None
Initiaiization
Parameter Description
str | Callable the function w ill be called whenever the app loads
.load_event attribute.
'stop')]
default: "secondary"
default: None
default: None
default: None
bool
default: True
bool
default: True
list[str] 1str 1None classes of this component in the HTML DOM. Can
component later.
respected first.
Interface String
Class Initialization
Shortcut
Event Listeners
Description
Event listeners allow you to capture and respond to user ¡nteractions with
the UI components you've defined ¡n a Gradio Blocks app. When a user
¡nteracts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
output component.
default: None
bool completion
default: False
’hidden’)]
default: "ful!"
component.
allowed to finish.
event is complete.
Parameter Description
default_concurrency_lim it parameter in
BarPlot Chatbot
$ gradio Status X o
Custom Components GalleryNEW Explore
<§, gradio =
New to Gradio? Start here: Getting Started See the Release History
^ Button Checkbox
Chatbot
gradio.Chatbot(•••)
Loading...
Description
Creates a chatbot that displays user-submitted messages and responses.
Supports a subset of Markdown including bold, italics, code, tables. Also
supports audio/video/image files, which are displayed in the Chatbot, and other
kinds of files which are displayed as links. This component is usually used as an
output component.
Behavior
As input component: Passes the messages in the chatbot as a l i s t [ l i s t [ s t r |
None | tu p ie ]], i.e. a list of lists. The inner list has 2 elements: the user message
and the response message. Each message can be (1) a string in valid Markdown,
(2) a tupie if tiñere are displayed files: (a filepath or URL to a file, [optional string
alt text]), or (3) None, if there is no message displayed.
def predict(
lists. The inner list should have 2 elements: the user message and the response
message. The individual messages can be (1) strings in valid Markdown, (2) tuples
if sending files: (a filepath or URL to a file, [optional string alt text]) -- if the file is
image/video/audio, it is displayed in the Chatbot, or (3) None, in which case the
message is not displayed.
| None
return value
Initiaiization
Parameter Description
list[list[str | tuple[str] | tuple[str | function w ill be called whenever the app loads to
Path, str] I None]] | Callable | set the initial value of the component.
None
default: None
to.
.load_event attribute.
bool 1None
default: None
default: True
respected first.
bool
Parameter Description
default: True
list[str] 1str 1None classes of this component in the HTML DOM. Can
component later.
(https://katex.org/docs/autorender.html).
Parameter Description
bool message.
default: False
tuple[str 1Path |None, str | Path | and bot (in that order). Pass None for either the
URL.
default: True
default: True False, single new lines w ill be ignored. Only applies
in the config.
Literal[('panel', 'bubble')] | None layout. If "bubble", w ill display the chatbot with
default: None message bubbles, with the user and bot messages
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
import random
import time
chatbot = gr.Chatbot()
msg = gr.Textbox()
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
Event Arguments
Parameter Description
output component.
default: "ful!
Parameter Description
component.
allowed to finish.
event is complete.
default_concurrency_lim it parameter in
Button Checkbox
^ gradio Status X o
Custom Com ponents GalleryNEW Explore
$ gradio =
New to Gradio? Start here: Getting Started See the Release History
^ Interface TabbedInterface
ChatInterface
g r a d io . C h a t I n t e r f a c e ( f n , •••)
Description
ChatInterface is Gradio's high-level abstraction for creating chatbot UIs, and allows you to create a
based dem o around a chatbot model in a few lines of code. Only one parameter is required: fn, wh
takes a function that governs the response of the chatbot based on the user input and chat history
Additional parameters can be used to control the appearance and behavior of the demo.
Example Usage
im port g r a d io as gr
d e f ech o ( m essage, h i s t o r y ) :
r e t u r n message
demo = g r . C h a t I n t e r f a c e ( f n =ech o , exam ples=[ " h e l l o " , " h o l a " , "m erh ab a"] , t i t l e ="E ch o B o t " )
demo. la u n c h ( )
Initialization
Parameter Description
bool com ponent for the input, which allows for the uploading of
default: False multimedia files. If False, the chat interface will use a gr.Textbi
default: None not provided, a default gr.Chatbot com ponent will be created
Textbox 1M u ltim o d a lT e x tb o x |N o n e to use for the chat interface, if you would like to customize the
default: None then the com ponents will be displayed under the chatbot, in ;
accordion.
str |N on e
default: None
g r .A c c o r d io n ( la b e l= " A d d it io n a l In p u ts ",
a d d i t i o n a l _ i n p u t s is provided.
Parameter Description
list[str] |list[dict[str, s tr |list]] |list[list] | chatbot and can be clicked to popúlate the chatbot input.
N on e
default: None
b o o l |L ite ra l['la z y '] |N on e examples. The default option in HuggingFace Spaces is True. '
str |N on e font. Also used as the tab title when opened in a browser wind
default: None
str |N on e chatbot and beneath the title in regular font. Accepts Markdo\
T h e m e |s tr |N on e
default: None
css Custom css as a string or path to a css file. This css will be incl
default: None
default: None executed when the page loads. For more flexibility, use the he
head Custom html to insert into the head of the demo webpage. Th
sto p _ b tn Text to display on the stop button, which replaces the submit.
str 1N o n e |B u tto n when the subm it.btn or retry.btn is clicked and response is
default: "Stop" streaming. Clicking on the stop.btn will halt the chatbot
bool
default: True
in t |N o n e |L ite ra l['d e fa u lt'] can be running simultaneously. Can be set to None to mean n
in .q u e u e ( ) , which is 1 by default).
fill_ h e ig h t If True, the chat interface will expand to the height of window.
bool
default: True
default: None created by this Blocks instance will be deleted if more than ag
seconds have passed since the file was created. For example,
Demos
im port g r a d io as gr
d e f ech o ( m essage, h i s t o r y ) :
demo = g r . C h a t I n t e r f a c e ( f n =ech o , exam ples=[ { " t e x t " : " h e l i o " } , { " t e x t " : "h o la "} , { " t e x t " : "m e rh ab a"}]
demo. la u n c h ( )
Loading...
Guides
^ Interface TabbedInterface
$ gradio Status xO
Custom Components GalleryNEW Explore
<§, gradio
New to Gradio? Start here: Getting Started See the Release History
^ Chatbot CheckboxGroup
Checkbox
g r a d io . C h a tb o t( •••)
Loading...
Description
Creates a checkbox that can be set to True or False . Can be used as an input to
Behavior
As input component: Passes the status of the checkbox as a bool.
d e f p r e d ic t (
v a lu e : l i s t [ l i s t [ s t r | tu p le [ s t r ] | tu p le [ s t r , s t r ] | None] ] | None
. . . d e f p r e d ic t (
v a lu e : bool | None
As output component: Expects a bool value that is set as the status of the
checkbox
re tu rn v a lu e
Initialization
Parameter Description
bool | Callable will be called whenever the app loads to set the
to.
str I None
default: None
Parameter Description
.load_event attribute.
b o o l 1N o n e
default: None
default: True
respected first.
as an input or output.
Parameter Description
bool
default: True
list[str] Istr I None classes of this component in the HTML DOM. Can
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
sentence_builder hello_world_3
im port g ra d io as gr
▲
im port random
im port tim e
I
w ith g r . B lo c k s ( ) as demo:
▲
c h atb o t = gn. C h a tb o t( )
bot messase = nandom. c h o ic e ( [ ''How ane v o u ? " . " I lo v e v o u " . " I 'm venv hunsn
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
Event Arguments
Parameter Description
output component.
default: "ful!"
component.
allowed to finish.
event is complete.
default_concurrency_lim it parameter in
Chatbot CheckboxGroup -
^ gradio Status O
Custom Components GalleryNEW Explore
<§, gradio
New to Gradio? Start here: Getting Started See the Release History
^ Checkbox ClearButton
CheckboxGroup
g r a d io . C h a tb o t( •••)
Loading...
Description
Creates a checkbox that can be set to True or F a lse . Can be used as an input to
Behavior
As input component: Passes the status of the checkbox as a bool.
d e f p r e d ic t (
v a lu e : l i s t [ l i s t [ s t r | tu p le [ s t r ] | tu p le [ s t r , s t r ] | None] ] | None
. . . d e f p r e d ic t (
v a lu e : bool | None
As output component: Expects a bool value that is set as the status of the
checkbox
re tu rn v a lu e
Initialization
Parameter Description
bool | Callable will be called whenever the app loads to set the
to.
str I None
default: None
Parameter Description
.load_event attribute.
b o o l 1N o n e
default: None
default: True
respected first.
as an input or output.
Parameter Description
bool
default: True
list[str] Istr I None classes of this component in the HTML DOM. Can
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
sentence_builder hello_world_3
im port g ra d io as gr
▲
im port random
im port tim e
I
w ith g r . B lo c k s ( ) as demo:
▲
c h atb o t = gn. C h a tb o t( )
bot messase = nandom. c h o ic e ( [ ''How ane v o u ? " . " I lo v e v o u " . " I 'm venv hunsn
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
Event Arguments
Parameter Description
output component.
default: "ful!"
component.
allowed to finish.
event is complete.
default_concurrency_lim it parameter in
Chatbot CheckboxGroup -
^ gradio Status O
Custom Components GalleryNEW Explore
<§, gradio =
New to Gradio? Start here: Getting Started See the Release History
^ CheckboxGroup Code
ClearButton
gradio.ClearButton(•••)
Textbox
Clear
Description
Button that clears the value of a component or a list of components when
clicked. It is instantiated with the list of components to clear.
Behavior &
def predict(
return value
Initiaiization
Parameter Description
components
Com ponent
default: None
.load_event attribute.
L ite r a l[ C p rim a ry ’, 's e c o n d a ry , more subdued style, 'stop' for a stop button.
'stop')]
default: "secondary"
default: None
Parameter Description
default: None
default: None
bool
default: True
bool
default: True
component later.
Parameter Description
respected first.
api_name
default: None
show_api
bool
default: False
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
Event Arguments
Parameter Description
components
None |C o m p o n e n t |
lis t[C o m p o n e n t]
r e q u ir e d
CheckboxGroup Code
<§, gradio =
New to Gradio? Start here: Getting Started See the Release History
^ ClearButton ColorPicker
Code
gradio.Code(•••)
Loading...
Description ¿¡P
Creates a code editor for viewing code (as an output component), or for entering
Behavior
As input component: Passes the code entered as a s t r .
def predict(
)
As output component: Expects a s tr of code or a single-element tu p ie :
return value
Initiaiization
Parameter Description
s t r |C a lla b le |tu p le[str] |N o n e the function will be called whenever the app loads
’j s o n ’, h t m l , ’c s s , ja v a s c r ip t ,
m y S Q L , S q l- m a r ia D B , S q l-s q lite ,
S q l- c a s s a n d r a , S q l-p lS Q L , Sq l-
h iv e , S q l-p g S Q L , S q l- g q l, S q l-
g p S Q L , S q l-s p a rk S Q L , Sq l-
e s p e r ’)] |N o n e
default: None
.load_event attribute.
lin e s
Parameter Description
in t
default: 5
to.
b o o l 1N o n e view it.
default: None
b o o l 1N o n e
default: None
default: True
respected first.
bool
default: True
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
Event Arguments
Parameter Description
^ ClearButton ColorPicker
^ gradio Status X o
Custom Components GalleryNEW Explore
<§, gradio
New to Gradio? Start here: Getting Started See the Release History
^ Code Dataframe
ColorPicker
gradio.ColorPicker(•••)
ColorPicker
Description
Creates a color picker for user to select a color as string input. Can be used as an
input to pass a color value to a function or as an output to display a color value.
Behavior
As input component: Passes selected color value as a hex s tr into the function.
def predict( cP
value: str | None
As output component: Expects a hex s tr returned from function and sets color
Initiaiization
Parameter Description
str |C a lla b le |N o n e the function will be called whenever the app loads
to.
s t r 1N o n e
default: None
b o o l 1N o n e
default: None
default: True
Parameter Description
respected first.
bool
default: True
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
color_picker
▲
import gradio as gr
import numpy as np
import os
Args:
O
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
the UI components you've defined in a Gradio Blocks app. When a user
interacts with an element, such as changing a slider value or uploading an
image, a function is called.
Listener Description
g rad io.C olorP icker. chan Triggered when the value of the ColorPicker
ge(fn, •••) changes either because of user input (e.g. a
user types in a textbox) OR because of a
function update (e.g. an image receives a value
from the output of an event trigger). See
.inp ut() for a listener that is only triggered
by user input.
g rad io.C olorP icker. inpu This listener is triggered when the user
t ( f n, •••) changes the value of the ColorPicker.
g rad io.C olorP icker. subm This listener is triggered when the user presses
it ( f n , •••) the Enter key while the ColorPicker is focused.
g rad io.C olorP icker. focu This listener is triggered when the ColorPicker
s(fn, •••) is focused.
Event Arguments
Parameter Description
output component.
default: "ful!"
component.
allowed to finish.
event is complete.
default_concurrency_lim it parameter in
Code Dataframe
$ gradio Status X o
Custom Components Gallery NEW Explore
0 , gradio
New to Gradio? Start here: Getting Started See the Release History
R ow Tab
Column
with gradio.Column():
Description
C o lu m n is a la y o u t e le m e n t w ith in B lo c k s t h a t re n d e rs a ll c h ild re n v e rtic a lly . T he
p a ra m e te r w ill w in .
Exampíe Usage
with gr.Row():
with gr.Column(scale=1 ):
textl = gr.Textbox()
text2 = gr.Textbox()
with gr.Column(scale=4 ):
Initiaíization
Parameter Description
respected first.
default: "default"
bool
default: True
str | None com ponent in the HTML DOM. Can be used for
list[str] 1str 1None assigned as the class of this com ponent in the
default: None HTML DOM. Can be used for targeting CSS styles.
Controlling Layout
R ow Tab
^ gradio Status X O
Custom Components GalleryNEW Explore
*§ gradio
New to Gradio? Start here: Getting Started See the Release History
Components
G radio in cludes pre-built com ponents that can be used as in puts o r o utputs in yo ur Interface or B lo cks w ith a single line of code. Com ponents include preprocessing steps that convert user data subm itted through brow ser to
som ething th a t be can used by a Python fun ctio n, and postprocessin g steps to convert va lu e s returned by a Python function into som ething th a t can be displayed in a browser.
C on sider an exam ple w ith three in puts (Textbox, Number, and Image) and tw o o utputs (N um ber and G a lle ry), below is a diagram of w hat o ur preprocessing w ill send to the function and w hat our postprocessing w ill require from it.
C om ponents also come w ith certain events th a t th e y suppo rt. These are m ethods th a t are triggered w ith user actio ns. Below is a table show ing w hich eve nts are supported for each com ponent. All eve nts are also listed (w ith
param eters) in the com ponent's docs.
submit stop_recording edit like start_recording click change upload release blur play apply pause_recording
AnnotatedImage X X X X X X X X X X X X X X X X X X X X X y
Audio X y y y y X X y X y X y y X X y X y X X X X
BarPlot X X X X X X X y X X X y X X X X X X X X X X
Button X X X X X X X X X X y X X X X X X X X X X X
Chatbot X X X X X X y X X X X y X X X X X X X X X y
Checkbox X X X X X X X X X X X y X X X X X X X X y y •.
-o gradio Status
Custom Com ponents G a lle ry NEW E x p lo re
*§ gradio =
New to Gradio? Start here: G ettíng Started See the Release Hístory
^ C o lo r P ic k e r D a ta se t
Dataframe
g r a d i o .Dat a f r a m e ( ■■■)
1 ▲ 2 ▲ 3 ▲ ^
4 ►
Description
T h is c o m p o n e n t d is p la y s a ta b le o f v a lu e s p re a d s h e e t-lik e c o m p o n e n t. C a n be u se d to d is p la y d a ta as an o u t p u t c o m p o n e n t, o r as an
Behavior
A s in p u t c o m p o n e n t: P asses th e u p lo a d e d s p r e a d s h e e t d a ta as a p a n d a s .D a ta F ra m e , n u m p y .a rr a y , p o la r s .D a t a F r a m e , o r n a tiv e 2D
P y th o n l i s t [ l i s t ] d e p e n d in g o n t y p e
def p r e d i c t (
A s o u t p u t c o m p o n e n t : E x p e c ts d a ta a n y o f th e s e fo rm a ts: p a n d a s .D a ta F ra m e , p a n d a s . S t y le r , n u m p y .a rr a y , p o la r s .D a t a F r a m e ,
def p r e d i c t ( ■■■) -> p d .DataFrame | Styler | n p .ndarray | p l .DataFrame | list | l i s t [li s t ] | dict | str | None
Initialization
Param eter D escription
v a lu e Default value to display in the DataFrame. If a Styler is provided, it w ill be used to set
pd.DataFrame | Styler |np.ndarray |pl.DataFrame | list | the displayed value in the DataFrame (e.g. to set precision of numbers) if the
list[list] | dict |str | Callable |None I n t e r a c t i v e is False. If a Callable function is provided, the function w ill be called
default: None whenever the app loads to set the initial value of the com ponent.
list[str] |None
default: None
row _count Lim it num ber of rows for input and decide whether user can create new rows. The
int | tuple[int, str] first elem ent of the tuple is an i n t , the row count; the second should be 'fixed' or
default: (1, 'dynamic') 'dynamic', the new row behaviour. If an i n t is passed the rows default to 'dynam ic'
c o l_ c o u n t Lim it num ber of colum ns for input and decide whether user can create new columns.
int | tuple[int, str] |None The first elem ent of the tuple is an i n t , the num ber of columns; the second should be
default: None 'fixed' or 'dynamic', the new colum n behaviour. If an i n t is passed the colum ns
d a ta ty p e Datatype of valúes in sheet. Can be provided per colum n as a list of strings, or for the
str | list[str] entire sheet as a single string. Valid datatypes are "str", "number", "bool", "date", and
Literal[('pandas', 'numpy', 'array', 'polars')] "num py" for numpy array, "polars" for polars dataframe, or "array" for a Python list of
la t e x _ d e lim ite r s A list of dicts of the form " l e f t " : open d e l i m i t e r ( s t r ) , " r ig h t " : c lo s e
default: None that w ill be used to render LaTeX expressions. If not provided, l a t e x _ d e l i m i t e r s is
set to [ " l e f t " : "$ $ ", " r ig h t " : "$ $ ", " d is p la y " : T r u e ] , so only
expressions enclosed in $$ delim iters w ill be rendered as LaTeX, and in a new line.
Pass in an em pty list to disable LaTeX rendering. For more inform ation, see the [KaTeX
la b e l The label for this com ponent. Appears above the com ponent and is also used as the
str |None header if there are a table of examples for this com ponent. If None and used in a
default: None g r . I n t e r f a c e , the label w ill be the name of the parameter this com ponent is
assigned to.
boo! I None
default: None
e ve ry If v a lu e is a callable, run the function 'every' num ber of seconds while the client
float INone connection is open. Has no effect otherwise. The event can be accessed (e.g. to cancel
h e ig h t The m aximum height of the dataframe, specified in pixels if a num ber is passed, or in
int CSS units if a string is passed. If more rows are created than can fit in the height, a
s c a le relative size com pared to adjacent Com ponents. For example if Com ponents A and B
int INone are in a Row, and A has scale=2, and B has scale=1, A w ill be twice as wide as B.
default: None Should be an integer. scale applies in Rows, and to top-level Com ponents in Blocks
where fill_height=True.
m in_w idth m inim um pixel width, w ill wrap if not sufficient screen space to satisfy this value. If a
int certain scale value results in this Com ponent being narrower than m in_width, the
in t e r a c t iv e if True, w ill a llow users to edit the dataframe; if False, can only be used to display
boo! |None data. If not provided, this is inferred based on w hether the com ponent is used as an
boo!
default: True
e le m _ id An optional string that is assigned as the id of this com ponent in the HTML DOM. Can
default: None
e le m _ c la s s e s An optional list of strings that are assigned as the classes of this com ponent in the
!ist[str] |str |None HTML DOM. Can be used for targeting CSS styles.
Parameter Descríptíon
default: None
ren d er If False, com ponent w ill not render be rendered in the Blocks context. Should be used
bool if the intention is to assign event listeners now but render the com ponent later.
default: True
wrap If True, the text in table cells w ill wrap when appropriate. If False and the
bool c o lu m n _ w id th parameter is not set, the colum n widths w ill expand based on the cell
default: False contents and the table may need to be horizontally scrolled. If c o lu m n _ w id th is set,
lin e _ b r e a k s If True (default), w ill enable Github-flavored Markdown line breaks in chatbot
bool messages. If False, single new lines w ill be ignored. Only applies for colum ns of type
c o lu m n _ w idth s An optional list representing the w idth of each colum n. The elem ents of the list
list[str |int] | None should be in the form at "100px" (ints are also accepted and converted to pixel values)
default: None or "10%". If not provided, the colum n w idths w ill be autom atically determ ined based
on the content of the cells. Setting this parameter w ill cause the browser to try to fit
Shortcuts
Class Interface Stríng Shortcut Initialization
Demos
f ilt e r _ r e c o r d s m a tr ix _ tr a n s p o s e t a x _ c a lc u la to r s o rt_ re c o rd s
import g r adio as gr
return r e c o r d s [r e c o rds["gender"] == ge n d e r ]
demo = g r .Int e r f a c e (
filt e r _ r e c o r d s ,
g r .Data f r a m e (
Loading...
Description
E ve n t lis te n e rs a llo w y o u to c a p tu r e a n d re s p o n d to u s e r in te r a c tio n s w ith th e UI c o m p o n e n t s y o u 'v e d e fin e d in a G ra d io
Listener Description
g n a d io . Datafname. change(f n , •••) Triggered when the valúe of the Dataframe changes either because of user input
(e.g. a user types in a textbox) OR because of a function update (e.g. an image
receives a value from the output of an event trigger). See .in p u t ( ) for a listener
that is o nly triggered by user input.
g n a d io . Datafname. in p u t (f n , •••) This listener is triggered when the user changes the value of the Dataframe.
g n a d io . Datafname. s e le c t (f n , •••) Event listener for when the user selects or deselects the Dataframe. Uses event
data gradio.SelectData to carry v a lu e referring to the label of the Dataframe, and
s e le c te d to refer to state of the Dataframe. See EventData docum entation on
how to use this event data
Event Arguments
Parameter Description
fn the function to call when this event is triggered. Often a m achine learning
Callable | None | Literal['decorator'] m odel's prediction function. Each parameter of the function corresponds to one
default: "decorator" input com ponent, and the function should return a single value or a tuple of
values, with each elem ent in the tuple corresponding to one output com ponent.
in p u t s List of gradio.com ponents to use as inputs. If the function takes no inputs, this
default: None
default: None
api_nam e defines how the endpoint appears in the API docs. Can be a string, None, or False.
str | None |Literal[False] If set to a string, the endpoint w ill be exposed in the API docs with the given
default: None name. If None (default), the name of the function w ill be used as the API
endpoint. If False, the endpoint w ill not be exposed in the API docs and
downstream apps (including those that g r .lo a d this app) w ill not be able to use
this event.
bool
default: False
default: "full"
queue If True, w ill place the request on the queue, if the queue has been enabled. If
bool | None False, w ill not put this event on the queue, even if the queue has been enabled. If
default: None None, w ill use the queue setting of the gradio app.
b a tc h If True, then the function should process a batch of inputs, meaning that it should
bool accept a list of input values for each parameter. The lists should be of equal
Parameter Descríptíon
default: False length (and be up to length m ax_batch_size). The function is then required to
return a tupie of lists (even if there is only 1 output com ponent), with each list in
m a x _ b a tc h _ s iz e Maximum num ber of inputs to batch together if this is called from the queue
default: 4
p re p r o c e s s If False, w ill not run preprocessing of com ponent data before running 'fn' (e.g.
bool leaving it as a base64 string if this m ethod is called with the Image component).
default: True
p o s tp r o c e s s If False, w ill not run postprocessing of com ponent data before returning 'fn'
default: True
c a n c e ls A list of other events to cancel when this listener is triggered. For example, setting
dict[str, Any] |list[dict[str, Any]] | None cancels=[click_event] w ill cancel the click_event, where click_event is the return
default: None value of another com ponents .click method. Functions that have not yet run (or
generators that are iterating) w ill be cancelled, but functions that are currently
e v e ry Run this event 'every' num ber of seconds w hile the client connection is open.
default: None
t rig g e r _ m o d e If "once" (default for a ll events except .ch a nge ()) would not a llow any
Llterai[('once'í ' e,'a iw a y sja st')] |None subm issions w hile an event is pending. If set to "m ultiple", unlim ited subm issions
ltip
ú
m
default: None are allowed w hile pending, and "always_last" (default for .change() and
.key_up() events) w ould allow a second subm ission after the pending event is
complete.
js O ptional frontend js method to run before running 'fn'. Input arguments for js
str 1None method are values of 'inputs' and 'outputs', return should be a list of values for
c o n c u r r e n c y _ lim it If set, this is the maximum num ber of this event that can be running
int 1None | Literai['defauit'] sim ultaneously. Can be set to None to mean no concurrency_lim it (any number
default: "default" of this event can be running sim ultaneously). Set to "default" to use the default
c o n c u r r e n c y _ id If set, this is the id of the concurrency group. Events with the same
str | None concurrency_id w ill be lim ited by the low est set concurrency_lim it.
default: None
sh o w _ a p i whether to show this event in the "view API" page of the Gradio app, or in the
bool ".view_api()" m ethod of the Gradio clients. Unlike setting api_nam e to False,
default: True setting show_api to False w ill still a llow downstream apps to use this event. If fn
C o lo r P ic k e r D a ta se t
^ gradio =
New to Gradio? Start here: Getting Started See the Release History
^ Dataframe DownloadButton
Dataset
gr.Dataset(components, samples)
:= Text Dataset
Build & share delightful machine learning apps She sells seashells by the seashore
Description
Creates a gallery or table to display data samples. This com ponent is designed for
Behavior
As input com ponent: Passes the selected sample either as a l i s t of data
corresponding to each input com ponent (if type is "value") or as an in t index (if
type is "index")
d e f p r e d ic t (
[P
v a l u e : pd. DataFrame | np. n d a rra y | p l . DataFrame | lis t [lis t ]
. . . d e f p r e d ic t (
v a lu e : in t | lis t | None
)
d e f p r e d ic t ( " 0 -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e d e f p r e d ic t ( " 0 -> l i s t [ l i s t ]
re t u r n v a lu e
InitiaMzation
Parameter Description
default: None
TimeSeries, Video
c o m p o n e n t_ p r o p s
default: None
Parameter Description
int
default: 10
bool
default: True
str 1None com ponent in the HTML DOM. Can be used for
list[str] 1str 1None classes of this com ponent in the HTML DOM. Can
default: True
respected first.
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
event listener takes the same parameters, which are listed in the Event
Listener Description
(f n , • • • )
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
default: "full
Parameter Description
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
^ Dataframe DownloadButton
^ gradio Status J C
Custom Components GalleryNEW Explore
^ gradio
New to Gradio? Start here: Getting Started See the Release History
^ Dataset Dropdown
DownloadButton
gradio.DownloadButton(•••)
Description
Creates a button, that when clicked, allows a user to download a single file of
arbitrary type.
Behavior
As input com ponent: (Rarely used) passes the file as a s t r into the function.
d e f p r e d ic t (
[P
v a l u e : pd. DataFrame | np. n d a rra y | p l . DataFrame | lis t [lis t ]
. . . d e f p r e d ic t (
v a lu e : s t r | None
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
str "Download".
default: "Download"
.load_event attribute.
Literal[(’prim ary’, ’secondary’, more subdued style, 'stop' for a stop button.
'stop')]
default: "secondary"
bool
default: True
Parameter Description
default: None
default: None
respected first.
bool state.
default: True
str I None com ponent in the HTML DOM. Can be used for
list[str] Istr I None classes of this com ponent in the HTML DOM. Can
Parameter Description
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
upload_and_download
import gradio as gr
def upload_file(filepath):
name = Path(filepath).name
def download_file():
e)]
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
listeners. Each event listener takes the same parameters, which are listed
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
Parameter Description
default: "full"
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
^ Dataset Dropdown
^ gradio Status J C
Custom Components GalleryNEW Explore
^ gradio
New to Gradio? Start here: Getting Started See the Release History
^ DownloadButton DuplicateButton
Dropdown
gradio.Dropdown(•••)
<30
Loading...
Description
Creates a dropdown of choices from which a single entry or múltiple entries can
Behavior
As input com ponent: Passes the value of the selected dropdown choice as a s t r
m u ltis e le c t is True, passes the values of the selected dropdown choices as a list
. . . d e f p r e d ic t (
d e f p r e d ic t ( " 0 -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Imtiaíization
Parameter Description
list[str |int | float | tuple[str, str | can also be a tuple of the form (name, value),
str |int | float | list[str |int | float] | value is selected by default. If callable, the function
Callable |None w ill be called whenever the app loads to set the
bool | None
default: None
default: False
default: None
str I None com ponent and is also used as the header if there
to.
str |None
default: None
Parameter Description
.load_event attribute.
bool 1None
default: None
default: True
respected first.
default: None
Parameter Description
bool
default: True
str |None com ponent in the HTML DOM. Can be used for
list[str] Istr I None classes of this com ponent in the HTML DOM. Can
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
sentence builder
▲
import gradio as gr
I
▲
ning) :
demo = g r . I n t e r f a c e (
<30
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
event listener takes the same parameters, which are listed in the Event
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
default: "full
Parameter Description
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
^ DownloadButton DuplicateButton
^ gradio Status J C
Custom Components GalleryNEW Explore
^ gradio =
New to Gradio? Start here: Getting Started See the Release History
^ Dropdown File
DuplicateButton
gradio.DuplicateButton(•••)
Duplicate Space
Description
Button that triggers a Spaces Duplication, when the demo is on Hugging Face
Behavior
As input com ponent: (Rarely used) the s t r corresponding to the button label
d e f p r e d ic t (
[P
v a l u e : pd. DataFrame | np. n d a rra y | p l . DataFrame | lis t [lis t ]
. . . d e f p r e d ic t (
v a lu e : s t r | None
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
.load_event attribute.
Literal[(’prim ary’, ’secondary’, more subdued style, 'stop' for a stop button.
'stop')]
default: "secondary"
default: "sm"
default: None
Parameter Description
default: None
bool
default: True
bool
default: True
str 1None com ponent in the HTML DOM. Can be used for
list[str] 1str 1None classes of this com ponent in the HTML DOM. Can
respected first.
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
listeners. Each event listener takes the same parameters, which are listed
Listener Description
(f n , • • • )
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
default: "full"
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Dropdown File
^ gradio Status J C
Custom Components GalleryNEW Explore
$ gradio
New to Gradio? Start here: Getting Started See the Release History
EventData Warning
Error
gradio.Error(•••)
Description
This class allows you to pass custom error messages to the user. You can do so by
raising a gr.Error("custom message") anywhere in the code, and when that line is
Exampíe Usage
import gradio as gr
if denominator == 0 :
Parameter Description
<class 'str'>
Demos
calculator blocks_chained_events
import gradio as gr
if operation == "add":
EventData Warning
Status
^ gradio o
Custom Components GalleryNEW Explore
$ gradio
New to Gradio? Start here: Getting Started See the Release History
set_static_paths Examples
EventData
gradio.EventData(target, •••)
Description
information about the event that triggered the listener, such the target object,
and other data related to the specific event that are attributes of the subclass.
statement = gr.Textbox()
def on_select(evt: gr.SelectData): # SelectData is a subclass of EventData
InitiaMzation
Parameter Description
Demos
gallery_select¡ons tictactoe
▲
import gradio as gr
import numpy as np
imgs = gr.State()
I
gallery = gr.Gallery(allow_preview=False)
def deselect_images():
return gr.Gallery(selected_index=None)
def generate_images():
Loading...
set_static_paths Examples
Status
^ gradio o
Custom Components GalleryNEW Explore
$ gradio
New to Gradio? Start here: Getting Started See the Release History
EventData Progress
Examples
Description
This class is a wrapper over the Dataset com ponent and can be used to create
Examples for Blocks / Interfaces. Populates the Dataset com ponent with
examples and assigns event listener so that clicking on an example populates the
inference.
Initialization
Parameter Description
corresponding inputs.
required
default: None cached after their first use. Can also be set by the
"tru e ", " la z y " , o r " f a l s e " (for the first two
int
default: 10
default: "Examples"
default: None
default: False clicked. Set this to True to run the function when
cache_examples is True.
False.
Parameter Description
False.
example function.
Demos
fake_gan
▲
# This demo needs to be run from the repo folder.
# python demo/fake_gan/run.py
import random
import gradio as gr
I
▲
def fake_gan():
images = [
(random.choice(
[
I
Loading...
Guides
Status
^ gradio o
Custom Components GalleryNEW Explore
^ gradio =
New to Gradio? Start here: Getting Started See the Release History
^ DuplicateButton FileExplorer
File
gradio.File(•••)
Loading...
Description
Creates a file com ponent that allows uploading one or more generic files (when
used as an input) or displaying generic files or URLs for download (as output).
Behavior
As input com ponent: Passes the file as a s t r or bytes object, or a list of s t r or list
d e f p r e d ic t (
)
. . . d e f p r e d ic t (
filepaths/URLs.
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
str |list[str] | Callable | None URL, or a list of str file paths / URLs. If callable, the
default: "single" directory. Return type w ill be list for each file in
files to be uploaded.
Literal[('filepath', ’binary')] returns a temporary file object with the same base
default: "filepath" name as the uploaded file, whose full path can be
bytes object.
str |None com ponent and is also used as the header if there
to.
bool 1None
default: None
default: True
Parameter Description
respected first.
as an input or output.
bool
default: True
str I None com ponent in the HTML DOM. Can be used for
list[str] |str | None classes of this com ponent in the HTML DOM. Can
Shortcuts
Interface String
Class Initialization
Shortcut
Uses
g r a d io . F ile s "files"
file count="multiple"
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
listener takes the same parameters, which are listed in the Event Arguments
table below.
Listener Description
Event Arguments
Parameter Description
output component.
set[Component] | None
default: None
default: None
bool completion
default: False
’hidden’)]
default: "full"
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
Parameter Description
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
^ DuplicateButton FileExplorer
^ gradio Status J C
Custom Components GalleryNEW Explore
^ gradio =
New to Gradio? Start here: Getting Started See the Release History
^ File Gallery
FileExplorer
gradio.FileExplorer(•••)
Loading...
Description
Creates a file explorer com ponent that allows users to browse files on the
machine hosting the Gradio app. As an input component, it also allows users to
Behavior
As input com ponent: Passes the selected file or directory as a s t r path (relative
to ro o t) or l i s t [ s t r ] depending on file _ c o u n t
. . . d e f p r e d ic t (
v a lu e : l i s t [ s t r ] | str | None
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Initiaíization
Parameter Description
default: "**/*" all .png files, "/*.txt" to match any .txt file in any
documentation at
https://docs.python.org/3/library/glob.html for
more information.
default: "."
str 1None used to exclude files from the list. For example,
default: None "*.py" w ill exclude all .py files from the list. See the
https://docs.python.org/3/library/glob.html for
more information.
str |None com ponent and is also used as the header if there
to.
default: None
Parameter Description
bool | None
default: None
default: True
respected first.
input or output.
bool
default: True
str |None com ponent in the HTML DOM. Can be used for
list[str] Istr I None classes of this com ponent in the HTML DOM. Can
ro o t
None
default: None
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
file_explorer
▲
import gradio as gr
current_file_path = Path(__file__).resolve()
I
relative_path = "path/to/file"
()
def get_file_content(file):
return (file,)
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
Each event listener takes the same parameters, which are listed in the
Listener Description
gradio.Dataframe.change
(fn, •••)
Event Arguments
Parameter Description
output component.
default: None
default: None
Parameter Description
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
File Gallery
^ gradio Status J C
Custom Com ponents G alleryNEW Explore
$ gradio
New to Gradio? Start here: Getting Started See the Release History
mount_gradio_app Themes
Flagging
Description
A Gradio Interface includes a 'Flag' button that appears underneath the output.
By default, clicking on the Flag button sends the input and output data back to
the machine where the gradio demo is running, and saves it to a CSV log file. But
this default behavior can be changed. To set what happens when the Flag button
SimpleCSVLogger
gradio.SimpleCSVLogger(•••)
Descri ption
illustrative purposes. Each flagged sample (both the input and output data) is
Exampíe Usage
import gradio as gr
def image_classifier(inp):
flagging_callback=SimpleCSVLogger())
CSVLogger
gradio.CSVLogger(•••)
Description
sample (both the input and output data) is logged to a CSV file with headers on
Exampíe Usage
import gradio as gr
def image_classifier(inp):
flagging_callback=CSVLogger())
InitiaMzation
Parameter Description
s im p lif y _ f ile _ d a t a
bool
default: True
Guides
Using Flagging
HuggingFaceDatasetSaver
Description
A callback that saves each flagged sample (both the input and output data) to a
HuggingFace dataset.
Exampíe Usage
import gradio as gr
s")
def image_classifier(inp):
allow_flagging="manual", flagging_callback=hf_writer)
Initiaíization
Parameter Description
required classifier-1".
bool False).
default: False
convenient to use.
Guides
Using Flagging
mount_gradio_app Themes
Status
$ gradio X o
Custom Com ponents G alleryNEW Explore
^ gradio =
New to Gradio? Start here: Getting Started See the Release History
^ FileExplorer HTML
Gallery
gradio.Gallery(•••)
Loading...
Description
Creates a gallery com ponent that allows displaying a grid of images, and
optionally captions. If used as an input, the user can upload images to the
gallery. If used as an output, the user can click on individual images to view them
at a higher resolution.
Behavior
As input com ponent: Passes the list of images as a list of (image, caption) tuples,
or a list of (image, None) tuples if no captions are provided (which is usually the
case). The image can be a s t r file path, a numpy array, or a PlL.lm age object
depending on ty p e .
. . . d e f p r e d ic t (
p l e [ np . n d a r ra y , s t r | None] ] | None
P lL .lm a g e o b je ct.
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Initiaíization
Param eter Description
|str I Path I tupie] | Callable | app loads to set the initial value of the component.
None
default: None
default: "w ebp" parameter only applies to images that are returned
PIL library.
str |None com ponent and is also used as the header if there
to.
.load_event attribute.
bool 1None
default: None
default: True
respected first.
bool
default: True
str |None com ponent in the HTML DOM. Can be used for
list[str] Istr I None classes of this com ponent in the HTML DOM. Can
int I tupie I None shown in one row, for each of the six standard
int I tupie I None for each of the six standard screen sizes (<576px,
Parameter Description
fewer than 6 are given then the last w ill be used for
default: True
bool | None shows all of the images as thum bnails and allows
default: None the user to click on them to view them in full size.
Literal[('contain', 'cover', ’fill’, the gallery. Can be "contain", "cover", "fill", "none",
default: None
bool | None of the selected image. If False, the icon does not
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
fake_gan
I
▲
# This demo needs to be run from the repo folder.
# python demo/fake_gan/run.py
import random
import gradio as gr
def fake_gan():
images = [
(random.choice(
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
event listener takes the same parameters, which are listed in the Event
Arguments table below.
Listener Description
Event Arguments
Parameter Description
output component.
set[Component] | None
default: None
default: None
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
Parameter Description
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
FileExplorer HTML ^
^ gradio Status J C
Custom Components GalleryNEW Explore
gradio =
New to Gradio? Start here: Getting Started See the Release History
^ Tab A c c o rd io n
Group
with gradio.Group():
Description
G ro u p is a la y o u t e le m e n t w ith in B lo c k s w h ic h g ro u p s to g e th e r c h ild re n so th a t
th e y d o n o t h ave a n y p a d d in g o r m a rg in b e tw e e n th e m .
Exampíe Usage
with gr.Group():
gr.Textbox(label="First")
gr.Textbox(label="Last")
Initiaíization ¿¡P
Parameter Description
bool
default: True
str | None com ponent in the HTML DOM. Can be used for
list[str] |str | None assigned as the class of this com ponent in the
default: None HTML DOM. Can be used for targeting CSS styles.
^ Tab A c c o rd io n
^ gradio =
New to Gradio? Start here: Getting Started See the Release History
^ HTML Image
HighlightedText
gradio.HighlightedText(•••)
Loading...
g rad io/high lig hted text_ com p on ent built with Gradio. Hosted on HS Spaces
Description
Displays text that contains spans that are highlighted by category or numerical
value.
Behavior
As input com ponent: Passes the value as a list of tuples as a li s t [ t u p le ] into
the function. Each tu p ie consists of a s t r substring of the text (so the entire text
of that substring.
. . . d e f p r e d ic t (
two keys: "text", and "entities", which itself is a list of dictionaries, each of which
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Initiaíization
Param eter Description
list[tuple[str, str | float | None]] | be called whenever the app loads to set the initial
default: None
default: None For example: " p e r s o n " : "re d ", " l o c a t io n " :
#FFEE22
Parameter Description
default: False
default: False
default: ""
str |None com ponent and is also used as the header if there
to.
.load_event attribute.
bool | None
default: None
Parameter Description
default: True
respected first.
bool
default: True
str I None com ponent in the HTML DOM. Can be used for
list[str] Istr I None classes of this com ponent in the HTML DOM. Can
default: None
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
diff_texts
I
▲
from difflib import Differ
import gradio as gr
d = Differ()
return [
]
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
listeners. Each event listener takes the same parameters, which are listed
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
N a m e d Entity Recognition
HTML Im age
^ gradio Status J C
Custom Com ponents G alleryNEW Explore
—
*§, gradio
^ Gallery HighlightedText
HTML
gradio.HTML(•••)
Description
Creates a com ponent to display arbitrary HTM L output. As this com ponent does
Behavior
As input com ponent: (Rarely used) passes the HTML as a s t r .
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : s t r | None
d ic t | s tr | None
re t u r n v a lu e
Initiaíization
Parameter Description
str | Callable | None whenever the app loads to set the initial value of
is assigned to.
.load_event attribute.
bool | None
default: None
bool
Parameter Description
default: True
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
blocks_scroll
import gradio as gr
demo = gr.Blocks()
with demo:
scroll_btn = gr.Button("Scroll")
no_scroll_btn = gr.Button("No Scroll")
big_block = gr.HTML(..
<6
Loading...
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
ta b le below .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
Parameter Description
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Guides
Key Features
^ Gallery HighlightedText
^ gradio Status J C
Custom Com ponents G allery NEW E x p lo r e
^ gradio =
^ HighlightedText ImageEditor
Image
gradio.Image(•••)
0 Image
i_!_i
C o lo q u e la im a g e n a q u í
-o -
H aga c lic k p a ra c a rg a r
£ ©s
gradio/image_component built with Gradio. Hosted on B Spaces
Description
Creates an image com ponent that can be used to upload images (as an input) or
Behavior
As input com ponent: Passes the uploaded image as a numpy.array, PlL.lm age
or s t r filepath depending on typ e . For SVGs, the type parameter is ignored and
. . . d e f p r e d ic t (
p a t h lib . P a t h file p a th to an im a g e w h ic h is d is p la y e d .
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Initiaíization
Param eter Description
default: None whenever the app loads to set the initial value of
the component.
'CMYK', YCbCr, 'LAB, HSV, 'I, /concepts.html for other supported image modes
default: "RGB"
list[Literal[(’upload, 'webcam, box where user can drop an image file, "webcam"
Literal[('numpy, p il, 'filepath ’)] passed into the prediction function. "numpy"
default: "num py" converts the image to a numpy array with shape
str |None com ponent and is also used as the header if there
to.
.load_event attribute.
bool I None
default: None
bool
default: True
default: True
respected first.
bool
default: True
str 1None com ponent in the HTML DOM. Can be used for
list[str] 1str 1None classes of this com ponent in the HTML DOM. Can
bool
default: True
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
import numpy as np
import gradio as gr
def sepia(input_img):
sepia_filter = np.array([
])
▲
sepia_img = input_img.dot(sepia_filter.T)
sepia_img /= sepia_img.max()
___ 1
<6
Loading...
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
ta b le below .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
Parameter Description
default: None
bool completion
default: False
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Guides
^ HighlightedText ImageEditor
^ gradio Status J C
Custom Com ponents G alleryNEW Explore
^ gradio =
^ Image JSON
ImageEditor
gradio.ImageEditor(•••)
Loading...
Description
Creates an image com ponent that, as an input, can be used to upload and edit
images using simple editing tools such as brushes, strokes, cropping, and layers.
Behavior
As input com ponent: Passes the uploaded images as an instance of EditorValue,
which is just a d ic t with keys: 'background', 'layers', and 'composite'. The values
. . . d e f p r e d ic t (
v a l u e : E d it o r V a lu e | None
th e b a ck g ro u n d .
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Initiaíization
Param eter Description
'CMYK', YCbCr, 'LAB, HSV, 'I, /concepts.html for other supported image modes
default: "RGBA"
'webcam, ’clipboard’)]] |None user can drop an image file, "webcam" allows user
Literal[('numpy, p il, 'filepath ’)] being passed into the prediction function.
str |None com ponent and is also used as the header if there
to.
.load_event attribute.
bool I None
default: None
bool
default: True
default: True
respected first.
bool
default: True
component later.
Param eter Description
bool
default: True
tuple[int I float, int | float] |str | value is the width and the second value is the
default: ('crop',)
default: None None to use the default settings. Can also be False
default: None None to use the default settings. Can also be False
eraser tool.
Parameter Description
default: True
tu p le [in t, int] |N o n e the first value is the width and the second value is
default: None the height. If None, the canvas size will be the
Shortcuts
Interface String
Class Initialization
Shortcut
Uses sources=(),
brush=Brush(colors=
g r a d i o .S k e t c h p a d "sketchpad"
["#000000"],
color_mode="fixed")
Uses
brush=Brush(colors=
g r a d i o .I m a g e M a s k "imagemask"
["#000000"],
color_mode="fixed")
Demos
image_editor
import gradio as gr
import time
def sleep(im):
time.sleep(5)
te"]]
def predict(im):
▼
<30
Loading...
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Image JSON ^
^ gradio Status J C
Custom Com ponents G alleryNEW E xp lore
$ gradio
W a rn in g R e q u e st
Info
gradio.Info(•••)
Description
import gradio as gr
def hello_world():
demo.queue().launch()
InitiaMzation
str
Demos
blocks_chained_events
▲
import gradio as gr
import time
I
def failure():
def exception():
def success():
Loading...
W a rn in g R e q u e st
Status
^ gradio o
Custom Com ponents G alleryNEW E xp lore
^ gradio =
Im a g e E d ito r L ab e l
JSON
gradio.JSON(•••)
Loading...
Description
U sed to d is p la y a rb itra ry JS O N o u tp u t p rettily. A s th is c o m p o n e n t d o e s n ot
a c c e p t u se r in p u t, it is ra re ly used as an in p u t c o m p o n e n t.
Behavior
As input com ponent: P asses th e JS O N v a lu e as a d i c t o r l i s t d e p e n d in g on th e
valu e.
d e f p r e d ic t (
)
. . . d e f p r e d ic t (
v a lu e : d ic t | lis t | None
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
str |dict | list | Callable |None d i c t that can be serialized to a JSON string. If
str |None com ponent and is also used as the header if there
to.
.load_event attribute.
bool |N o n e
default: None
default: True
respected first.
bool
default: True
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
z ip _ to js o n b lo ck s_ x ra y
import gradio as gr
def zip_to_json(file_obj):
files = []
files.append(
{
Loading...
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
ta b le below .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Im a g e E d ito r L ab e l
^ gradio Status J C
Custom Com ponents G alleryNEW E xp lore
^ gradio =
^ JSON LinePlot ^
Label
gradio.Label(•••)
Loading...
g r a d i o / l a b e l _ c o m p o n e n t b u ilt w ith G ra d io . H o s te d o n HS S p a c e s
Description
Displays a classification label, along with confidence scores of top categories, if
provided. As this com ponent does not accept user input, it is rarely used as an
input component.
Behavior
As input com ponent: Depending on the value, passes the label as a s t r | in t |
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : d i c t [ s t r , f l o a t ] | s tr | in t | flo a t | None
d e f p r e d ic t ( " 0 -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Imtiaíization
Param eter Description
dict[str, flo a t] |s t r |flo a t | number is provided, sim ply displays the string or
in t |N o n e
default: None
Parameter Description
str |None com ponent and is also used as the header if there
to.
.load_event attribute.
bool 1None
default: None
default: True
respected first.
bool
default: True
component later.
default: None
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
ta b le below .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Guides
JS O N L in e P lo t
^ gradio Status J C
Custom Com ponents G alleryNEW E xp lore
^ gradio =
^ Label LoginButton
LinePlot
gradio.LinePlot(•••)
Loading...
g r a d i o / l i n e p l o t _ c o m p o n e n t b u ilt w ith G ra d io . H o s te d o n HS S p a c e s
Description
Creates a line plot com ponent to display data from a pandas DataFrame (as
output). As this com ponent does not accept user input, it is rarely used as an
input component.
Behavior
As input com ponent: (Rarely used) passes the data displayed in the line plot as
. . . d e f p r e d ic t (
v a l u e : A l t a ir P lo t D a t a | None
d is p la y in th e lin e p lo t. T h e D ataFram e sh o u ld c o n ta in a t le a st tw o c o lu m n s , o n e
axis (c o rre s p o n d in g to y ).
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Initiaíization
Param eter Description
default: None
s t r IN o n e
default: None
s t r |N o n e
Parameter Description
default: None
b o o l 1N o n e coordinate pair.
default: None
s t r 1N o n e
default: None
default: None
default: None
default: None
Parameter Description
x_label_angle The angle for the x axis labels. Positive valúes are
y_label_angle The angle for the y axis labels. Positive valúes are
default: None
s t r |N o n e parameter.
default: None
L ite ra l[(’le ft’, ’r ig h t ’, ’t o p ’, 'none' is passed, this legend is omitted. For other
’b o tto m ', 'to p -le ft, 'to p -rig h t, valid position values see:
default: None
L ite ra l[(’le ft’, 'r ig h t , ’to p , other valid position values see:
'n o n e ')] |N o n e
Parameter Description
default: None
default: None
default: None
s t r 1N o n e
default: None
default: None
b o o l |N o n e
Parameter Description
default: None
c o n t a in e r
bool
default: True
s c a le
int | None
default: None
m in _ w id t h
int
default: 160
.load_event attribute.
bool
default: True
str 1None com ponent in the HTML DOM. Can be used for
list[str] 1str 1None classes of this com ponent in the HTML DOM. Can
component later.
default: False
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
live_dashboard
▲
import math
import pandas as pd I
import gradio as gr
import datetime
import numpy as np
def get_time():
return datetime.datetime.now()
Loading...
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Arguments ta b le b elow .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
L ab e l L o g in B u tto n
^ gradio Status J C
Custom Com ponents G alleryNEW E xp lore
$ gradio
m a k e _ w a v e fo rm Erro r
load
gradio.load(name, •••)
Description
n o t be lo a d e d .
import gradio as gr
demo.launch()
InitiaMzation
Parameter Description
str |None Face Hub models or spaces. Find your token here:
are loading.
^ make_waveform Error
Status
$$ gradio O
Custom Com ponents G alleryNEW E xp lore
^ gradio =
^ LinePlot LogoutButton
LoginButton
gradio.LoginButton(•••)
Loading...
g r a d i o / l o g i n b u t t o n _ c o m p o n e n t b u ilt w ith G ra d io . H o s te d o n HS S p a c e s
Description
Creates a button that redirects the user to Sign with Hugging Face using OAuth.
Behavior
As input com ponent: (Rarely used) the s t r corresponding to the button label
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : s t r | None
d e f p r e d ic t ( " 0 -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Initiaíization
Param eter Description
value
str
Face"
logout_value The text to display when the user is signed in. The
"Logout ()".
every
flo a t |N o n e
default: None
variant
L ite ra l[(’p r im a r y ’, ’s e c o n d a r y ’,
'stop')]
Parameter Description
default: "secondary"
si z e
default: None
icon
s t r |N o n e
default:
" https://huggingface.co/front/a
ssets/huggingface_logo-
noborder.svg"
link
s t r IN o n e
default: None
visible
bool
default: True
interactive
bool
default: True
elem_id
s t r IN o n e
default: None
elem_classes
list[str] Is t r I N o n e
Parameter Description
default: None
render
bool
default: True
scale
in t |N o n e
default: 0
min_width
in t I N o n e
default: None
signed_in_value
str
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Listener Description
(fn, •••)
Event Arguments
Parameter Description
output component.
default: None
default: None
Parameter Description
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
L in e P lo t L o g o u tB u tto n
^ gradio Status J C
Custom Com ponents G alleryNEW E xp lore
^ gradio
^ LoginButton Markdown
LogoutButton
gradio.LogoutButton(•••)
<*>
Loading...
g r a d io / lo g o u t b u t t o n _ c o m p o n e n t b u ilt w ith G ra d io . H o s te d o n HS S p a c e s
Description
Creates a Button to log out a user from a Space using OAuth.
Behavior
As input com ponent: (Rarely used) the s t r corresponding to the button label
d e f p r e d ic t (
)
. . . d e f p r e d ic t (
v a lu e : s t r | None
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
.load_event attribute.
L ite ra l[('p rim a ry ', 'se co n d a ry ', more subdued style, 'stop' for a stop button.
'stop')]
default: "secondary"
default: None
default:
" https://huggmgface.co/front/a
ssets/huggingface_logo-
noborder.svg"
default: "/logout"
bool
default: True
bool
default: True
component later.
respected first.
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Listener Description
(fn, •••)
Event Arguments
Parameter Description
output component.
default: None
default: None
Parameter Description
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
L o g in B u tto n M a rk d o w n
^ gradio Status J C
Custom Com ponents G alleryNEW E x p lo r e
$ gradio
P ro g re ss load
make waveform
gradio.make_waveform(audio, •••)
Description
c o m p o n e n t.
InitiaMzation a¡>
Parameter Description
required
Parameter Description
default: "#f3f4f6"
str |None
default: None
float
default: 0.75
int
default: 50
default: 0.6
default: False
^ Progress load
Status
$ gradio O
Custom Com ponents G alleryNEW E x p lo r e
^ gradio =
^ LogoutButton Model3D
Markdown
gradio.Markdown(•••)
Loading...
Description
Used to render arbitrary Markdown output. Can also render latex enclosed by
dollar signs. As this com ponent does not accept user input, it is rarely used as an
input component.
Behavior
As input com ponent: Passes the s t r of Markdown corresponding to the
displayed value.
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : s t r | None
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
str |C a lla b le |N o n e the function w ill be called whenever the app loads
is assigned to.
.load_event attribute.
Parameter Description
bool |N o n e
default: None
(https://katex.org/docs/autorender.html).
bool
default: True
component later.
vulnerabilities.
default: False
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
blocks_hello b lo c k s _ k in e m a tic s
▲
import gradio as gr
I
def welcome(name):
gr.Markdown(
# Helio World!
.. )
<*>
Loading...
g r a d i o / b l o c k s _ h e l l o b u ilt w ith G r a d io . H o s te d o n BB S p a c e s
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Arguments ta b le b elow .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Guides
Key Features
LogoutButton Model3D ^
^ gradio Status J C
Custom Com ponents G alleryNEW E x p lo r e
^ gradio =
^ Markdown MultimodalTextbox
Model3D
gradio.Model3D(•••)
Loading...
g r a d io / m o d e l3 d _ c o m p o n e n t b u ilt w ith G r a d io . H o s te d o n B S p a c e s
Description &
Creates a com ponent allows users to upload or view 3D Model files (.obj, .glb, .stl,
Behavior
As input com ponent: Passes the uploaded file as a s t r filepath to the function.
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : s t r | None
d e f p r e d ic t ( " 0 -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
Imtiaíization
Param eter Description
default: None w ill be called whenever the app loads to set the
tu p le [flo a t, flo a t, flo a t, flo a t] | floats between 0 and 1 representing RGBA values.
None
default: None
default: (None, None, None) degrees reflecting the angular position along the
camera.
str |None com ponent and is also used as the header if there
to.
bool 1None
default: None
Parameter Description
.load_event attribute.
default: True
respected first.
as an input or output.
bool
Parameter Description
default: True
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Listener Description
Event Arguments
Parameter Description
output component.
s e t[C o m p o n e n t] |N o n e
default: None
default: None
bool completion
default: False
’h id d e n ’)]
default: None put this event on the queue, even if the queue
Parameter Description
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Guides
M a rk d o w n M u ltim o d a lT e x tb o x
^ gradio Status J C
Custom Com ponents G alleryNEW E x p lo r e
$ gradio
Request Flagging ^
mount_gradio_app
Description
import gradio as gr
app = FastAPI()
@app.get("/")
def read_main():
00/gradio.
InitiaMzation
Parameter Description
fastapi.FastAPI
required
gradio.Blocks app.
required
str mounted.
required
list[tuple[str, str]] | None gradio app. Can also provide function that takes
login.
Parameter Description
default: None
default: None authorized to access the gradio app (they w ill see a
"https://example.com/myapp", the r o o t_ p a th
by Gradio by default.
app.
limit is set.
^ Request Flagging ^
Status
$$ gradio X o
Custom Com ponents G alleryNEW E x p lo r e
^ gradio
^ Model3D Number
MultimodalTextbox
gradio.MultimodalTextbox(•••)
Loading...
Description &
Creates a textarea for users to enter string input or display string output and also
Behavior
As input com ponent: Passes text value and list of file(s) as a d ic t into the
function.
d e f p r e d ic t (
)
. . . d e f p r e d ic t (
v a l u e : M u ltim o d a lV a lu e | None
As output com ponent: Exp ects a d i c t w ith "text" and "files", b oth o p tio n a l. The
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
dict[str, str | list] | Callable | None dictionary of the form " t e x t " : "sa m p le
files to be uploaded.
in t textarea.
default: 1
in t textarea.
default: 20
str |N o n e
default: None
to.
s t r |N o n e
default: None
.load_event attribute.
Parameter Description
bool |N o n e
default: None
default: True
respected first.
bool
default: True
Parameter Description
str |None com ponent in the HTML DOM. Can be used for
default: True user scrolls up. If False, w ill not scroll to the
list[str] 1str 1None classes of this com ponent in the HTML DOM. Can
t e x t _ a lig n How to align the text in the textbox, can be: "left",
be changed if t y p e is "text".
default: False
Parameter Description
the right.
str |L ite ra l[F a ls e ] |N o n e w ill use that string as the subm it button text. Only
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
▲
import gradio as gr
import os
import time
# Chatbot demo with multimodal input (text, markdown, LaTeX, code blocks, i
I
mage, audio, & video). Plus shows support for streaming text.
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Listener Description
Event Arguments
Parameter Description
output component.
default: None
None
default: None
bool completion
default: False
’h id d e n ’)]
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
Parameter Description
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
^ Model3D Number
^ gradio Status J C
Custom Com ponents G alleryNEW E xp lore
$ gradio
^ Themes
NO RELOAD
if gr.NO_RELOAD:
Description &
Any code in a 'if gr.NO_RELOAD' code-block will not be re-evaluated when the
source file is reloaded. This is helpful for importing modules that do not like to be
reloaded (tiktoken, numpy) as well as database connections and long running set
up code.
Exampíe Usage
import gradio as gr
if gr.NO_RELOAD:
sentiment-latest")
gr.Interface.from_pipeline(pipe).launch()
th e m e s
Status
$ gradio o
Custom Com ponents G alleryNEW E xp lore
$ gradio
^ MultimodalTextbox ParamViewer
Number
gradio.Number(•••)
<*>
Loading...
Description
Creates a numeric field for user to enter numbers as input or display numeric
output.
Behavior
d e p e n d in g on p r e c i s i ó n .
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : f lo a t | in t | None
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
flo a t |C a lla b le |N o n e whenever the app loads to set the initial value of
str |None com ponent and is also used as the header if there
to.
str 1None
default: None
.load_event attribute.
bool 1None
default: None
default: True
respected first.
output.
bool
default: True
component later.
Parameter Description
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
tax_calculator b lo c k s _ s im p le _ s q u a re s
▲
import gradio as gr
tax_brackets = [(10, 0), (25, 8), (60, 12), (120, 20), (250, 30)]
total_deductible = sum(assets["Cost"])
i
taxable_income = income - total_deductible
total_tax = 0
Loading...
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Arguments ta b le b elow .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’h id d e n ’)]
default: "fu ll
Parameter Description
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
M u ltim o d a lT e x tb o x P a ra m V ie w e r
Status
$ gradio O
Custom Com ponents G alleryNEW E xp lore
$ gradio
Number Plot ^
ParamViewer
gradio.ParamViewer(•••)
Loading...
Description
c o m p o n e n ts in th e C u sto m C o m p o n e n t G a lle ry
(h ttp s ://w w w .g ra d io .a p p /c u s to m -c o m p o n e n ts /g a lle ry ).
Behavior
"type", "d e sc rip tio n ", an d (o p tio n a lly ) "d e fa u lt" fo r each p aram eter.
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a l u e : d i c t [ s t r , P a ra m e te r]
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e d e f p r e d ic t ( ^ " ) -> d i c t [ s t r , P a ra m e te r]
re t u r n v a lu e
InitiaMzation
Parameter Description
default: None
default: "python"
Shortcuts
Interface String
Class Initialization
Shortcut
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
Parameter Description
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
default: None
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Num ber P lo t
Status
$ gradio O
Custom Com ponents G alleryNEW Exp lore
$ gradio
New to Gradio? Start here: Getting Started See the Release History
^ ParamViewer Radio
Plot
gradio.Plot(•••)
12 Plot
g r a d i o / p l o t _ c o m p o n e n t b u ilt w i t h G r a d i o . H o s te d on Spaces
Description <sP
altair, or bokeh plots are supported). As this component does not accept user
Behavior
As input com ponent: (Rarely used) passes the data displayed in the plot as an
PlotData dataclass, which includes the plot information as a JSON string, as well
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a l u e : P lo tD a ta | None
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
the component.
str |None com ponent and is also used as the header if there
to.
.load_event attribute.
bool 1None
default: None
default: True
respected first.
bool
default: True
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
blocks_kinem atics s to c k _ fo re c a st
▲
import pandas as pd
import numpy as np
import gradio as gr
I
def plot(v, a):
g = 9.81
Loading...
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
ta b le below .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’h id d e n ’)]
default: "fu ll
Parameter Description
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
Guides
^ ParamViewer Radio
Status
$ gradio X o
Custom Com ponents G alleryNEW E xp lore
$ gradio
E xa m p le s m a k e _ w a v e fo rm
Progress
gradio.Progress(•••)
Description
import gradio as gr
import time
for i in progress.tqdm(range(100)):
time.sleep(0.1)
return x
InitiaMzation
Parameter Description
Methods
cali
gradio.Progress.__call__(progress, •••)
Description
Parameter Description
s t r 1N o n e
default: None
in t 1N o n e
default: None
str
default: "steps"
tqdm
gradio.Progress.tqdm(iterableJ •••)
Descri ption
Agruments
Parameter Description
Ite ra b le |N o n e
required
s t r 1N o n e
default: None
in t 1N o n e
default: None
str
default: "steps"
E xa m p le s m a k e _ w a v e fo rm
Status
$ gradio O
Custom Com ponents G alleryNEW E xp lore
$ gradio
P lo t S c a tte rP lo t
Radio
gradio.Radio(•••)
Loading...
Description
se le cte d .
Behavior
in t | f l o a t , o r its in d e x as an i n t in to th e fu n c tio n , d e p e n d in g on t y p e .
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : s t r | in t | flo a t | None
o f th e ra d io b u tto n to be se le cte d
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
list[str |in t |flo a t |tuple[str, s t r | option can also be a tupie of the form (name,
default: None be called whenever the app loads to set the initial
to.
s t r |N o n e
default: None
.load_event attribute.
bool |N o n e
default: None
default: True
respected first.
bool
default: True
Parameter Description
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
sentence_builder b lo c k s_ e s sa y
I
import gradio as gr
to the {place} where they {" and ".join(activity_list)} until the {"mornin
Loading...
Event Listeners
Description
E ven t lis te n e rs a llo w y o u to c a p tu re an d re sp o n d to u ser in te ra c tio n s w ith
ta b le below .
Listener Description
Event Arguments
Parameter Description
output component.
default: None
Parameter Description
default: None
bool completion
default: False
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Plot ScatterPlot
Status
$ gradio O
Custom Com ponents G alleryNEW E xp lore
$ gradio
Info m o u n t_ g ra d io _ a p p
Request
gradio.Request(•••)
Description
A ttrib u te s o f th is c la s s in clu d e : h e a d e r , c l i e n t , q u e ry _ p a ra m s, s e s s io n _ h a s ,
import gradio as gr
if request:
return text
InitiaMzation
Parameter Description
request A fastapi.Request
fa s t a p i.R e q u e s t |N o n e
default: None
s t r IN o n e enabled)
default: None
default: None
Demos
request_ip_headers
import gradio as gr
host = request.client.host
user_agent = request.headers["user-agent"]
return {
"ip": host,
"user_agent": user_agent,
"headers": headers,
Loading...
Info m o u n t_ g ra d io _ a p p
Status
O
Custom Com ponents G a lle ry NEW Explore
gradio =
New to Gradio? Start here: G etting Started See the Release History
^ B lo c k s C o lu m n
Row
with gradio.Row():
Description
R o w is a la y o u t e le m e n t w ith in B lo c k s th a t re n d e rs a ll c h ild re n h o riz o n ta lly .
Exampíe Usage
with gr.Row():
g r .Image("lion.jpg", scale=2)
g r .Image("tiger.jpg", scale=1)
demo.launch()
Initiaíization
Param eter D escription
bool
Param eter D escription
default: True
str | None com ponent in the HTML DOM. Can be used for
list[str] 1str 1None assigned as the class of this com ponent in the
default: None HTML DOM. Can be used for targeting CSS styles.
bool height
default: True
Guides
Controlling Layout
^ B lo c k s C o lu m n
0 gradio Status X O
Custom Com ponents G alleryNEW E xp lore
$ gradio
^ Radio Simplelmage
ScatterPlot
gradio.ScatterPlot(•••)
Description &
Behavior
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a l u e : A l t a ir P lo t D a t a | None
d is p la y in th e s c a tte r p lo t. T h e D ataFram e sh o u ld c o n ta in a t le a st tw o co lu m n s ,
th e y-axis (c o rre s p o n d in g to y ).
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
default: None the function will be called whenever the app loads
s t r 1N o n e
default: None
s t r 1N o n e
default: None
s t r 1N o n e
default: None
Parameter Description
default: None
default: None
default: None
default: None
default: None
default: None
Parameter Description
L ite ra l[(’le ft, 'right', ’t o p ’, 'none' is passed, this legend is omitted. For other
’b o tto m ', ’to p -le ft, 't o p - r ig h t , valid position values see:
default: None
L ite ra l[(1 e ft, 'rig h t, 'to p , 'none' is passed, this legend is omitted. For other
'b o tt o m , ’to p -le ft, 'to p -rig h t, valid position values see:
default: None
L ite ra l[(’le ft, 'r ig h t , ’to p , 'none' is passed, this legend is omitted. For other
'b o tt o m , ’to p -le ft, 'to p -rig h t, valid position values see:
default: None
default: None
default: None
s t r 1N o n e
default: None
default: None
.load_event attribute.
b o o l 1N o n e
default: None
c o n t a in e r
Parameter Description
bool
default: True
scale
in t |N o n e
default: None
min_width
in t
default: 160
bool
default: True
component later.
default: False
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
Each event listener takes the s a m e parameters, which are listed in the
Listener Description
output component.
default: None
default: None
bool completion
default: False
’hidden’)]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
Parameter Description
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Radio Simplelmage
Status
^ gradio o
Custom Com ponents G alleryNEW E xp lore
$ gradio
Video EventData
set_static_paths
gradio.set_static_paths(paths, •••)
Description
Static files are not m o v e d to the gradio cache and are served directly from the file
system. This function is useful w h e n you w a n t to serve files that you k n o w will
not be modified during the lifetime of the gradio a p p (like files used in
gr.Examples). By setting static paths, your a p p will launch faster and it will
c o n s u m e less disk space. Calling this function will set the static paths for all
or the session ends. To clear out the static paths, call this function with an e m p t y
list.
gr.set_static_paths(paths= ["test/test_files/"])
# will not be copied to the gradio cache and will be served directly.
demo = gr.Interface(
lambda s : s .rotate(45),
gr.Image(value="test/test_files/cheetah1.jpg", type="pil"),
gr.Image(),
examples= ["test/test_files/bus.png"],
demo.launch()
Imtiaíization
Parameter Description
Video EventData
Status
$ gradio O
Custom Com ponents G alleryNEW E xp lore
$ gradio
ScatterPlot Slider
Simplelmage
gradio.SimpleImage(•••)
Loading...
Description
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : s t r | None
to th e im age.
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
to.
b o o l IN o n e
default: None
bool
default: True
default: True
respected first.
bool
default: True
component later.
Shortcuts
Interface String
Class Initialization
Shortcut
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
Each event listener takes the s a m e parameters, which are listed in the
Listener Description
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’h id d e n ’)]
default: None put this event on the queue, even if the queue
component.
Parameter Description
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
ScatterPlot Slider
Status
^ gradio o
Custom Components GalleryNEW Explore
$ gradio
New to Gradio? Start here: Getting Started See the Release History
^ S im p le lm a g e State
Slider
gradio.Slider(•••)
Loading...
Description ¿P
Behavior
As input component: Passes slid e r value as a f l o a t into the function.
def p r e d ic t (
. . . d ef p r e d ic t (
v a lu e : f l o a t
As output component: Expects an i n t o r f l o a t returned from fu n ction and sets s lid e r value to
def p r e d ic t ( ---) -> pd. DataFrame | S t y le r | np. ndarray | p l . DataFrame | l i s t | lis t[lis t] | d ic t | str | None
re tu rn va lu e
Initialization
Parameter Description
float
default: 0
float
default: 100
float | Callable | None the app loads to set the initial value of the component.
Parameter Description
float | None
default: None
label The label for this component. Appears above the component
str 1None and is also used as the header if there are a table of examples
assigned to.
str 1None
default: None
float 1None seconds while the client connection is open. Has no effect
default: None otherwise. The event can be accessed (e.g. to cancel it) via
bool 1None
default: None
default: True
int 1None if Components A and B are in a Row, and A has scale=2, and B
min_width mínimum pixel width, will wrap if not sufficient screen space
bool
default: True
str I None in the HTML DOM. Can be used for targeting CSS styles.
default: None
list[str] Istr I None this component in the HTML DOM. Can be used for targeting
randomize If True, the value of the slider when the app loads is taken
Demos
import gradio as gr
return f.. The {quantity} {animal}s from {" and ".join(countries)} went to the {place}
where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}..
demo = gr.Interface(
sentence_builder,
Loading...
Description
Event listeners a llo w you to cap ture and respond to user in te ra ctio n s w ith the UI
co m p o n e n ts you 've defin ed in a G radio B locks app. W hen a user interacts w ith an
elem ent, such as ch ang ing a slid e r value o r u p lo a d in g an im age, a fu n ction is called.
Listener Description
•)
because of user input (e.g. a user types in a textbox) OR
because of a function update (e.g. an image receives a
value from the output of an event trigger). See . in p u t ( )
for a listener that is only triggered by user input.
gradio.Slider.input(fn, ■■■) This listener is triggered when the user changes the value
of the Slider.
Event Arguments
Parameter Description
default: None
api_name defines how the endpoint appears in the API docs. Can
str | None | Literal[False] be a string, None, or False. If set to a string, the endpoint
default: None will be exposed in the API docs with the given name. If
event.
default: False
default: "full"
queue If True, will place the request on the queue, if the queue
bo° | None has been enabled. If False, will not put this event on the
default: None queue, even if the queue has been enabled. If None, will
default: True
that have not yet run (or generators that are iterating)
ev ery Run this event 'every' number of seconds while the client
float 1None connection is open. Interpreted in seconds.
default: None
Parameter Description
components.
concurrency_limit If set, this is the maximum number of this event that can
int 1None | Literal['default'] be running simultaneously. Can be set to None to mean
default: "default" no concurrency_limit (any number of this event can be
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
show_api whether to show this event in the "view API" page of the
bool Gradio app, or in the ".view_api()" method of the Gradio
default: True clients. Unlike setting api_name to False, setting
set to False.
Guides
^ S im p le lm a g e State
Status
$ gradio O
Custom Com ponents G alleryNEW E xp lore
$ gradio
^ Slider Textbox
State
gradio.State(•••)
Description
Behavior
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a l u e : Any
)
deepcopied.
d e f p r e d ic t ( " 0 -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
value the initial value (of arbitrary type) of the state. The
default: True
sessions.
^ S lid e r T extbox
Status
$ gradio X o
Custom Com ponents G allery NEW Explore
0 , gradio
New to Gradio? Start here: G etting Started See the Release History
C o lu m n G ro u p
Tab
with gradio.Tab():
Description
Tab (or its a lia s T abItem ) is a la y o u t e le m e n t. C o m p o n e n ts d e fin e d w ith in th e Tab
w ill be v is ib le w h e n th is ta b is s e le c te d tab .
Exampíe Usage
with gr.Tab("Lion"):
gr.Image("lion.jpg")
gr.Button("New Lion")
with gr.Tab("Tiger"):
gr.Image("tiger.jpg")
gr.Button("New Tiger")
Initiaíization
Param eter D escription
str | None
default: None
Param eter D escription
bool
default: True
bool
default: True
int |str | None wish to control the selected tab from a predict
styles.
list[str] 1str 1None assigned as the class of this com ponent in the
default: None HTML DOM. Can be used for targeting CSS styles.
Methods
select
gradio.Tab.select(•••)
Description
E v e n t lis te n e r fo r w h e n th e u se r s e le c ts o r d e s e le c ts th e Tab. U se s e v e n t
h o w to use th is e v e n t d ata
Agruments
Param eter D escription
output component.
default: None
default: None
Param eter D escription
default: False
'hidden')]
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Guides
Controlling Layout
^ C o lu m n G ro u p
^ gradio Status O
Custom Com ponents G a lle ry NEW Explore
gradio =
New to Gradio? Start here: G etting Started See the Release History
^ C h a tIn te rfa c e B lo c k s
TabbedInterface
gradio.TabbedInterface(interface_list, •••)
Description
A T a b b e d In te rfa c e is cre a te d b y p ro v id in g a lis t o f In terface s o r B lo c k s , each o f
Initialization
Param eter D escription
list[Interface] tabs.
required
default: None
default: None
Param eter D escription
Theme |str | None a string, w ill look for a built-in theme with that
Default theme.
default: None
Demos
tabbed_interface_lite
import gradio as gr
d"])
if __name__ == "__main
demo.launch()
Loading...
C h a tIn te rfa ce B lo c k s
$ gradio
State UploadButton
Textbox
gradio.Textbox(•••)
Loading...
Description &
Creates a textarea for user to enter string input or display string output.
Behavior
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : s t r | None
v a lu e to it.
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
int textarea.
default: 1
int textarea.
default: 20
str |None
default: None
str |None com ponent and is also used as the header if there
to.
str 1None
default: None
.load_event attribute.
Parameter Description
default: None
default: True
respected first.
bool
default: True
Parameter Description
default: True user scrolls up. IfFalse, will not scroll to the
component later.
'em a il')]
default: "text"
L ite ra l[('le ft, 'righ t')] |N o n e "right", or None (default). If None, the alignment is
default: None
Parameter Description
be changed if t y p e is "text".
the right.
default: False
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
import gradio as gr
def greet(name):
demo.launch()
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
event listener takes the s a m e parameters, which are listed in the Event
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’h id d e n ’)]
default: "fu ll
Parameter Description
bool | None the queue has been enabled. If False, w ill not
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Guides
State UploadButton
Status
$ gradio xO
Custom Com ponents G alleryNEW E xp lore
0 gradio
New to Gradio? Start here: Getting Started See the Release History
^ F la g g in g NO RELO AD ^
Themes
Description
Base
gradio.Base(•••)
InitiaMzation
Parameter Description
gradio.themes.utils.Color object.
gradio.themes.utils.Color object.
gradio.themes.utils.Color object.
object.
object.
object.
Parameter Description
font The primary font to use for the theme. Pass a string
(<gradio.themes.utils.fonts.Goo fallbacks.
serif')
(<gradio.themes.utils.fonts.Goo fallbacks.
'ui-monospace', 'Consolas',
'm onospace')
Methods
Methods
push_to_hub
gradio.Base.push_to_hub(repo_name, •••)
Description
account. <br>
Agruments
Parameter Description
required
h/_token is used.
s t r 1N o n e
default: None
Parameter Description
str |N o n e repo_name
default: None
s t r 1N o n e
default: None
prívate
bool
default: False
from hub
gradio.Base.from_hub(repo_name, •••)
Description
Agruments
Parameter Description
default: None
load
gradio.Base.load(path, •••)
Description
Agruments
Parameter Description
str
r e q u ir e d
dump
gradio.Base.dumpfilename, •••)
Description
Agruments
Parameter Description
str
r e q u ir e d
from dict
gradio.Base.from_dict(theme, •••)
Description
Create a t h e m e instance from a dictionary representation. <br>
Agruments
r e q u ir e d
to dict
gradio.Base.to_dict(•••)
Description
Flagging N O RELOAD ^
Status
$ gradio X o
Custom Com ponents G alleryNEW E xp lore
$ gradio
^ Textbox Video
UploadButton
gradio.UploadButton(•••)
Loading...
Description &
Used to create an upload button, w h e n clicked allows a user to upload files that
satisfy the specified file type or generic files (if file_type not set).
Behavior
o f b y te s o b je cts, d e p e n d in g on ty p e an d f i l e _ c o u n t .
d e f p r e d ic t (
. . . d e f p r e d ic t (
file p a th s /U R L s.
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
str File".
s t r |list[str] |C a lla b le |N o n e
default: None
.load_event attribute.
'stop')]
default: "secondary"
bool
default: True
default: None
default: None
respected first.
bool state.
default: True
component later.
L ite ra l[('fíle p a th ', ’b ytes')] returns a temporary file object with the same base
bytes object.
Parameter Description
uploaded.
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
upload_and_download upload_button
import gradio as gr
def upload_file(filepath):
name = Path(filepath).name
def download_file():
e)]
<6
Loading...
Event Listeners
Description
Event listeners allow you to capture and respond to user interactions with
Each event listener takes the s a m e parameters, which are listed in the
Event Arguments
Parameter Description
output component.
default: None
default: None
bool completion
default: False
’h id d e n ’)]
default: None put this event on the queue, even if the queue
component.
Parameter Description
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
Textbox Video
Status
^ gradio o
Custom Com ponents G alleryNEW E xp lore
$ gradio
UploadButton load
Video
gradio.Video(•••)
Loading...
Description &
input) or display videos (as an output). For the video to be playable in the
combinations are . m p 4 with h264 codec, .ogg with theora codec, and . w e b m with
vp 9 co d e c. If th e c o m p o n e n t d e te cts th a t th e o u tp u t v id e o w o u ld n o t be p la y a b le
in th e b ro w s e r it w ill a tte m p t to c o n v e rt it to a p la y a b le m p 4 v id e o . If th e
Behavior
d e f p r e d ic t (
. . . d e f p r e d ic t (
v a lu e : s t r | None
d is p la y e d , o r a T u p le [ s t r | p a t h l ib . P a t h , s tr | p a t h lib . P a t h | None]
d e f p r e d ic t ( ^ " ) -> pd. DataFrame | S t y le r | np. n d a rra y | p l . DataFrame | lis t | lis t [lis t ] |
d ic t | s tr | None
re t u r n v a lu e
InitiaMzation
Parameter Description
list[L ite ra l[(’u p lo a d ’, ’w e b c a m ’)]] creates a box where user can drop an video file,
to.
.load_event attribute.
bool 1None
default: None
default: True
respected first.
Parameter Description
bool
default: True
component later.
bool
default: True
uploaded videos.
Parameter Description
default: False will not autoplay video files ifthe user has not
input components.
Shortcuts
Interface String
Class Initialization
Shortcut
Demos
video_identity_2
import gradio as gr
def video_identity(video) :
return video
demo = gr.Interface(video_identity,
gr.Video(),
"playable_video",
Loading...
Description
Event listeners allow you to capture and respond to user interactions with
listener takes the s a m e parameters, which are listed in the Event Arguments
table below.
Listener Description
Event Arguments
Parameter Description
output component.
default: None
Parameter Description
default: None
bool completion
default: False
default: None put this event on the queue, even if the queue
component.
default: 4 batch=True)
allowed to finish.
event is complete.
d e f a u lt _ c o n c u r r e n c y _ lim it parameter in
UploadButton load
Status
$ gradio O
Custom Com ponents G alleryNEW E xp lore
$ gradio
E rro r Info
Warning
gradio.Warning(•••)
Description
m u st be e n a b le d fo r th is b e h a v io r; o th e rw is e , th e w a rn in g w ill be p rin te d to th e
import gradio as gr
def hello_world():
md = gr.Markdown()
demo.queue().launch()
InitiaMzation
str
Demos
blocks_chained_events
▲
import gradio as gr
import time
I
def failure():
def exception():
def success():
Loading...
Error Info
Status
^ gradio o