Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from app.main import app as fastapi_app
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
def _hf_zero_gpu_probe():
|
| 10 |
-
return "ok"
|
| 11 |
-
except ImportError:
|
| 12 |
-
pass # Safe fallback for local testing
|
| 13 |
|
| 14 |
-
#
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
gr.Markdown("# 🛡️ Moderation API")
|
| 17 |
gr.Markdown("This is a live API. Send POST requests to `/api/v1/moderate`.")
|
| 18 |
gr.Markdown("You can view the interactive API docs at [here](/docs) once it starts.")
|
| 19 |
|
| 20 |
-
#
|
| 21 |
app = gr.mount_gradio_app(fastapi_app, demo, path="/")
|
|
|
|
| 1 |
+
# 1. CRITICAL: Import spaces FIRST, before any CUDA-related packages
|
| 2 |
+
import spaces
|
| 3 |
+
|
| 4 |
+
# 2. Now it is safe to import other libraries
|
| 5 |
import gradio as gr
|
| 6 |
from fastapi import FastAPI
|
| 7 |
from app.main import app as fastapi_app
|
| 8 |
|
| 9 |
+
# 3. Dummy GPU probe function to satisfy ZeroGPU's startup check
|
| 10 |
+
@spaces.GPU
|
| 11 |
+
def _hf_zero_gpu_probe():
|
| 12 |
+
return "ok"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# 4. Your Gradio wrapper
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
gr.Markdown("# 🛡️ Moderation API")
|
| 17 |
gr.Markdown("This is a live API. Send POST requests to `/api/v1/moderate`.")
|
| 18 |
gr.Markdown("You can view the interactive API docs at [here](/docs) once it starts.")
|
| 19 |
|
| 20 |
+
# 5. Mount FastAPI onto Gradio
|
| 21 |
app = gr.mount_gradio_app(fastapi_app, demo, path="/")
|