I have a Gradio app on Hugging Face Spaces, and within that same container, I start a second server (Viser, GitHub - nerfstudio-project/viser: Web-based 3D visualization + Python) on a different port—e.g., 8080. I want to display that second webpage inside an iframe on the main Gradio interface. This works locally (because localhost:8080 is accessible on my local machine), but on Hugging Face Spaces, the second server is not accessible externally. The iframe (using gradio.HTML) never loads, with texts such as “connection is reset” or “localhost refused to connect”.
How My Code Works Locally
Within the Hugging Face Space container, I start a second web server with:
server = viser.ViserServer(host="0.0.0.0", port=port)
If port=8080, this should enable a webpage at:
HTTP │ http://localhost:8080
Basically, within a hugging face space container, I want to do:
Locally, I can open this page in a browser and successfully embed it into Gradio using:
viser_output = gr.HTML(....)
viser_url = f"http://localhost:{port}"
iframe_code = f'<iframe src="{viser_url}" width="100%" height="520px"></iframe>'
# Pass iframe_code to the Gradio HTML component
Issue on Hugging Face Spaces
• The Gradio interface itself works fine.
• The Viser server starts inside the container, but the iframe cannot access it.
• It seems like Hugging Face Spaces do not expose multiple ports publicly, preventing me from reaching localhost:8080 externally.
I was wondering if I misunderstand anything here. Is there a way to expose a second server within Hugging Face Spaces? or Could I tunnel the second server (Viser) to make it accessible externally?
Any guidance or suggestion is much appreciated. Thanks!
My hugging face space setting is:
---
title: demo3d
emoji: 🏆
colorFrom: indigo
colorTo: indigo
sdk: gradio
sdk_version: 5.17.1
app_file: app.py
pinned: false
license: cc-by-nc-4.0
short_description: demo3d (alpha test)
---