turtle170 commited on
Commit
3f10aeb
·
verified ·
1 Parent(s): e00bc88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py CHANGED
@@ -214,6 +214,26 @@ def get_cache_stats() -> str:
214
  "error": str(e)
215
  }, indent=2)
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  # ============================================================================
218
  # GRADIO INTERFACE
219
  # ============================================================================
@@ -292,6 +312,13 @@ with gr.Blocks(title="ZeroEngine-Backend", theme=gr.themes.Monochrome()) as demo
292
  stats_output = gr.Code(label="Statistics (JSON)", language="json")
293
 
294
  stats_btn.click(get_cache_stats, None, [stats_output])
 
 
 
 
 
 
 
295
 
296
  if __name__ == "__main__":
297
  demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
 
214
  "error": str(e)
215
  }, indent=2)
216
 
217
+ def get_backend_health() -> str:
218
+ """
219
+ Get backend health status for monitoring
220
+ """
221
+ try:
222
+ return json.dumps({
223
+ "success": True,
224
+ "status": "healthy",
225
+ "cache_size": len(prompt_cache) + len(response_cache),
226
+ "users_tracked": len(token_ledger),
227
+ "total_requests": sum(u["requests"] for u in token_ledger.values()),
228
+ "timestamp": time.time()
229
+ }, indent=2)
230
+
231
+ except Exception as e:
232
+ return json.dumps({
233
+ "success": False,
234
+ "error": str(e)
235
+ }, indent=2)
236
+
237
  # ============================================================================
238
  # GRADIO INTERFACE
239
  # ============================================================================
 
312
  stats_output = gr.Code(label="Statistics (JSON)", language="json")
313
 
314
  stats_btn.click(get_cache_stats, None, [stats_output])
315
+
316
+ with gr.Tab("🏥 Health"):
317
+ gr.Markdown("### Backend Health Status")
318
+ health_btn = gr.Button("Check Health", variant="primary")
319
+ health_output = gr.Code(label="Health Status (JSON)", language="json")
320
+
321
+ health_btn.click(get_backend_health, None, [health_output])
322
 
323
  if __name__ == "__main__":
324
  demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)