Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from fastapi.middleware.wsgi import WSGIMiddleware
|
| 5 |
+
|
| 6 |
+
# -----------------------------
|
| 7 |
+
# FastAPI section (real API)
|
| 8 |
+
# -----------------------------
|
| 9 |
+
api = FastAPI(title="RFT-Ω Kernel Demo")
|
| 10 |
+
|
| 11 |
+
@api.get("/rft/ping")
|
| 12 |
+
def ping():
|
| 13 |
+
return {"ok": True, "message": "RFT-Ω API online"}
|
| 14 |
+
|
| 15 |
+
@api.get("/rft/metrics")
|
| 16 |
+
def metrics():
|
| 17 |
+
q_omega = float(np.random.uniform(0.82, 0.89))
|
| 18 |
+
z_sync = float(np.random.uniform(0.75, 0.88))
|
| 19 |
+
return {"QΩ": q_omega, "ζ_sync": z_sync}
|
| 20 |
+
|
| 21 |
+
# -----------------------------
|
| 22 |
+
# Gradio UI section
|
| 23 |
+
# -----------------------------
|
| 24 |
+
def ui_fn():
|
| 25 |
+
q = float(np.random.uniform(0.82, 0.89))
|
| 26 |
+
z = float(np.random.uniform(0.75, 0.88))
|
| 27 |
+
return f"QΩ = {q:.3f} | ζ_sync = {z:.3f}"
|
| 28 |
+
|
| 29 |
+
iface = gr.Interface(
|
| 30 |
+
fn=ui_fn,
|
| 31 |
+
inputs=[],
|
| 32 |
+
outputs="text",
|
| 33 |
+
title="RFT-Ω Harmonic Demo",
|
| 34 |
+
description="Endpoints: /rft/ping and /rft/metrics available for JSON access."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# -----------------------------
|
| 38 |
+
# Mount Gradio onto FastAPI
|
| 39 |
+
# -----------------------------
|
| 40 |
+
app = FastAPI()
|
| 41 |
+
app.mount("/api", api) # optional alias under /api
|
| 42 |
+
app.mount("/", WSGIMiddleware(iface.app))
|