import random import fastapi import gradio as gr import uvicorn from viser_proxy_manager import ViserProxyManager def main() -> None: app = fastapi.FastAPI() viser_manager = ViserProxyManager(app) # Create a Gradio interface with title, iframe, and buttons with gr.Blocks(title="Viser Viewer") as demo: # Add a title and description gr.Markdown("# 🌐 Viser Interactive Viewer") # Add the iframe with a border add_sphere_btn = gr.Button("Add Random Sphere") iframe_html = gr.HTML("") @demo.load(outputs=[iframe_html]) def start_server(request: gr.Request): assert request.session_hash is not None viser_manager.start_server(request.session_hash) # Use the request's base URL if available host = request.headers["host"] # Determine protocol (use HTTPS for HuggingFace Spaces or other secure environments) protocol = ( "https" if request.headers.get("x-forwarded-proto") == "https" else "http" ) return f"""