Creating an Interface
gradio.Interface(self, fn, inputs, outputs, verbose=False, examples=None, examples_per_page=10, live=False, layout="horizontal", capture_session=False, interpretation=None, title=None, description=None, article=None, thumbnail=None, css=None, server_port=7860, server_name="127.0.0.1", allow_screenshot=True, allow_flagging=True, flagging_options=None, show_tips=True, flagging_dir="flagged")
Interfaces are created with Gradio using the `gradio.Interface()` function.
Parameters
- fn (Callable) - the function to wrap an interface around.
- inputs (Union[str, List[Union[str, InputComponent]]]) - a single Gradio input component, or list of Gradio input components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. The number of input components should match the number of parameters in fn.
- outputs (Union[str, List[Union[str, OutputComponent]]]) - a single Gradio output component, or list of Gradio output components. Components can either be passed as instantiated objects, or referred to by their string shortcuts. The number of output components should match the number of values returned by fn.
- verbose (bool) - whether to print detailed information during launch.
- examples (List[List[Any]]) - sample inputs for the function; if provided, appears below the UI components and can be used to populate the interface. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component.
- examples_per_page (int) - If examples are provided, how many to display per page.
- live (bool) - whether the interface should automatically reload on change.
- layout (str) - Layout of input and output panels. "horizontal" arranges them as two columns of equal height, "unaligned" arranges them as two columns of unequal height, and "vertical" arranges them vertically.
- capture_session (bool) - if True, captures the default graph and session (needed for Tensorflow 1.x)
- interpretation (Union[Callable, str]) - function that provides interpretation explaining prediction output. Pass "default" to use built-in interpreter.
- title (str) - a title for the interface; if provided, appears above the input and output components.
- description (str) - a description for the interface; if provided, appears above the input and output components.
- article (str) - an expanded article explaining the interface; if provided, appears below the input and output components. Accepts Markdown and HTML content.
- thumbnail (str) - path to image or src to use as display picture for models listed in gradio.app/hub
- css (str) - custom css or path to custom css file to use with interface.
- server_port (int) - will start gradio app on this port (if available)
- server_name (str) - to make app accessible on local network set to "0.0.0.0".
- allow_screenshot (bool) - if False, users will not see a button to take a screenshot of the interface.
- allow_flagging (bool) - if False, users will not see a button to flag an input and output.
- flagging_options (List[str]) - if not None, provides options a user must select when flagging.
- flagging_dir (str) - what to name the dir where flagged data is stored.
- show_tips (bool) - if True, will occasionally show tips about new Gradio features
gradio.Interface.launch(self, inline=None, inbrowser=None, share=False, debug=False, auth=None)
Generates the UI for the interface.
Parameters
- inline (bool) - whether to display in the interface inline on python notebooks.
- inbrowser (bool) - whether to automatically launch the interface in a new tab on the default browser.
- share (bool) - whether to create a publicly shareable link from your computer for the interface.
- debug (bool) - if True, and the interface was launched from Google Colab, prints the errors in the cell output.
- auth (Tuple[str, str]) - If provided, username and password required to access interface.
Input Components
gradio.inputs.Textbox(self, lines=1, placeholder=None, default=None, numeric=False, type="str", label=None)
Component creates a textbox for user to enter input. Provides a string as an argument to the wrapped function.
Input type: str
Parameters
- lines (int) - number of line rows to provide in textarea.
- placeholder (str) - placeholder hint to provide behind textarea.
- default (str) - default text to provide in textarea.
- numeric (bool) - DEPRECATED. Whether the input should be parsed as a number instead of a string.
- type (str) - DEPRECATED. Type of value to be returned by component. "str" returns a string, "number" returns a float value. Use Number component in place of number type.
- label (str) - component name in interface.
String Shortcuts
- "text" - Uses defaults implementation.
- "textbox" -
Sets
lines=7
gradio.inputs.Textbox.interpret(self, separator=" ", replacement=None)
- separator (str) - Separator to use to split input into tokens.
- replacement (str) - In the "leave one out" step, the text that the token should be replaced with.
- (List[Tuple[str, float]]) - Each tuple set represents a set of characters and their corresponding interpretation score.
Demos
gradio.inputs.Number(self, default=None, label=None)
Component creates a field for user to enter numeric input. Provides a nuber as an argument to the wrapped function.
Input type: float
Parameters
- default (float) - default value.
- label (str) - component name in interface.
String Shortcuts
- "number" - Uses defaults implementation.
gradio.inputs.Number.interpret(self, steps=3, delta=1, delta_type="percent")
- steps (int) - Number of nearby values to measure in each direction (above and below the input number).
- delta (float) - Size of step in each direction between nearby values.
- delta_type (str) - "percent" if delta step between nearby values should be a calculated as a percent, or "absolute" if delta should be a constant step change.
- (List[Tuple[float, float]]) - Each tuple set represents a numeric value near the input and its corresponding interpretation score.
Demos


