PyTorch
Published in

PyTorch

Running PyTorch Hub Models in Your Browser (with Gradio)

A new button on PyTorch Hub allows you to try models without writing any code!

You may have seen a new button on PyTorch Hub! Here’s what it does:

PyTorch Hub has around 50 (and growing) state-of-the-art machine learning models in computer vision, audio, and natural language processing. The PyTorch Hub team’s goal is to make models accessible and easy to use.

Many models can be opened in a colab notebook, where the code is provided to load a model, as well as make predictions on new data programmatically.

But it’s not just programmers who are using machine learning models!

Increasingly, interdisciplinary machine learning teams create demos for non-programmers to test models and help discover biases and failure points in the model. Building these demos often takes time since it involves creating a web-based front end and infrastructure for hosting and sharing the model.

Demos like this one:

It takes just 5 lines of Python code to create a demo like this using Gradio

This is where the Gradio library comes in. The open-source Python library (with more than 2,500 stars) lets machine learning developers create demos and GUIs from models very easily, and share them for free with collaborators as easily as sharing a Google docs link.

We’re excited to share that many of the models on PyTorch Hub now include a button that lets you create a Gradio demo so that anyone can use the model to make predictions without needing to write any code. Above is an example of a Gradio demo for an bird image classification model.

Gradio’s library is quite flexible and can handle different types of models. Here is another interface for a speech-to-text model.

A Gradio interface for a speech-to-text model

With the Gradio library, you can test the model with your own voice, and so can your teammates/users/testers/customers.

What does the code look like to generate this GUI? Just 3 lines of code (See the notebook for yourself)

Given the ease of creating these demos, we decided to incorporate them into PyTorch Hub itself. To create a demo like this, simply click on the “Demo Model Output” button next on the model page for models on PyTorch Hub:

Click this button to open a Colab notebook & then click Runtime > Run all

This launches a Colab notebook with the code above. You can edit the code to customize the GUI that is created, or simply click “Runtime > Run all” to launch the GUI. You can even create a shareable link allowing you to send the GUI to teammates and collaborators.

Launching the Silero Speech-to-Text Model Demo

And that’s it! We hope you find PyTorch Hub models even easier to use through Gradio.

We would like to thank the PyTorch team for integrating Gradio into the PyTorch Hub and creating this amazing experience for programmers and non-programmers alike!

--

--

--

An open source machine learning framework that accelerates the path from research prototyping to production deployment

Recommended from Medium

Alphabet Soup of IT Architects

Camera App with Flask and OpenCV

Coding Problems and Solutions-5

Slow Python Code? I Reveal my 5 (Extreme) SECRETS to Rocket its Performance to the Moon🚀

Best VScode themes 2021

Agile at Archimedes Digital

Pong Game using Pygame

Archway — smart contract platform that rewards developers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abubakar Abid

Abubakar Abid

More from Medium

Intro to PyTorch: Part 1

Having fun with CLIP features — Part I

Adventures in Deploying a Deep Learning Model in the Browser

ML Model Optimization for low compute environments