10 Building Web-Based UI using Gradio

 

This chapter covers

  • Building basic UI using Gradio
  • Configuring and customizing your Gradio application
  • Sharing and deploying your Gradio application on HuggingFace Spaces
  • Creating a chatbot UI for chatbot applications

Imagine you have just spent weeks coding your machine learning projects and it is finally done! Now, you are eager show it off to your friends and hopefully it will impress your boss. But there is just one more thing you need to do – create a nice shiny front-end so that you can impress your users. But while developers excel in technical aspects and problem-solving, their strengths may not always align with creative design. So how do you quickly come up with a nice web front-end that can interface with your machine learning models?

Introducing Gradio, an open-source Python package that makes it very easy for you to quickly build a demo web application to showcase 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, you can use the pip command in Jupyter notebook:

!pip install gradio
 

At the time of writing, the version of the Gradio Python package used is 5.18.0.

Let’s start by exploring the basics of how Gradio works. We will create a simple Gradio application and then dive into how it works and how you can deploy them in production environments. Specifically, you will learn:

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.1 Working with Different Widgets

10.1.1 Working with Textbox

10.1.2 Working with Audio

10.1.3 Working with Images

10.1.4 Working with selection widgets

10.1.5 Layout using the TabbedInterface class

10.2 Creating a Chatbot UI

10.2.1 Creating the basic chatbot UI

10.2.2 Wiring the Textbox’s submit event

10.2.3 Clearing the Chatbot

10.3 Summary