RFT_Omega_API / app.py
RFTSystems's picture
Update app.py
27dce05 verified
raw
history blame
1.9 kB
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import gradio as gr
import numpy as np
import uvicorn
# ============================================================
# RFT-Ω HARMONIC DEMONSTRATOR — PUBLIC VALIDATION API
# ============================================================
# --- Core FastAPI application ---
api = FastAPI(title="RFT-Ω Kernel Validation API",
description="Public verification interface for RFT harmonic stability metrics.",
version="1.0")
api.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# --- Secure public endpoints --------------------------------
@api.get("/api/ping")
def ping():
"""Lightweight heartbeat for connectivity verification."""
return {"ok": True, "message": "RFT-Ω API online and stable"}
@api.get("/api/metrics")
def metrics():
"""Return simulated QΩ and ζ_sync readings."""
q_omega = float(np.random.uniform(0.82, 0.89))
z_sync = float(np.random.uniform(0.75, 0.88))
return {
"QΩ": round(q_omega, 3),
"ζ_sync": round(z_sync, 3),
"status": "nominal"
}
# --- Gradio dashboard (for manual inspection) ----------------
def ui_fn(choice):
if choice == "Ping":
r = ping()
else:
r = metrics()
return f"{r}"
demo = gr.Interface(
fn=ui_fn,
inputs=gr.Radio(["Ping", "Metrics"], label="Select endpoint"),
outputs="text",
title="RFT-Ω Harmonic Demo",
description="Endpoints live at /api/ping and /api/metrics for JSON access."
)
# --- Combine FastAPI + Gradio -------------------------------
app = gr.mount_gradio_app(api, demo, path="/")
# --- Local launch (HF auto-runs this) ------------------------
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7860)