Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """Phox Dashboard — Hyperdimensional Engine on HuggingFace Spaces. | |
| Starts the full dashboard HTTP server (port 8765) in a background thread | |
| and serves it via a Gradio iframe so the Space remains sdk=gradio compatible. | |
| Requires: numpy (for hyper_vocab_memory) | |
| """ | |
| import os, sys, threading, time | |
| DASH_PORT = 8765 | |
| def start_dashboard(): | |
| os.environ["PHOENIX_PORT"] = str(DASH_PORT) | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| try: | |
| import phoenix_dashboard as pd | |
| except ImportError as e: | |
| print(f"[dashboard] import failed: {e}") | |
| return | |
| pd.PORT = DASH_PORT | |
| try: | |
| server = pd.Server(("0.0.0.0", DASH_PORT), pd.Handler) | |
| server.serve_forever() | |
| except Exception as e: | |
| print(f"[dashboard] server failed: {e}") | |
| # Start dashboard in background | |
| dash_thread = threading.Thread(target=start_dashboard, daemon=True) | |
| dash_thread.start() | |
| time.sleep(1.5) | |
| # ── Minimal Gradio wrapper (iframe to the dashboard) ── | |
| import gradio as gr | |
| CSS = """ | |
| iframe { border: none; width: 100%; height: 100vh; } | |
| .gradio-container { max-width: 100% !important; padding: 0 !important; } | |
| """ | |
| with gr.Blocks(title="Phox — Living Brain", css=CSS, | |
| head='<meta charset="utf-8">') as demo: | |
| gr.HTML(f"""<iframe src="http://localhost:{DASH_PORT}" | |
| width="100%" height="100%" | |
| style="border:none;position:fixed;top:0;left:0;width:100vw;height:100vh"> | |
| </iframe>""") | |
| if __name__ == "__main__": | |
| demo.queue().launch( | |
| server_name="0.0.0.0", | |
| server_port=int(os.environ.get("GRADIO_SERVER_PORT", | |
| os.environ.get("PORT", 7860))), | |
| share=False, | |
| ) |