rihancloud commited on
Commit
2ef9bf1
Β·
1 Parent(s): 7a29207

Fix asyncio loop cleanup warning and launch cleanly

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -1,8 +1,17 @@
1
  import sys
2
  import subprocess
3
  import importlib
 
4
 
5
- # πŸš€ 1. Self-Healing Auto-Installer: Catches any missing library, installs it, and retries!
 
 
 
 
 
 
 
 
6
  while True:
7
  try:
8
  from main import app as fastapi_app
@@ -33,7 +42,7 @@ while True:
33
  import gradio as gr
34
  import spaces
35
 
36
- # πŸš€ 2. Crucial for ZeroGPU: Tells Hugging Face this Space is an active GPU worker!
37
  @spaces.GPU
38
  def zero_gpu_keepalive():
39
  return "GPU Active"
@@ -45,9 +54,9 @@ with gr.Blocks(title="Tools Backend API") as demo:
45
  gr.Markdown("- **Interactive Swagger Docs:** [/docs](/docs)")
46
  gr.Markdown("- **Health Check:** [/health](/health)")
47
 
48
- # πŸš€ 4. Mount all your FastAPI endpoints directly into Gradio
49
  demo.app.include_router(fastapi_app.router)
50
 
51
- # πŸš€ 5. Launch without Node SSR
52
  if __name__ == "__main__":
53
- demo.launch(ssr_mode=False)
 
1
  import sys
2
  import subprocess
3
  import importlib
4
+ import asyncio
5
 
6
+ # πŸ›‘οΈ Fix the "Exception ignored in BaseEventLoop.__del__" warning
7
+ if sys.platform != "win32":
8
+ try:
9
+ import selectors
10
+ asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
11
+ except Exception:
12
+ pass
13
+
14
+ # πŸš€ 1. Self-Healing Auto-Installer
15
  while True:
16
  try:
17
  from main import app as fastapi_app
 
42
  import gradio as gr
43
  import spaces
44
 
45
+ # πŸš€ 2. ZeroGPU Worker Anchor
46
  @spaces.GPU
47
  def zero_gpu_keepalive():
48
  return "GPU Active"
 
54
  gr.Markdown("- **Interactive Swagger Docs:** [/docs](/docs)")
55
  gr.Markdown("- **Health Check:** [/health](/health)")
56
 
57
+ # πŸš€ 4. Mount all FastAPI endpoints
58
  demo.app.include_router(fastapi_app.router)
59
 
60
+ # πŸš€ 5. Launch cleanly
61
  if __name__ == "__main__":
62
+ demo.launch(ssr_mode=False, server_name="0.0.0.0", server_port=7860)