Python WebAssembly4 min readvia Hugging Face

Gradio gr.HTML release: one-shot web apps in a single file

gr.HTML turns a local HTML file or string into a runnable Gradio interface with one call and no server rewrite.

The Brieftide

TL;DR

  • 01gr.HTML turns a local HTML file or string into a runnable Gradio interface with one call and no server rewrite.
  • 02Gradio released gr.HTML today, a new component that lets developers wrap a local HTML file or raw HTML string into a runnable Gradio app with a single call.
  • 03The workflow is intentionally compact: point gr.HTML at an existing index.html and call launch to serve the frontend alongside any Python callbacks.

Gradio released gr.HTML today, a new component that lets developers wrap a local HTML file or raw HTML string into a runnable Gradio app with a single call. The component runs the HTML inside a Gradio interface so the file can be served, previewed locally, or packaged for Hugging Face Spaces without modifying the Python server code.

gr.HTML accepts a filesystem path, a URL, or an HTML string, and presents that content as an embeddable frame inside a Gradio Blocks layout. The workflow is intentionally compact: point gr.HTML at an existing index.html and call launch to serve the frontend alongside any Python callbacks. Gradio documents include examples for embedding JavaScript widgets, single-page apps, and micro-frontends that communicate with Python via Gradio events or standard web messaging.

Example usage is concise and reflects the one-shot intent:

import gradio as gr

with gr.Blocks() as demo:
 html = gr.HTML("path/to/index.html")

demo.launch()

This pattern preserves an existing client-side codebase while exposing it through the same port and runtime Gradio uses for typical Python components. Developers can also provide HTML as a string to generate inline content or point gr.HTML at a remote URL to embed third-party pages inside an interface.

How gr.HTML works

gr.HTML embeds the supplied HTML into a Gradio layout and serves it from the same development server that hosts other Gradio components. The component creates an iframe or a DOM insertion depending on the content and context, and Gradio's runtime maps static assets so relative paths in the HTML continue to load when served. For local development the component supports hot reload in many cases, so editing the source HTML file updates the running preview without reconstructing the entire Python environment.

Integration points include JavaScript events and message passing. A developer can build a client-side UI that dispatches a message to Python code via Gradio's event handlers or use HTTP endpoints to communicate between the embedded frontend and backend. The approach lowers friction for teams that already have a frontend artifact and want to expose it quickly to Python-driven logic, model demos, or interactive visualizations.

Deployment and limits

gr.HTML is designed to work with local launches and with hosted deployments on Hugging Face Spaces. When used in Spaces, the HTML file and its assets become part of the repository served by the environment. The component does not alter how Spaces handles build steps or static asset bundling, so developers should include necessary build outputs in the repository or use a build script to produce the final HTML before deployment.

There are practical constraints. Embedding complex single-page applications that expect a full application server may require additional routing or build adjustments. Cross-origin restrictions will still apply when embedding remote URLs, and some browser security features can limit interaction between the embedded content and the Gradio runtime. Developers should test expected messaging and resource loading in both local and deployed environments.

Why it matters

gr.HTML reduces the friction of publishing interactive frontends with Python backends by letting developers reuse existing HTML artifacts without rebuilding them as separate Gradio components. The feature shortens the path from a static web bundle to a runnable demo or model interface, affecting researchers, data scientists, and teams that maintain separate frontend and Python stacks.

Using gr.HTML in four steps
  1. 01

    Prepare HTML

    Ensure index.html and assets are ready locally or build outputs are committed for deployment.

  2. 02

    Instantiate gr.HTML

    Create gr.HTML with a file path, URL, or HTML string inside a Blocks layout.

  3. 03

    Launch locally

    Call demo.launch() to preview the embedded content served by the Gradio runtime.

  4. 04

    Deploy to Spaces

    Include the HTML and assets in the repository; push to Hugging Face Spaces for hosted sharing.

Primary source

Hugging Face

huggingface.co
Read the original

The Brieftide Daily · 06:00

Briefs like this one, in your inbox every morning.

 

FreeNo adsNo trackingUnsubscribe in one click

Read next

  1. WASM wheels on PyPI: publish packages for Pyodide browsersJun 13 · 3 min read
  2. luau-wasm 0.1a0 release: Luau in WebAssembly for browsersJun 13 · 4 min read
  3. asyncinject 0.7: Simon Willison releases Python async DI updateJun 11 · 3 min read
  4. DiffusionGemma JavaScript: WebGPU browser diffusion demoJun 10 · 3 min read