Gradio Client
Most people in the AI-sphere (Deep Learning, LLM’s) are aware of the Gradio project (now under the huggingface umbrella).
Gradio is a simple Machine Learning App framework that provides easy components and reactivity. See for yourself:
import gradio as gr
def greet(name):
return "Hello " + name + "!"
= gr.Interface(fn=greet, inputs="text", outputs="text")
demo demo.launch()
One drawback is that input, output, and function are separated which reduces type-safety and removes all intellisense. This is a big one for me and makes me highly prefer streamlit
& solara
. Though I can’t deny all the greatness Gradio provides to the table.
Even though Gradio is well-known some people might’ve missed that they’ve added two new projects in their fast pace!
gradio_client
: A client that can call any Gradio Application (!)- Gradio clients are easily deployed on HuggingFace, and there exist a ton of them. All are now accessible in a REST-like interface (including the compute)!
gradio_lite
: A WASM version of Gradio.- Very simple to embed a Gradio app inside a HTML file or JS app.
- They’ve implemented smooth solutions for things like Multi File, PIP Requirements and more.
- WASM brings Serverless deployment with Low Latency and high Privacy.
How do I use Gradio Client?
Step 1: Connect to a Client
from gradio_client import Client, handle_file
= Client("abidlabs/whisper") client
Step 2: Predict
client.predict(=handle_file("audio_sample.wav")
audio
)
>> "This is a test of the whisper speech recognition model."
Easy right?!
If we have multiple boxes / steps in the Gradio App we can call each of the components. The client usage of any Gradio App is easily found at the bottom.
And that opens a new menu which shows how to use each box of the App.
Available Clients
Anyone can run this as it supports regular REST requests! They supply a curl
sample on how to query the App. But they’ve got a Python and JS native client.
Possibilities
Gradio implemented the whole thing in a way where you don’t need to do anything at all. In turn we now get user-friendly App that is easily deployed with an automatically included REST API. It’s two birds with one stone!
Combining this “App+API” deployment with the free, or paid, HuggingFace Spaces creates a high-value package!
HuggingFace (HF) Spaces is as simple deployments get:
- Free compute1
- ZeroGPU available using Gradio SDK
- Natively Support streamlit, Gradio, static (webapp)
- Support any app via Docker2
HF Spaces can deploy apps via Client, git, or Drag n’ Drop.
You get a public pretty URL huggingface.co/spaces/<USER>/<APP_NAME>
to share. All in all a great tool that puts the power into developers hands!
Outro
This blog is really short and to the point. The Gradio Client is sweet and I really wanted to share the experience.
The combination of App+API written at the same time is exciting, when enhancing it with HuggingFace Spaces it all becomes magical. And Gradio’s “auto-share” when running locally that can then provide an API too is not too shabby 😉
This is it for this time,
Hampus Londögård