Social Media

Full-Stack ML Apps (Javascript, React, Streamlit) with Gradio API

Related AI


In this video

Gradio: Building Machine Learning Applications with Streamlined APIs


When it comes to building machine learning applications, it's often necessary to wrap the entire ML functionality as an API. This allows for the separation of front-end and back-end development, where the front-end can be implemented using various JavaScript frameworks like React.js or AngularJS, while the back-end is powered by Python. Traditionally, developers would host the API on a server using frameworks like FastAPI. However, a recent announcement by Gradio has introduced a new feature that allows users to leverage Gradio as an API, hosted on Hugging Face Spaces. This article explores the capabilities of the Gradio API and demonstrates how to create a streamlined machine learning application using this powerful tool.

The Gradio API

Gradio, a machine learning toolkit, now offers an API option, allowing users to create machine learning applications hosted on Hugging Face Spaces and utilize them as APIs. This means that developers can build ML applications and seamlessly integrate them into any web application, regardless of the programming language used for the front-end. This API option enhances the flexibility and versatility of machine learning application development.

To access the Gradio API, users need to navigate to the Gradio Uplink and ensure that they are using a version greater than 3.11. Upon opening the application, a new button labeled «Use via API» will be visible at the bottom. Clicking on this button provides all the necessary details and documentation to utilize the Gradio API.

Building a Text-to-Speech Application with the Gradio API

To showcase the capabilities of the Gradio API, we will create a simple text-to-speech application using a locally hosted Streamlit application powered by the Gradio API hosted on Hugging Face Spaces.

The application allows users to enter text, which will then be converted to speech using the Gradio API. The process involves making API calls to the Hugging Face Spaces endpoint. By following the provided API documentation, developers can easily understand the necessary endpoints, request types, sample input payloads, and output response objects.

To test the API functionality, we can use tools like Hopscotch, which is an open-source alternative to Postman. By making a POST request to the API endpoint with the appropriate payload, we can verify the successful conversion of text to a base64-encoded audio string. Decoding this base64 string allows us to play the audio file and confirm the accuracy of the text-to-speech conversion.

To integrate the Gradio API into a Streamlit application, we combine the provided Python code from the Gradio documentation with the Streamlit framework. This allows us to create a fully functional machine learning application with separate front-end and back-end components. The Streamlit application collects user input, sends it to the Gradio API endpoint, receives the response, and embeds the audio file into an HTML audio player for playback.


The Gradio API provides developers with a powerful tool to build machine learning applications and utilize them as APIs. By hosting ML models on Hugging Face Spaces and creating Gradio applications on top of them, developers can harness the capabilities of the Gradio API in any programming language. This flexibility opens up numerous possibilities for integrating machine learning functionality into various applications, from simple HTTP requests to complex R Shiny applications. The Streamlit application demonstrated in this article showcases the potential of combining front-end and back-end technologies to create streamlined, full-stack machine learning applications. With the Gradio API, developers can unlock the power of machine learning and build innovative applications with ease.



We Use Cookies to Enhance Your Experience

Our website uses cookies to provide you with a personalized experience and to improve our website. By clicking 'Accept', you consent to our use of cookies. To learn more about how we use cookies and your options, please see our Cookie Policy page.