Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,81 @@ import gradio as gr
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
|
|
|
|
| 5 |
from omega_memory import log_event
|
| 6 |
from agent_loop import reflex_loop
|
| 7 |
-
from ws_router import router as ws_router
|
| 8 |
from codexmesh_sync import CodexMeshSync
|
| 9 |
from CodexQuantum3D_Engine import simulate_quantum_visual
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
response, log = reflex_loop(user_input)
|
|
|
|
|
|
|
| 16 |
img = simulate_quantum_visual(user_input)
|
|
|
|
| 17 |
return response, str(log), img
|
|
|
|
| 18 |
except Exception as e:
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 21 |
with gr.Blocks() as interface:
|
| 22 |
gr.Markdown("## π§ Codex Reality Engine β Phase IX+Ξ© Quantum Reflex")
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
btn = gr.Button("β‘ Run Reflex Engine")
|
|
|
|
| 25 |
output1 = gr.Textbox(label="π€ Response")
|
| 26 |
output2 = gr.Textbox(label="π§Ύ Ξ©-Memory Log")
|
| 27 |
output3 = gr.Image(type="pil", label="π Quantum Visual Output")
|
| 28 |
-
btn.click(fn=launch_command, inputs=[user_input], outputs=[output1, output2, output3])
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
app = FastAPI()
|
|
|
|
|
|
|
| 31 |
app = gr.mount_gradio_app(app, interface, path="/")
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
app.add_middleware(
|
| 34 |
CORSMiddleware,
|
| 35 |
allow_origins=["*"],
|
|
@@ -38,6 +85,8 @@ app.add_middleware(
|
|
| 38 |
allow_headers=["*"]
|
| 39 |
)
|
| 40 |
|
|
|
|
| 41 |
if __name__ == "__main__":
|
| 42 |
import uvicorn
|
|
|
|
| 43 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
|
| 5 |
+
# Local Codex imports
|
| 6 |
from omega_memory import log_event
|
| 7 |
from agent_loop import reflex_loop
|
|
|
|
| 8 |
from codexmesh_sync import CodexMeshSync
|
| 9 |
from CodexQuantum3D_Engine import simulate_quantum_visual
|
| 10 |
|
| 11 |
+
# --- Optional WebSocket Router ---
|
| 12 |
+
# Safe import: won't crash if file is missing
|
| 13 |
+
try:
|
| 14 |
+
from ws_router import router as ws_router
|
| 15 |
+
WS_AVAILABLE = True
|
| 16 |
+
except Exception:
|
| 17 |
+
WS_AVAILABLE = False
|
| 18 |
|
| 19 |
+
# --- Boot CodexMesh Sync ---
|
| 20 |
+
try:
|
| 21 |
+
CodexMeshSync()
|
| 22 |
+
print("π CodexMesh Node Alive β Heartbeat Sync")
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print("β CodexMesh Sync failed:", e)
|
| 25 |
+
|
| 26 |
+
# --- Reflex Execution Wrapper ---
|
| 27 |
+
def launch_command(user_input: str):
|
| 28 |
try:
|
| 29 |
+
if not user_input.strip():
|
| 30 |
+
return "No intent provided.", "Ξ©-log skipped.", None
|
| 31 |
+
|
| 32 |
+
# Run reflex loop
|
| 33 |
response, log = reflex_loop(user_input)
|
| 34 |
+
|
| 35 |
+
# Generate quantum visual
|
| 36 |
img = simulate_quantum_visual(user_input)
|
| 37 |
+
|
| 38 |
return response, str(log), img
|
| 39 |
+
|
| 40 |
except Exception as e:
|
| 41 |
+
err_msg = f"Execution error: {str(e)}"
|
| 42 |
+
print("β Reflex Failure:", err_msg)
|
| 43 |
+
return err_msg, "Ξ©-memory failure", None
|
| 44 |
+
|
| 45 |
|
| 46 |
+
# --- Gradio UI ---
|
| 47 |
with gr.Blocks() as interface:
|
| 48 |
gr.Markdown("## π§ Codex Reality Engine β Phase IX+Ξ© Quantum Reflex")
|
| 49 |
+
|
| 50 |
+
user_input = gr.Textbox(
|
| 51 |
+
label="π Intent",
|
| 52 |
+
placeholder="Enter your intent (e.g., Render a harmonic spiral field)"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
btn = gr.Button("β‘ Run Reflex Engine")
|
| 56 |
+
|
| 57 |
output1 = gr.Textbox(label="π€ Response")
|
| 58 |
output2 = gr.Textbox(label="π§Ύ Ξ©-Memory Log")
|
| 59 |
output3 = gr.Image(type="pil", label="π Quantum Visual Output")
|
|
|
|
| 60 |
|
| 61 |
+
btn.click(
|
| 62 |
+
fn=launch_command,
|
| 63 |
+
inputs=[user_input],
|
| 64 |
+
outputs=[output1, output2, output3]
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# --- FastAPI Host ---
|
| 69 |
app = FastAPI()
|
| 70 |
+
|
| 71 |
+
# Mount Gradio app
|
| 72 |
app = gr.mount_gradio_app(app, interface, path="/")
|
| 73 |
+
|
| 74 |
+
# Add WebSocket routes if present
|
| 75 |
+
if WS_AVAILABLE:
|
| 76 |
+
app.include_router(ws_router)
|
| 77 |
+
print("π° WebSocket Router Online")
|
| 78 |
+
|
| 79 |
+
# CORS middleware
|
| 80 |
app.add_middleware(
|
| 81 |
CORSMiddleware,
|
| 82 |
allow_origins=["*"],
|
|
|
|
| 85 |
allow_headers=["*"]
|
| 86 |
)
|
| 87 |
|
| 88 |
+
# --- HF Runtime Launch ---
|
| 89 |
if __name__ == "__main__":
|
| 90 |
import uvicorn
|
| 91 |
+
print("π Codex Runtime Booting on :7860")
|
| 92 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|