RFTSystems commited on
Commit
d38a78d
·
verified ·
1 Parent(s): 5563105

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -34
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 uvicorn
 
6
 
7
  # ============================================================
8
- # RFT-Ω Harmonic Demo — Unified FastAPI + Gradio
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
- return {"ok": True, "message": "RFT-Ω API online"}
 
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
- # --- Gradio UI ---
34
- def ui_fn():
35
- q = float(np.random.uniform(0.82, 0.89))
36
- z = float(np.random.uniform(0.75, 0.88))
37
- return f"QΩ = {q:.3f} | ζ_sync = {z:.3f}"
38
-
 
 
 
 
39
  demo = gr.Interface(
40
  fn=ui_fn,
41
- inputs=[],
42
  outputs="text",
43
  title="RFT-Ω Harmonic Demo",
44
- description="Use /rft/ping and /rft/metrics for API JSON access."
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
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
 
 
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()