Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 37 ยท Getting Started

What Is Gradio?

Learn what Gradio is, what problems it solves, how a Python function becomes a web app, and when to choose it over Streamlit, Flask or a full front end.

Gradio is an open-source Python library for turning a function into a small web application. You write a normal Python function, tell Gradio which kinds of inputs and outputs it has (text, images, audio, sliders, tables), and Gradio builds a browser interface, a REST API and a shareable link around it. It was created so that machine learning researchers could let other people try a model without writing HTML, JavaScript or a web server.

This track teaches Gradio from the first function to custom components and deployment. A note on honesty first: the real Gradio package, its web server and its browser front end cannot run inside this site. Every import gradio as gr block is therefore read-only, and the output is described in words. Each lesson also gives you runnable stand-ins (real Python running in your browser) that reproduce the underlying ideas, such as reading a function signature or routing events, and every stand-in is labelled.

The idea in one example

Here is a complete Gradio app. The function is ordinary Python:

Python
import gradio as gr

def greet(name, excited):
    message = f"Hello, {name}"
    return message + "!" if excited else message + "."

demo = gr.Interface(
    fn=greet,
    inputs=[gr.Textbox(label="Your name"), gr.Checkbox(label="Excited?")],
    outputs=gr.Textbox(label="Greeting"),
)

demo.launch()

Running this file starts a local server (by default at http://127.0.0.1:7860). The page shows a text box, a checkbox, a Submit button, a Clear button and an output box. Typing Ada, ticking the box and pressing Submit shows Hello, Ada! in the output box. The page also has a "Use via API" link at the bottom that documents a ready-made HTTP endpoint for the same function.

Notice what you did not write: no routes, no HTML, no JavaScript, no CORS settings, no form handling.

Where Gradio fits

Tool Main idea Best at
Gradio A function with typed inputs and outputs Model demos, quick APIs, sharing a prototype
Streamlit A script that reruns top to bottom Dashboards and data apps (see the Streamlit track)
Flask or FastAPI You write routes and templates Full control, production back ends
Jupyter widgets Controls inside a notebook Exploring in a notebook

Gradio is strongest when the product is "input goes in, result comes out": classify this image, transcribe this audio, summarize this text, chat with this model. It is also the front end behind many public demos on Hugging Face Spaces.

What Gradio gives you for free

  • A UI built from components: text boxes, images, audio and files, dropdowns and sliders.
  • An API: every function becomes an endpoint you can call from Python or JavaScript clients.
  • A queue that lines up requests so a slow model is not overwhelmed (see queue and concurrency).
  • Sharing: share=True creates a temporary public URL that tunnels to your machine.
  • Flagging, examples and caching for collecting feedback and speeding up demos.

A function becomes an app

Python function Your own code
Components Inputs and outputs
Web page Built for you
API Also built for you

One function, two front doors.

1 / 2

Stand-in 1: a function and its signature

Gradio can work out a lot from your function. The standard library does the same inspection, so we can see what information is available. This is our own stand-in, not Gradio code.

Python Stand-in: what a function tells a UI builder

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A real UI builder uses exactly this kind of information to decide which widgets to draw. Gradio itself asks you to list components explicitly in Interface, which is clearer and gives you labels and options.

Stand-in 2: a function behind a "web request"

When you press Submit, the browser sends the input values to the server, the server calls your function, and the result travels back. We can model that with a dictionary standing in for the request body:

Python Stand-in: simulating a Submit click

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real Gradio uses a very similar shape: a list of input values in, a list of output values out. The next lessons show what happens around that call.

When not to use Gradio

  • You need a multi-page site with logins, billing and a database: use a web framework such as Flask or Django and call your model from there.
  • You need pixel-perfect branding on every element: Gradio can be themed (themes and CSS), but it is not a design tool.
  • You need a long-lived dashboard that reacts to every widget change with data refresh: Streamlit or a BI tool may feel more natural.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is Gradio's core idea?

    You provide a function and describe its inputs and outputs. Gradio generates the web UI, the API and the queue around it.
  2. 2. Which of these does Gradio give you without extra code?

    Every event function is exposed through the API automatically. Logins and databases are your own responsibility.
  3. 3. Which job is Gradio best suited for?

    Gradio shines at input-to-output demos such as classifiers, transcribers and chat models.
  4. 4. Why are the Gradio code blocks in this track read-only?

    The site runs Python in your browser, but not the Gradio server. Stand-ins reproduce the underlying ideas and are always labelled.

Summary

  • Gradio turns a Python function into a web UI and an API with very little code.
  • You choose input and output components; Gradio handles the page, the queue and sharing.
  • Interface is the quick route; Blocks gives full layout and event control.
  • It fits model demos best; for large sites use a web framework.
  • Code that imports gradio is read-only here; labelled stand-ins run in your browser.

Next: Install Gradio and Build Your First App