Simple implementation of Gradio

Gradio allows us to quickly create customizable UI components for Python functions. And this Gradio library is free and open-source!

Let’s try Gradio with simple python code.

Creating a Python function to get spaces count in String

We can install Gradio via pip. Below code can be used for installation:

pip install gradio

The below code can be used for importing the library:

import gradio as gr

To quickly give you an idea of how this library works, let’s run the below code as a python script

import gradio as gr
def chech_space(input_string):
""" to get spaces count"""
space_count = 0
for i in input_string:
if (i.isspace()):
space_count = space_count+1
return f"Number of spaces in the given text is {space_count}"

TO get the interface automatically need to run the below code.

face = gr.Interface(fn=chech_space, inputs=["text"], outputs=["text"])
face.launch()

In the above code fn is the python function which needs to execute

And Final Gradio output will be like…..

Thanks for reading…..