Creating an Interface

gradio.Interface(self, fn, inputs, outputs, examples=None, live=False, capture_session=False, title=None, description=None)

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, AbstractInput]]]) - 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, AbstractOutput]]]) - 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.
  • live (bool) - whether the interface should automatically reload on change.
  • capture_session (bool) - if True, captures the default graph and session (needed for Tensorflow 1.x)
  • 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.
  • 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.

gradio.Interface.launch(self, share=False)

Generates the UI for the interface.

Parameters

  • share (bool) - whether to create a publicly shareable link from your computer for the interface.

Input Components

gradio.inputs.Textbox(self, lines=1, placeholder=None, default=None, numeric=False, label=None)

Component creates a textbox for user to enter input. Provides a string (or number is `is_numeric` is true) 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) - whether the input should be parsed as a number instead of a string.
  • label (str) - component name in interface.

String Shortcuts

  • "text" - Uses defaults implementation.
  • "textbox" - Sets lines=7
  • "number" - Sets numeric=True

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.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.CheckboxGroup(self, choices, 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: List[str]

Parameters

  • choices (List[str]) - list of options to select from.
  • label (str) - component name in interface.

String Shortcuts

None.

gradio.inputs.Radio(self, choices, 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: str

Parameters

  • choices (List[str]) - list of options to select from.
  • label (str) - component name in interface.

String Shortcuts

None.

gradio.inputs.Dropdown(self, choices, 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: str

Parameters

  • choices (List[str]) - list of options to select from.
  • label (str) - component name in interface.

String Shortcuts

None.

gradio.inputs.Image(self, shape=(224, 224), image_mode="RGB", label=None)

Component creates an image upload box with editing capabilities. Provides numpy array of shape `(width, height, 3)` if `image_mode` is "RGB" as an argument to the wrapped function. Provides numpy array of shape `(width, height)` if `image_mode` is "L" as an argument to the wrapped function.

Input type: numpy.array

Parameters

  • shape (Tuple[int, int]) - shape to crop and resize image to.
  • image_mode (str) - "RGB" if color, or "L" if black and white.
  • label (str) - component name in interface.

String Shortcuts

  • "image" - Uses defaults implementation.

gradio.inputs.Sketchpad(self, shape=(28, 28), invert_colors=True, flatten=False, label=None)

Component creates a sketchpad for black and white illustration. Provides numpy array of shape `(width, height)` as an argument to the wrapped function.

Input type: numpy.array

Parameters

  • shape (Tuple[int, int]) - shape to crop and resize image to.
  • invert_colors (bool) - whether to represent black as 1 and white as 0 in the numpy array.
  • flatten (bool) - whether to reshape the numpy array to a single dimension.
  • label (str) - component name in interface.

String Shortcuts

  • "sketchpad" - Uses defaults implementation.

gradio.inputs.Webcam(self, shape=(224, 224), label=None)

Component creates a webcam for captured image input. Provides numpy array of shape `(width, height, 3)` as an argument to the wrapped function.

Input type: numpy.array

Parameters

  • shape (Tuple[int, int]) - shape to crop and resize image to.
  • label (str) - component name in interface.

String Shortcuts

  • "webcam" - Uses defaults implementation.

gradio.inputs.Microphone(self, preprocessing=None, label=None)

Component creates a microphone element for audio inputs. Provides numpy array of shape `(samples, 2)` as an argument to the wrapped function.

Input type: numpy.array

Parameters

  • preprocessing (Union[str, Callable]) - preprocessing to apply to input
  • label (str) - component name in interface.

String Shortcuts

  • "microphone" - Uses defaults implementation.

Output Components

gradio.outputs.Textbox(self, label=None)

Component creates a textbox to render output text or number.

Output type: str

Parameters

  • label (str) - component name in interface.

String Shortcuts

  • "text" - Uses defaults implementation.
  • "textbox" - Uses defaults implementation.
  • "number" - Uses defaults implementation.

gradio.outputs.Label(self, num_top_classes=None, 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.
  • label (str) - component name in interface.

String Shortcuts

  • "label" - Uses defaults implementation.

gradio.outputs.Image(self, plot=False, label=None)

Component displays an image. Expects a numpy array of shape `(width, height, 3)` to be returned by the function, or a `matplotlib.pyplot` if `plot = True`.

Output type: numpy.array

Parameters

  • plot (bool) - whether to expect a plot to be returned by the function.
  • label (str) - component name in interface.

String Shortcuts

  • "image" - Uses defaults implementation.
  • "plot" - Sets plot=True

gradio.outputs.KeyValues(self, label=None)

Component displays a table representing values for multiple fields.

Output type: List[Tuple[str, value]]

Parameters

  • label (str) - component name in interface.

String Shortcuts

  • "key_values" - Uses defaults implementation.