Loading…
Using & Mixing Hugging Face Models with Gradio 2.0
Abubakar Abid
Summary
The Hugging Face Model Hub hosts more than 10,000 user-submitted machine learning models spanning natural language processing, image classification, and audio processing. Machine learning developers increasingly need to demo models to interdisciplinary collaborators or non-programmers to uncover biases and failure points. The Gradio 2.0 library enables users to create graphical user interfaces and load almost any Hugging Face model using a single line of code. By default, these interfaces query Hugging Face's hosted Inference API without requiring an API key, though users can also run computations locally via the transformers library. Gradio interfaces can be customized through the Interface class and composed to load multiple models in parallel or chain them in series.
Context
Machine learning models need to be shared and demoed to interdisciplinary teams and non-programmers to help uncover biases and failure points, but programmatic interfaces typically restrict model interactions to software developers.
Approach / What changed
Gradio 2.0 integrates with the Hugging Face Model Hub to generate model GUIs in one line of code, using either Hugging Face's hosted Inference API or local execution via transformers, while supporting custom Interface parameters and model compositions in parallel or series.
Takeaways
- Gradio 2.0 allows loading almost any model from the Hugging Face Model Hub into a shareable GUI with a single line of code.
- Inference runs by default through Hugging Face's hosted Inference API without requiring an API key, or locally by installing the transformers library.
- Developers can compose models within Gradio by executing them in parallel for side-by-side comparison or chaining them in series for multi-step tasks.
Related reading
huggingface.co ·
Showcase Your Projects in Spaces using Gradio
Demonstrating machine learning projects to the community requires accessible hosting and minimal interface boilerplate. Gradio integrates directly with the Hugging Face Hub and its underlying Inference API, enabling developers to load models using repository identifiers and launch interactive interfaces with a few lines of code. Hugging Face Spaces provides a free hosting environment where users select Gradio as the SDK, commit an app.py script, and deploy live web demonstrations for frameworks like Transformers, spaCy, SpeechBrain, and Asteroid. For complex workflows, developers can chain multiple models sequentially via Gradio Series or host custom checkpoints directly when models lack native Inference API support.
mervehuggingface.co ·
Gradio is joining Hugging Face!
Hugging Face has acquired Gradio, the open-source machine learning library designed for building and sharing interactive model interfaces. Gradio originated in 2019 when its founder struggled to share a medical computer vision model with a physician collaborator who did not write Python. Co-founded alongside Ali Abdalla, Ali Abid, and Dawood Khan, the project expanded from computer vision into text, speech, and video modalities. Over 300,000 demos have been built using Gradio, allowing interdisciplinary industry teams and researchers to debug models internally and showcase them externally to non-technical users. The acquisition unites Gradio with Hugging Face to broaden browser-based machine learning accessibility and expand hiring efforts across the joint team.