Spaces:
Running on Zero
Running on Zero
Buffy commited on
Commit ·
79c96e0
1
Parent(s): 6c42c91
diag: temp live-frames route (frame timings only, no key exposure)
Browse files- node_probe.py +47 -0
node_probe.py
CHANGED
|
@@ -99,3 +99,50 @@ def register_routes(fa_app):
|
|
| 99 |
)
|
| 100 |
except Exception as e:
|
| 101 |
return JSONResponse({"error": str(e)}, status_code=502)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
)
|
| 100 |
except Exception as e:
|
| 101 |
return JSONResponse({"error": str(e)}, status_code=502)
|
| 102 |
+
|
| 103 |
+
@fa_app.get("/respite/v2/live-frames")
|
| 104 |
+
async def _live_frames(q: str = "Write three short paragraphs about rivers."):
|
| 105 |
+
"""TEMP DIAGNOSTIC: open a Live socket, log outputTranscription frame
|
| 106 |
+
timings/count. Returns only timing metadata — never the API key."""
|
| 107 |
+
import asyncio, json, time
|
| 108 |
+
websockets = None
|
| 109 |
+
try:
|
| 110 |
+
import websockets as _ws
|
| 111 |
+
websockets = _ws
|
| 112 |
+
except ImportError:
|
| 113 |
+
return JSONResponse({"error": "websockets not installed"})
|
| 114 |
+
key = os.environ.get("GOOGLE_API_KEY") or os.environ.get("GEMINI_API_KEY")
|
| 115 |
+
if not key:
|
| 116 |
+
return JSONResponse({"error": "no google key in env"})
|
| 117 |
+
url = f"wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent?key={key}"
|
| 118 |
+
frames = []
|
| 119 |
+
t0 = time.monotonic()
|
| 120 |
+
|
| 121 |
+
async def run():
|
| 122 |
+
async with websockets.connect(url, max_size=None) as ws:
|
| 123 |
+
await ws.send(json.dumps({"setup": {"model": "models/gemini-3.8-live"}}))
|
| 124 |
+
setup = True
|
| 125 |
+
while True:
|
| 126 |
+
try:
|
| 127 |
+
raw = await asyncio.wait_for(ws.recv(), timeout=45)
|
| 128 |
+
except (asyncio.TimeoutError, Exception):
|
| 129 |
+
break
|
| 130 |
+
try:
|
| 131 |
+
f = json.loads(raw)
|
| 132 |
+
except Exception:
|
| 133 |
+
continue
|
| 134 |
+
if f.get("setupComplete"):
|
| 135 |
+
await ws.send(json.dumps({"clientContent": {"turns": [{"role": "user", "parts": [{"text": q}]}], "turnComplete": True}}))
|
| 136 |
+
setup = False
|
| 137 |
+
continue
|
| 138 |
+
t = f.get("serverContent", {}).get("outputTranscription", {}).get("text")
|
| 139 |
+
if t:
|
| 140 |
+
frames.append({"t": round(time.monotonic() - t0, 2), "len": len(t)})
|
| 141 |
+
if f.get("serverContent", {}).get("generationComplete"):
|
| 142 |
+
break
|
| 143 |
+
|
| 144 |
+
try:
|
| 145 |
+
await asyncio.wait_for(run(), timeout=50)
|
| 146 |
+
except Exception as e:
|
| 147 |
+
return JSONResponse({"error": str(e), "frames": frames})
|
| 148 |
+
return JSONResponse({"frames": frames, "count": len(frames), "total_chars": sum(f["len"] for f in frames)})
|