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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -1
app.py CHANGED
@@ -238,7 +238,10 @@ def get_backend_health() -> str:
238
  # GRADIO INTERFACE
239
  # ============================================================================
240
 
241
- with gr.Blocks(title="ZeroEngine-Backend", theme=gr.themes.Monochrome()) as demo:
 
 
 
242
  gr.HTML("""
243
  <div style='text-align: center; padding: 20px;'>
244
  <h1>🔧 ZeroEngine-Backend</h1>
@@ -321,4 +324,30 @@ with gr.Blocks(title="ZeroEngine-Backend", theme=gr.themes.Monochrome()) as demo
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)
 
238
  # GRADIO INTERFACE
239
  # ============================================================================
240
 
241
+ with gr.Blocks(title="ZeroEngine-Backend") as demo:
242
+ # Apply theme after Blocks creation for Gradio 6.5.0 compatibility
243
+ if hasattr(demo, 'theme'):
244
+ demo.theme = gr.themes.Monochrome()
245
  gr.HTML("""
246
  <div style='text-align: center; padding: 20px;'>
247
  <h1>🔧 ZeroEngine-Backend</h1>
 
324
  health_btn.click(get_backend_health, None, [health_output])
325
 
326
  if __name__ == "__main__":
327
+ import atexit
328
+ import signal
329
+
330
+ def cleanup_on_exit():
331
+ """Cleanup function called on application exit"""
332
+ print("[CLEANUP] Backend shutting down...")
333
+ # Clear caches
334
+ global prompt_cache, response_cache, token_ledger
335
+ prompt_cache.clear()
336
+ response_cache.clear()
337
+ token_ledger.clear()
338
+ print("[CLEANUP] Backend shutdown complete")
339
+
340
+ # Register cleanup functions
341
+ atexit.register(cleanup_on_exit)
342
+
343
+ def signal_handler(signum, frame):
344
+ """Handle shutdown signals gracefully"""
345
+ print(f"[CLEANUP] Received signal {signum}")
346
+ cleanup_on_exit()
347
+ import sys
348
+ sys.exit(0)
349
+
350
+ signal.signal(signal.SIGTERM, signal_handler)
351
+ signal.signal(signal.SIGINT, signal_handler)
352
+
353
  demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)