Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,39 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
import gradio as gr
|
| 4 |
import numpy as np
|
| 5 |
-
import
|
|
|
|
| 6 |
|
| 7 |
# ============================================================
|
| 8 |
-
# RFT-Ω Harmonic Demo —
|
| 9 |
# ============================================================
|
| 10 |
|
| 11 |
-
# --- Core FastAPI ---
|
| 12 |
-
app = FastAPI(title="RFT-Ω Kernel Demo")
|
| 13 |
-
|
| 14 |
-
app.add_middleware(
|
| 15 |
-
CORSMiddleware,
|
| 16 |
-
allow_origins=["*"],
|
| 17 |
-
allow_credentials=True,
|
| 18 |
-
allow_methods=["*"],
|
| 19 |
-
allow_headers=["*"],
|
| 20 |
-
)
|
| 21 |
-
|
| 22 |
-
# --- API endpoints ---
|
| 23 |
-
@app.get("/rft/ping")
|
| 24 |
def ping():
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
@app.get("/rft/metrics")
|
| 28 |
def metrics():
|
|
|
|
| 29 |
q_omega = float(np.random.uniform(0.82, 0.89))
|
| 30 |
z_sync = float(np.random.uniform(0.75, 0.88))
|
| 31 |
-
return {"QΩ": q_omega, "ζ_sync": z_sync}
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
demo = gr.Interface(
|
| 40 |
fn=ui_fn,
|
| 41 |
-
inputs=[],
|
| 42 |
outputs="text",
|
| 43 |
title="RFT-Ω Harmonic Demo",
|
| 44 |
-
description="
|
| 45 |
)
|
| 46 |
|
| 47 |
-
# Mount the Gradio app at root so both systems coexist
|
| 48 |
-
app = gr.mount_gradio_app(app, demo, path="/")
|
| 49 |
-
|
| 50 |
-
# --- Launch only if running locally (Hugging Face auto-runs it) ---
|
| 51 |
if __name__ == "__main__":
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
+
import json
|
| 4 |
+
import requests
|
| 5 |
|
| 6 |
# ============================================================
|
| 7 |
+
# RFT-Ω Harmonic Demo — All-in-One Gradio API Simulation
|
| 8 |
# ============================================================
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def ping():
|
| 11 |
+
"""Return a JSON-formatted heartbeat."""
|
| 12 |
+
return json.dumps({"ok": True, "message": "RFT-Ω API online"})
|
| 13 |
|
|
|
|
| 14 |
def metrics():
|
| 15 |
+
"""Generate simulated QΩ / ζ_sync metrics."""
|
| 16 |
q_omega = float(np.random.uniform(0.82, 0.89))
|
| 17 |
z_sync = float(np.random.uniform(0.75, 0.88))
|
| 18 |
+
return json.dumps({"QΩ": q_omega, "ζ_sync": z_sync})
|
| 19 |
+
|
| 20 |
+
def ui_fn(choice):
|
| 21 |
+
"""Bridge UI buttons to internal API functions."""
|
| 22 |
+
if choice == "Ping":
|
| 23 |
+
return ping()
|
| 24 |
+
elif choice == "Metrics":
|
| 25 |
+
return metrics()
|
| 26 |
+
else:
|
| 27 |
+
return json.dumps({"error": "invalid option"})
|
| 28 |
+
|
| 29 |
+
# Gradio interface
|
| 30 |
demo = gr.Interface(
|
| 31 |
fn=ui_fn,
|
| 32 |
+
inputs=gr.Radio(["Ping", "Metrics"], label="Select endpoint"),
|
| 33 |
outputs="text",
|
| 34 |
title="RFT-Ω Harmonic Demo",
|
| 35 |
+
description="Select 'Ping' or 'Metrics' to call the internal JSON endpoints."
|
| 36 |
)
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|