Lior-0618 commited on
Commit
ef7f038
·
1 Parent(s): 64b796f

debug: add /debug-inference endpoint to smoke-test local model

Browse files
Files changed (1) hide show
  1. api/main.py +21 -0
api/main.py CHANGED
@@ -257,6 +257,27 @@ app.add_middleware(
257
  )
258
 
259
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  @app.get("/health")
261
  async def health():
262
  return {
 
257
  )
258
 
259
 
260
+ @app.get("/debug-inference")
261
+ async def debug_inference():
262
+ """Quick smoke-test: synthesize 0.5s of silence and run a minimal generate() call."""
263
+ import traceback, torch
264
+ if _model is None:
265
+ return {"ok": False, "error": "model not loaded"}
266
+ try:
267
+ import numpy as np
268
+ silence = np.zeros(8000, dtype=np.float32) # 0.5 s @ 16 kHz
269
+ import tempfile, soundfile as sf, asyncio
270
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
271
+ wav_path = f.name
272
+ sf.write(wav_path, silence, 16000)
273
+ loop = asyncio.get_running_loop()
274
+ text = await loop.run_in_executor(None, _transcribe_sync, wav_path)
275
+ import os; os.unlink(wav_path)
276
+ return {"ok": True, "text": text, "dtype": str(_model_dtype), "device": str(_model_device)}
277
+ except Exception as e:
278
+ return {"ok": False, "error": str(e), "traceback": traceback.format_exc()}
279
+
280
+
281
  @app.get("/health")
282
  async def health():
283
  return {