Gradio is an open-source python library which allows you to quickly create easy to use, customizable UI components for your ML model, any API, or any arbitrary function in just a few lines of code. You can integrate the GUI directly into your Python notebook, or you can share the link to anyone.
$ pip install gradio
We can create interfaces with Gradio using
gradio.Interface(self, fn, inputs, outputs, examples=None, live=False,
capture_session=False, title=None, description=None)
- fn: (Callable)the function to wrap an interface.
- inputs: (Union[str, List[Union[str, AbstractInput]]]) a single Gradio input component, or list of Gradio input components.
- outputs: (Union[str, List[Union[str, AbstractOutput]]]) a single Gradio output component, or list of Gradio output components.
- live: (bool) whether the interface should automatically reload on change.
- capture_session: (bool) if True, captures the default graph and session (needed for Tensorflow 1.x)
- title: (str) a title for the interface; if provided, appears above the input and output components.
- description: (str) a description for the interface; if provided, appears above the input and output components.
- examples: (List[List[Any]]) sample inputs for the function; if provided, appears below the UI components and can be used to populate the interface. Should be nested list, in which the outer list consists of samples and each inner list consists of an input corresponding to each input component.
UI for the interface can be generated by
gradio.Interface, launch() function.
share: (bool) - whether to create a publicly shareable link from your computer for the interface.
There are several Input and Output Component given for the inputs and outputs parameter of
|Input Components||Output Components|
Now, to wrap this function with gradio interface write following code in the same file.
When you run the above code cells in a jupyter notebook. It will generate a UI like this:
You can also copy the link and share that to anyone, it will open the same UI in the browser. Now, we’ll show you how to make an interface for a Machine Learning model.
For the demo, we’ll load a pre-trained Inception Net Image Classification model with tensorflow. Since this is an Image Classification model we’ll use Image input interface. We’ll output a dictionary of labels and their corresponding confidence scores with the Label output interface.
When you run the above code cell it will generate the UI like this:
Here you can drag and drop the image in the left section of UI and click submit you will get the result like:
Also if you copy the link and paste it in your browser, your interface will look like this:
It is not localhost so you can open the same link on any device.
For more information about input and output components checkout the Gradio’s documentation.
Resource : Gradio’s documentaion
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Learning Model Building in Scikit-learn : A Python Machine Learning Library
- Creating a simple machine learning model
- Saving a machine learning Model
- seq2seq model in Machine Learning
- Deploy Machine Learning Model using Flask
- Using Google Cloud Function to generate data for Machine Learning model
- Machine Learning Computing at the edge using model artifacts
- Deploy a Machine Learning Model using Streamlit Library
- Metrics for Machine learning model
- How to Prepare Data Before Deploying a Machine Learning Model?
- Artificial intelligence vs Machine Learning vs Deep Learning
- How to Start Learning Machine Learning?
- Difference Between Artificial Intelligence vs Machine Learning vs Deep Learning
- Need of Data Structures and Algorithms for Deep Learning and Machine Learning
- Azure Virtual Machine for Machine Learning
- How to create a Face Detection Android App using Machine Learning KIT on Firebase
- ML | Reinforcement Learning Algorithm : Python Implementation using Q-learning
- Introduction To Machine Learning using Python
- Data Preprocessing for Machine learning in Python
- Best Python libraries for Machine Learning
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.