Quickstart
This guide will walk you through building your first Gradio app. You’ll learn how to create a simple web interface for a Python function and share it with others.Prerequisite: Gradio requires Python 3.10 or higher. Check your Python version with
python --version.Install Gradio
Install Gradio using pip:Build your first demo
You can run Gradio in your favorite code editor, Jupyter notebook, Google Colab, or anywhere else you write Python. Let’s write your first Gradio app.Run your app
Run the app from your terminal:The demo will open in a browser at http://localhost:7860. If you’re running in a notebook, the demo will appear embedded within the notebook.
Understanding the Interface class
You created an instance of thegr.Interface class. The Interface class is designed to create demos for machine learning models which accept one or more inputs and return one or more outputs.
The Interface class has three core arguments:
fn: the function to wrap a user interface (UI) aroundinputs: the Gradio component(s) to use for the input. The number of components should match the number of arguments in your functionoutputs: the Gradio component(s) to use for the output. The number of components should match the number of return values from your function
The function argument
Thefn argument is very flexible — you can pass any Python function that you want to wrap with a UI. The function could be anything from a music generator to a tax calculator to the prediction function of a pretrained machine learning model.
Input and output components
Gradio includes more than 30 built-in components (such asgr.Textbox(), gr.Image(), and gr.HTML()) that are designed for machine learning applications.
If your function accepts multiple arguments, pass a list of input components to inputs, with each component corresponding to one of the function’s arguments, in order. The same applies if your function returns multiple values — simply pass a list of components to outputs.
Share your demo
Gradio lets you easily share your demo without hosting on a web server. Simply setshare=True in launch(), and a publicly accessible URL will be created:
Hot reload mode
When developing locally, you can run your Gradio app in hot reload mode, which automatically reloads the app whenever you make changes to the file. Instead of runningpython app.py, run:
app.py.
Next steps
Now that you’ve built your first Gradio app, you can:Learn about Blocks
Build custom layouts and complex interactions with
gr.BlocksCreate a chatbot
Use
gr.ChatInterface to quickly build chatbot UIsExplore components
Discover Gradio’s 30+ built-in components for ML apps
Host on Spaces
Deploy your app for free on Hugging Face Spaces