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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -15
app.py CHANGED
@@ -1,39 +1,62 @@
 
 
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()
 
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 DEMONSTRATOR PUBLIC VALIDATION API
9
  # ============================================================
10
 
11
+ # --- Core FastAPI application ---
12
+ api = FastAPI(title="RFT-Ω Kernel Validation API",
13
+ description="Public verification interface for RFT harmonic stability metrics.",
14
+ version="1.0")
15
+
16
+ api.add_middleware(
17
+ CORSMiddleware,
18
+ allow_origins=["*"],
19
+ allow_credentials=True,
20
+ allow_methods=["*"],
21
+ allow_headers=["*"],
22
+ )
23
+
24
+ # --- Secure public endpoints --------------------------------
25
+ @api.get("/api/ping")
26
  def ping():
27
+ """Lightweight heartbeat for connectivity verification."""
28
+ return {"ok": True, "message": "RFT-Ω API online and stable"}
29
 
30
+ @api.get("/api/metrics")
31
  def metrics():
32
+ """Return simulated QΩ and ζ_sync readings."""
33
  q_omega = float(np.random.uniform(0.82, 0.89))
34
  z_sync = float(np.random.uniform(0.75, 0.88))
35
+ return {
36
+ "QΩ": round(q_omega, 3),
37
+ "ζ_sync": round(z_sync, 3),
38
+ "status": "nominal"
39
+ }
40
 
41
+ # --- Gradio dashboard (for manual inspection) ----------------
42
  def ui_fn(choice):
 
43
  if choice == "Ping":
44
+ r = ping()
 
 
45
  else:
46
+ r = metrics()
47
+ return f"{r}"
48
 
 
49
  demo = gr.Interface(
50
  fn=ui_fn,
51
  inputs=gr.Radio(["Ping", "Metrics"], label="Select endpoint"),
52
  outputs="text",
53
  title="RFT-Ω Harmonic Demo",
54
+ description="Endpoints live at /api/ping and /api/metrics for JSON access."
55
  )
56
 
57
+ # --- Combine FastAPI + Gradio -------------------------------
58
+ app = gr.mount_gradio_app(api, demo, path="/")
59
+
60
+ # --- Local launch (HF auto-runs this) ------------------------
61
  if __name__ == "__main__":
62
+ uvicorn.run(app, host="0.0.0.0", port=7860)