gradio.inputs.Slider(self, minimum=0, maximum=100, step=None, default=None, label=None)
Component creates a slider that ranges from `minimum` to `maximum`. Provides a number as an argument to the wrapped function.
Input type: float
Parameters
- minimum (float) - minimum value for slider.
- maximum (float) - maximum value for slider.
- step (float) - increment between slider values.
- default (float) - default value.
- label (str) - component name in interface.
String Shortcuts
- "slider" - Uses defaults implementation.
gradio.inputs.Slider.interpret(self, steps=8)
- steps (int) - Number of neighboring values to measure between the minimum and maximum values of the slider range.
- (List[float]) - Each value represents the score corresponding to an evenly spaced range of inputs between the minimum and maximum slider values.
Demos




gradio.inputs.Checkbox(self, label=None)
Component creates a checkbox that can be set to `True` or `False`. Provides a boolean as an argument to the wrapped function.
Input type: bool
Parameters
- label (str) - component name in interface.
String Shortcuts
- "checkbox" - Uses defaults implementation.
gradio.inputs.Checkbox.interpret(self)
- (Tuple[float, float]) - The first value represents the interpretation score if the input is False, and the second if the input is True.
Demos
gradio.inputs.CheckboxGroup(self, choices, type="value", label=None)
Component creates a set of checkboxes of which a subset can be selected. Provides a list of strings representing the selected choices as an argument to the wrapped function.
Input type: Union[List[str], List[int]]
Parameters
- choices (List[str]) - list of options to select from.
- type (str) - Type of value to be returned by component. "value" returns the list of strings of the choices selected, "index" returns the list of indicies of the choices selected.
- label (str) - component name in interface.
gradio.inputs.CheckboxGroup.interpret(self)
- (List[Tuple[float, float]]) - For each tuple in the list, the first value represents the interpretation score if the input is False, and the second if the input is True.
Demos
gradio.inputs.Radio(self, choices, type="value", label=None)
Component creates a set of radio buttons of which only one can be selected. Provides string representing selected choice as an argument to the wrapped function.
Input type: Union[str, int]
Parameters
- choices (List[str]) - list of options to select from.
- type (str) - Type of value to be returned by component. "value" returns the string of the choice selected, "index" returns the index of the choice selected.
- label (str) - component name in interface.
gradio.inputs.Radio.interpret(self)
- (List[float]) - Each value represents the interpretation score corresponding to each choice.
Demos




gradio.inputs.Dropdown(self, choices, type="value", label=None)
Component creates a dropdown of which only one can be selected. Provides string representing selected choice as an argument to the wrapped function.
Input type: Union[str, int]
Parameters
- choices (List[str]) - list of options to select from.
- type (str) - Type of value to be returned by component. "value" returns the string of the choice selected, "index" returns the index of the choice selected.
- label (str) - component name in interface.
gradio.inputs.Dropdown.interpret(self)
- (List[float]) - Each value represents the interpretation score corresponding to each choice.
Demos





