Gradio — Build & Share Delightful Machine Learning Apps

Vivek Pandit
3 min readMar 11, 2023

--

Overview

Gradio is a Python library that allows you to easily create customisable, interactive UI components for your machine learning or data science models. With Gradio, you can quickly create interfaces that allow users to input data, run your model, and see the results in real-time.

Gradio supports a wide range of input and output types, including images, text, audio, and video, and it is compatible with the most popular machine learning frameworks, including TensorFlow, PyTorch, and scikit-learn.

To use Gradio, you simply define a function that takes in some input and returns some output, and then you use Gradio’s interface-building functions to create an interactive UI for that function. You can customise the look and feel of the interface, including adding images and text, and you can also specify how the interface should handle errors and other edge cases.

Gradio is a powerful tool for quickly creating and testing machine learning models, as well as for creating demonstrations and tutorials to share your work with others. It is easy to use and well-documented, making it a popular choice for data scientists and machine learning practitioners.

UI Components

Here are some of the UI components available in Gradio:

  1. Input components:
  • Textbox: Allows users to input free-form text.
  • Slider: Allows users to select a value from a range of numeric values.
  • Checkbox: Allows users to select one or more options from a list of choices.
  • Dropdown: Allows users to select one option from a list of choices.
  • Radio: Allows users to select one option from a list of choices displayed as a set of radio buttons.
  • File upload: Allows users to upload a file from their local computer.
  1. Output components:
  • Textbox: Displays text output.
  • Image: Displays image output.
  • Plot: Displays a plot or chart.
  • Audio: Plays an audio file.
  • Video: Plays a video file.
  • HTML: Displays HTML content.

Gradio also provides a way to combine multiple input and output components into a single interface, allowing users to interact with a machine-learning model in a more intuitive and user-friendly way.

Sample Code

Suppose I am working on a question-answering kind of use case, in which user will use their voice to ask questions. I will have to provide the user a microphone button on UI that will enable recording by one of the microphone devices on the computer. Below is the code snippet that will do it.

import gradio as gr

ui = gr.Interface(fn=transcribe, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text").launch()
ui.launch()

Below is what the UI will look like.

What this does is provide a very easy way for ML engineers to train and test their models, without them knowing any of the fancy UI libraries such as React or Angular.

Refer for more

https://gradio.app/docs/

--

--