Lets talk about Gradio

in today article lets take a look at Gradio

Ahmad Mizan Nur Haq
Data And Beyond
2 min readMay 25, 2024

--

What is it ?

To put it simply, Gradio is a python package that allows you to build a demo or web app for ML

Check out the gradio app here:

We can start by installing it.

pip install gradio

thats it.

Now what we going to do is to import the module

import gradio as gr

Lets Cook it

def greet(name):
return "whats up " + name + "!"

Function Definition

def greet(name):
  • The function greet is defined with a single parameter name.
  • This parameter name is expected to be a string representing a person's name.

Function Body

return "whats up " + name + "!"
  • The function constructs a greeting message by concatenating three parts: 1. The string "whats up ". 2. The value of the name parameter. 3. The string "!".
  • The + operator is used to concatenate these strings together.
  • The resulting string is then returned by the function.

Creating the interface

app = gr.Interface(fn=greet, inputs="text", outputs="text")
app.launch()
app = gr.Interface(fn=greet, inputs="text", outputs="text")
  • gr.Interface: This is a class provided by Gradio to create an interactive interface.
  • fn=greet: This specifies the function that will be called when the interface is used. In this case, the function is named greet. This function should be defined elsewhere in the code.
  • inputs="text": This specifies that the input to the greet function will be a text string. Gradio will create a text input box in the interface.
  • outputs="text": This specifies that the output of the greet function will also be a text string. Gradio will create a text output box to display the result.

Launching the Interface:

app.launch()
  • app.launch(): This method starts a local web server and opens the interface in a new tab in the default web browser. Users can interact with the interface by entering text, which will be passed to the greet function, and the function's output will be displayed.

How it works

Hey 👋 Enjoying the content? If you find it valuable, why not subscribe and follow Me on Medium for more content?

🔔 Subscribe & Follow

☕️**Buymeacoffee** |📚Substack | Github | LinkedIn

By subscribing, you’ll get the latest updates, tips, and content delivered right to your inbox.

Thank you for your support! 🙌

--

--