gradio.inputs.Image(self, shape=None, image_mode="RGB", invert_colors=False, source="upload", tool="editor", type="numpy", label=None)
Component creates an image upload box with editing capabilities.
Input type: Union[numpy.array, PIL.Image, file-object]
Parameters
- shape (Tuple[int, int]) - (width, height) shape to crop and resize image to; if None, matches input image size.
- image_mode (str) - "RGB" if color, or "L" if black and white.
- invert_colors (bool) - whether to invert the image as a preprocessing step.
- source (str) - Source of image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "canvas" defaults to a white image that can be edited and drawn upon with tools.
- tool (str) - Tools used for editing. "editor" allows a full screen editor, "select" provides a cropping and zoom tool.
- type (str) - Type of value to be returned by component. "numpy" returns a numpy array with shape (width, height, 3) and values from 0 to 255, "pil" returns a PIL image object, "file" returns a temporary file object whose path can be retrieved by file_obj.name.
- label (str) - component name in interface.
String Shortcuts
- "image" - Uses defaults implementation.
- "webcam" -
Sets
source=webcam
- "sketchpad" -
Sets
image_mode=L, source=canvas, shape=(28, 28), invert_colors=True
gradio.inputs.Image.interpret(self, segments=16)
- segments (int) - Number of interpretation segments to split image into.
- (List[List[float]]) - A 2D array representing the interpretation score of each pixel of the image.
Demos
gradio.inputs.Video(self, type="avi", label=None)
Component creates a video file upload that is converted to a file path.
Input type: filepath
Parameters
- type (str) - Type of video format to be returned by component, such as 'avi' or 'mp4'. If set to None, video will keep uploaded format.
- label (str) - component name in interface.
String Shortcuts
- "video" - Uses defaults implementation.
Demos
gradio.inputs.Audio(self, source="upload", type="numpy", label=None)
Component accepts audio input files.
Input type: Union[Tuple[int, numpy.array], file-object, numpy.array]
Parameters
- source (str) - Source of audio. "upload" creates a box where user can drop an audio file, "microphone" creates a microphone input.
- type (str) - Type of value to be returned by component. "numpy" returns a 2-set tuple with an integer sample_rate and the data numpy.array of shape (samples, 2), "file" returns a temporary file object whose path can be retrieved by file_obj.name, "mfcc" returns the mfcc coefficients of the input audio.
- label (str) - component name in interface.
String Shortcuts
- "audio" - Uses defaults implementation.
- "microphone" -
Sets
source=microphone
gradio.inputs.Audio.interpret(self, segments=8)
- segments (int) - Number of interpretation segments to split audio into.
- (List[float]) - Each value represents the interpretation score corresponding to an evenly spaced subsection of audio.
Demos
gradio.inputs.File(self, type="file", label=None)
Component accepts generic file uploads.
Input type: Union[file-object, bytes]
Parameters
- type (str) - Type of value to be returned by component. "file" returns a temporary file object whose path can be retrieved by file_obj.name, "binary" returns an bytes object.
- label (str) - component name in interface.
String Shortcuts
- "file" - Uses defaults implementation.
Demos


gradio.inputs.Dataframe(self, headers=None, row_count=3, col_count=3, datatype="str", type="pandas", label=None)
Component accepts 2D input through a spreadsheet interface.
Input type: Union[pandas.DataFrame, numpy.array, List[Union[str, float]], List[List[Union[str, float]]]]
Parameters
- headers (List[str]) - Header names to dataframe.
- row_count (int) - Limit number of rows for input.
- col_count (int) - Limit number of columns for input. If equal to 1, return data will be one-dimensional. Ignored if `headers` is provided.
- datatype (Union[str, List[str]]) - Datatype of values in sheet. Can be provided per column as a list of strings, or for the entire sheet as a single string. Valid datatypes are "str", "number", "bool", and "date".
- type (str) - Type of value to be returned by component. "pandas" for pandas dataframe, "numpy" for numpy array, or "array" for a Python array.
- label (str) - component name in interface.
String Shortcuts
- "dataframe" -
Sets
type=pandas
- "numpy" -
Sets
type=numpy
- "matrix" -
Sets
type=array
- "list" -
Sets
type=array, col_count=1
gradio.inputs.Dataframe.interpret(self)
- (List[List[float]]) - A 2D array where each value corrseponds to the interpretation score of each cell.
Demos
Output Components
gradio.outputs.Textbox(self, type="auto", label=None)
Component creates a textbox to render output text or number.
Output type: Union[str, float, int]
Parameters
- type (str) - Type of value to be passed to component. "str" expects a string, "number" expects a float value, "auto" detects return type.
- label (str) - component name in interface.
String Shortcuts
- "text" -
Sets
type=str
- "textbox" -
Sets
type=str
- "number" -
Sets
type=number
Demos


gradio.outputs.Label(self, num_top_classes=None, type="auto", label=None)
Component outputs a classification label, along with confidence scores of top categories if provided. Confidence scores are represented as a dictionary mapping labels to scores between 0 and 1.
Output type: Union[Dict[str, float], str, int, float]
Parameters
- num_top_classes (int) - number of most confident classes to show.
- type (str) - Type of value to be passed to component. "value" expects a single out label, "confidences" expects a dictionary mapping labels to confidence scores, "auto" detects return type.
- label (str) - component name in interface.
String Shortcuts
- "label" - Uses defaults implementation.
Demos




