![](https://crypto4nerd.com/wp-content/uploads/2023/02/1DmazJpVHNDZ7p9paao7xpQ-1024x530.jpeg)
A step-by-step guide:
To demonstrate what I’m talking about, I’m going to write down the steps to follow in order to use this tool as well as an example from my jupyter notebook, Enjoy!
1- Install the package:
pip install gradio
2- Hello world demo:
# import gradio package
import gradio as gr# define a function that receives a name and displays "hello name!"
def greet(name):
return "Hello " + name + "!"
# the gradio Interface class
### with:
##fn: the function to wrap a UI around
##inputs: which component(s) to use for the input
##outputs: which component(s) to use for the output
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
# launch the app!
demo.launch()
3- Share the Hello world demo:
To create a public link, set `share=True` in launch()
Let’s do it!
# import gradio package
import gradio as gr# define a function that receives a name and displays "hello name!"
def greet(name):
return "Hello " + name + "!"
# the gradio Interface class
### with:
##fn: the function to wrap a UI around
##inputs: which component(s) to use for the input
##outputs: which component(s) to use for the output
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
# launch the app and create shareable links!
demo.launch(share=True)
This outputs the following things:
Now I’m able to access my GUI locally(localhost) or via a public link(using huggingface platform), let’s demonstrate that!
4- Local access to the Hello world demo:
5- Public access to the Hello world demo:
well, Gradio gives you a shareable public link but, it expires within 75 hours.
Let’s jump to hugginface platform!
Hugging Face Spaces provides the infrastructure to permanently host your machine learning model for free!
After signing up to the platform and confirming my account, I created a new space like shown in the below image
After that, I pushed my script.py file to the repository created,
After that, I switched to the app section where I can preview my app
Just click the right button within huggingface interface and select “Embed this Space” and a pop-up menu appears showing you a lot of options:
Success! I can now share the app with my friends and discover it using various devices!
Refer to https://ismailouahbi-hello-world-demo.hf.space to preview this app and let me know if you’ve enjoyed this article!