
Gradio
Gradio is an open source Python package for building web interfaces for ML models, APIs, or any Python function, letting you launch an app locally, generate share links with share=True, and deploy on your own server or on hosting like Hugging Face Spaces.
Overview
Gradio is an open source Python library for turning machine learning functions into interactive web apps. In the quickstart, Gradio describes building a demo or web application for an ML model, an API, or any arbitrary Python function and sharing it in seconds without needing JavaScript, CSS, or separate web hosting knowledge. The two primary construction styles are Interface and Blocks.
Interface is a fast wrapper for common single function demos, while Blocks provides more flexibility and control for multi step layouts, dashboards, and custom interaction patterns. Apps are assembled from UI components and event listeners, then launched with a built in web server. Sharing and deployment are practical features rather than a separate product layer.
The sharing guide explains that setting share=True in launch() creates a public link that anyone can open in a browser. It also covers hosting options such as Hugging Face Spaces, embedding hosted spaces, deep links, authentication, rate limits, analytics, and mounting a Gradio app within FastAPI. For programmatic use, the docs list client libraries for Python and JavaScript.
The Python client is installed with pip install gradio-client and the JavaScript client with npm install @gradio/client, enabling scripts and front ends to call hosted Gradio apps as part of pipelines and automation. Because Gradio is open source, pricing for the library itself is free. Any runtime cost depends on where you host the app and what compute you attach, so teams should evaluate deployment targets, security requirements, and model resource needs separately.
Key features
- Interface builder: Wrap a Python function with inputs and outputs to create a working web demo that is easy to share and reuse
- Blocks framework: Use Blocks for flexible layouts and multi step flows when Interface does not cover your interaction needs
- Launch server: launch() starts a local web server for your app so you can test and iterate without extra infrastructure setup
- Public share links: Set share=True in launch() to create a public link anyone can open in a browser for quick reviews and demos
- Hosting paths: Guides cover deploying on Hugging Face Spaces or your own server and embedding hosted spaces inside websites
- FastAPI mounting: The sharing guide includes mounting within FastAPI so apps can live inside an existing Python API service
- Client libraries: Use gradio-client for Python and @gradio/client for JavaScript to call hosted apps from code and pipelines
- Operational controls: Documentation includes authentication and rate limits and analytics and network request access for hosted apps
Best for
- Model demo: Build a quick browser UI for a text classifier or image model so teammates can test behavior without notebooks
- API wrapper: Put a web front end on top of an existing inference API so users can send inputs and view outputs interactively
- Shareable prototype: Launch with share=True to generate a public link for stakeholder review during early product discovery
- Internal tools: Create a small dashboard for analysts to run a Python workflow on demand and export results for reporting
- Website embed: Host on Hugging Face Spaces then embed the app into documentation or a landing page for guided trials and feedback
- FastAPI app: Mount a Gradio UI inside FastAPI so the same service provides both a web interface and a programmatic API endpoint
- Automation client: Call a hosted Gradio app from Python or JavaScript clients to integrate model steps into pipelines and scripts
- Controlled access: Add authentication and apply rate limits so shared demos stay usable when many users test at once online
Capabilities
Build Interface app
Use gr.Interface to wrap a Python function with declared inputs and outputs and launch a working UI quickly. This pattern is suited to single step demos and can expose an api_name so callers can invoke the same function programmatically.
Compose with Blocks
Use gr.Blocks to assemble multiple components and event listeners inside a with clause. Blocks is the approach for custom layouts, multi step flows, and dashboards where you need explicit control over state and interactions.
Share and deploy
Launch locally for development or set share=True in launch() to create a public link. Guides cover hosting on Hugging Face Spaces, embedding hosted spaces, deep links, authentication, and mounting a Gradio app within FastAPI.
Call apps from code
Install gradio-client for Python or @gradio/client for JavaScript to make requests to hosted Gradio apps. This enables automation pipelines, browser based callers, and integration of Gradio endpoints into larger systems.
Frequently Asked Questions
Is Gradio free and what costs should I expect?
The Gradio library is open source and can be used for free. Any cost comes from where you deploy it and the compute used by your models. Share links and hosting options may have separate hosting limits depending on the platform you choose.
Do I need front end skills to use Gradio?
The quickstart states you can build demos without JavaScript, CSS, or web hosting experience. You still need basic Python to define functions and inputs, and you may need extra engineering for production deployment, security, and monitoring.
How can I integrate Gradio apps with other systems?
Gradio docs list official client libraries for Python and JavaScript so other services can call your app. The sharing guide also covers mounting within FastAPI, which can help combine a UI with an existing API service and auth strategy.
What are data privacy and security considerations?
Inputs users submit through a Gradio UI are processed by your Python function and may be logged by your hosting environment. Use authentication and follow your hosting provider security controls, and avoid exposing sensitive data on public share links.
When is Gradio a better fit than custom web apps?
Gradio is strong for rapid ML demos and internal tools because UI components and sharing are built in. A custom web app can be better when you need a bespoke UX, strict governance, or complex multi service front end architectures.


