Spaces:
Runtime error
Runtime error
Commit Β·
2ef9bf1
1
Parent(s): 7a29207
Fix asyncio loop cleanup warning and launch cleanly
Browse files
app.py
CHANGED
|
@@ -1,8 +1,17 @@
|
|
| 1 |
import sys
|
| 2 |
import subprocess
|
| 3 |
import importlib
|
|
|
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|
| 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
|
| 49 |
demo.app.include_router(fastapi_app.router)
|
| 50 |
|
| 51 |
-
# π 5. Launch
|
| 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)
|