File size: 1,771 Bytes
a2124e2
bdf5f4a
a2124e2
bdf5f4a
 
a2124e2
bdf5f4a
a2124e2
bdf5f4a
a2124e2
bdf5f4a
a2124e2
 
bdf5f4a
 
 
4aa8326
bdf5f4a
 
 
a2124e2
bdf5f4a
3e5b14e
bdf5f4a
 
a2124e2
bdf5f4a
a2124e2
 
bdf5f4a
 
 
 
a2124e2
 
bdf5f4a
 
a2124e2
bdf5f4a
 
 
 
a2124e2
bdf5f4a
 
 
 
 
 
a2124e2
 
 
26b395e
a2124e2
bdf5f4a
 
a2124e2
bdf5f4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/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,
    )