chapter ten

10 Building a web-based UI using Gradio

 

This chapter covers

  • Building basic UI with Gradio
  • Configuring and customizing your Gradio application
  • Sharing and deploying your Gradio application on Hugging Face Spaces
  • Creating a chatbot UI for chatbot applications

Imagine that you’ve spent weeks coding your machine learning project, and it’s finally done. Now you’re eager to show it off to your friends, and you hope it will impress your boss. But you have one more thing to do: create a nice shiny frontend to impress your users.

Developers excel in technical aspects and problem-solving, but their strengths may not always align with creative design. How do you come up with a nice web frontend that can interface with your machine learning models?

Gradio, an open source Python package, makes it quick and easy to build a demo web application that showcases your machine learning applications. What’s more, with a single click, you can share a link to your demo application using Gradio’s built-in sharing feature.

10.1 Basics of Gradio

To install the Gradio package, use the pip command in Jupyter Notebook:

!pip install gradio

Let’s start by exploring how Gradio works. You’ll create a simple Gradio application and then dive into how it works and how to deploy it in a production environment. Specifically, you’ll learn how to do the following:

10.1.1 Using Gradio’s Interface class

10.1.2 Configuring flagging options

10.1.3 Configuring authentication

10.1.4 Customizing the server and port

10.1.5 Sharing your Gradio application

10.1.6 Deploying your Gradio application to Hugging Face Spaces

10.2 Working with widgets

10.2.1 Working with Textbox

10.2.2 Working with Audio

10.2.3 Working with Images

10.2.4 Working with selection widgets

10.3 Creating a chatbot UI