gradio.outputs.Image(self, type="auto", labeled_segments=False, plot=False, label=None)
Component displays an output image.
Output type: Union[numpy.array, PIL.Image, str, matplotlib.pyplot, Tuple[Union[numpy.array, PIL.Image, str], List[Tuple[str, float, float, float, float]]]]
Parameters
- type (str) - Type of value to be passed to component. "numpy" expects a numpy array with shape (width, height, 3), "pil" expects a PIL image object, "file" expects a file path to the saved image, "plot" expects a matplotlib.pyplot object, "auto" detects return type.
- labeled_segments (bool) - If True, expects a two-element tuple to be returned. The first element of the tuple is the image of format specified by type. The second element is a list of tuples, where each tuple represents a labeled segment within the image. The first element of the tuple is the string label of the segment, followed by 4 floats that represent the left-x, top-y, right-x, and bottom-y coordinates of the bounding box.
- plot (bool) - DEPRECATED. Whether to expect a plot to be returned by the function.
- label (str) - component name in interface.
String Shortcuts
- "image" - Uses defaults implementation.
- "segmented_image" -
Sets
labeled_segments=True
- "plot" -
Sets
type=plot
- "pil" -
Sets
type=pil
Demos
gradio.outputs.Video(self, label=None)
Used for video output.
Output type: filepath
Parameters
- label (str) - component name in interface.
String Shortcuts
- "video" - Uses defaults implementation.
Demos
gradio.outputs.KeyValues(self, label=None)
Component displays a table representing values for multiple fields.
Output type: Union[Dict, List[Tuple[str, Union[str, int, float]]]]
Parameters
- label (str) - component name in interface.
String Shortcuts
- "key_values" - Uses defaults implementation.
Demos

gradio.outputs.HighlightedText(self, color_map=None, label=None)
Component creates text that contains spans that are highlighted by category or numerical value. Output is represent as a list of Tuple pairs, where the first element represents the span of text represented by the tuple, and the second element represents the category or value of the text.
Output type: List[Tuple[str, Union[float, str]]]
Parameters
- color_map (Dict[str, str]) - Map between category and respective colors
- label (str) - component name in interface.
String Shortcuts
- "highlight" - Uses defaults implementation.
Demos


gradio.outputs.Audio(self, type="auto", label=None)
Creates an audio player that plays the output audio.
Output type: Union[Tuple[int, numpy.array], str]
Parameters
- type (str) - Type of value to be passed to component. "numpy" returns a 2-set tuple with an integer sample_rate and the data numpy.array of shape (samples, 2), "file" returns a temporary file path to the saved wav audio file, "auto" detects return type.
- label (str) - component name in interface.
String Shortcuts
- "audio" - Uses defaults implementation.
Demos


gradio.outputs.JSON(self, label=None)
Used for JSON output. Expects a JSON string or a Python object that is JSON serializable.
Output type: Union[str, Any]
Parameters
- label (str) - component name in interface.
String Shortcuts
- "json" - Uses defaults implementation.
Demos

gradio.outputs.HTML(self, label=None)
Used for HTML output. Expects an HTML valid string.
Output type: str
Parameters
- label (str) - component name in interface.
String Shortcuts
- "html" - Uses defaults implementation.
Demos

gradio.outputs.File(self, label=None)
Used for file output.
Output type: Union[file-like, str]
Parameters
- label (str) - component name in interface.
String Shortcuts
- "file" - Uses defaults implementation.
Demos

gradio.outputs.Dataframe(self, headers=None, type="auto", label=None)
Component displays 2D output through a spreadsheet interface.
Output type: Union[pandas.DataFrame, numpy.array, List[Union[str, float]], List[List[Union[str, float]]]]
Parameters
- headers (List[str]) - Header names to dataframe.
- type (str) - Type of value to be passed to component. "pandas" for pandas dataframe, "numpy" for numpy array, or "array" for Python array, "auto" detects return type.
- label (str) - component name in interface.
String Shortcuts
- "dataframe" - Uses defaults implementation.
- "numpy" -
Sets
type=numpy
- "matrix" -
Sets
type=array
- "list" -
Sets
type=array
Demos

