Spaces:
Sleeping
Sleeping
Commit ·
87327b9
1
Parent(s): b1f36e3
fix: export single ASGI app for Hugging Face supervisor on ZeroGPU
Browse files
README.md
CHANGED
|
@@ -6,7 +6,6 @@ colorTo: blue
|
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.16.0
|
| 8 |
app_file: app.py
|
| 9 |
-
app_port: 7860
|
| 10 |
pinned: false
|
| 11 |
---
|
| 12 |
|
|
|
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.16.0
|
| 8 |
app_file: app.py
|
|
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
app.py
CHANGED
|
@@ -1,25 +1,41 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from backend.app.main import app as fastapi_app
|
| 6 |
from backend.app.ml.manager import model_manager
|
| 7 |
|
| 8 |
# 1. ZeroGPU Inference Function
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# 2. Gradio Interface (Provides the @spaces.GPU
|
| 23 |
with gr.Blocks(title="SanjeevaniAI Healthcare Intelligence") as demo:
|
| 24 |
gr.Markdown("# 🏥 SanjeevaniAI — Healthcare Intelligence Engine")
|
| 25 |
gr.Markdown(
|
|
@@ -34,9 +50,6 @@ with gr.Blocks(title="SanjeevaniAI Healthcare Intelligence") as demo:
|
|
| 34 |
btn = gr.Button("⚡ Run ZeroGPU Clinical NER", variant="primary")
|
| 35 |
btn.click(fn=predict_ner, inputs=inp, outputs=out)
|
| 36 |
|
| 37 |
-
# 3. Mount Gradio under /
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
if __name__ == "__main__":
|
| 41 |
-
port = int(os.environ.get("PORT", 7860))
|
| 42 |
-
uvicorn.run(app, host="0.0.0.0", port=port)
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
import spaces
|
| 3 |
+
has_spaces = True
|
| 4 |
+
except ImportError:
|
| 5 |
+
has_spaces = False
|
| 6 |
+
|
| 7 |
import gradio as gr
|
| 8 |
from backend.app.main import app as fastapi_app
|
| 9 |
from backend.app.ml.manager import model_manager
|
| 10 |
|
| 11 |
# 1. ZeroGPU Inference Function
|
| 12 |
+
if has_spaces:
|
| 13 |
+
@spaces.GPU
|
| 14 |
+
def predict_ner(text: str):
|
| 15 |
+
if not text or not text.strip():
|
| 16 |
+
return "Please provide clinical text."
|
| 17 |
+
try:
|
| 18 |
+
model = model_manager.get_ner_model()
|
| 19 |
+
results = model.predict(text)
|
| 20 |
+
if not results:
|
| 21 |
+
return "No biomedical entities detected."
|
| 22 |
+
return "\n".join([f"• [{e.label}] {e.text} (Confidence: {round((e.confidence or 1.0)*100, 1)}%)" for e in results])
|
| 23 |
+
except Exception as e:
|
| 24 |
+
return f"Inference notice: {e}"
|
| 25 |
+
else:
|
| 26 |
+
def predict_ner(text: str):
|
| 27 |
+
if not text or not text.strip():
|
| 28 |
+
return "Please provide clinical text."
|
| 29 |
+
try:
|
| 30 |
+
model = model_manager.get_ner_model()
|
| 31 |
+
results = model.predict(text)
|
| 32 |
+
if not results:
|
| 33 |
+
return "No biomedical entities detected."
|
| 34 |
+
return "\n".join([f"• [{e.label}] {e.text} (Confidence: {round((e.confidence or 1.0)*100, 1)}%)" for e in results])
|
| 35 |
+
except Exception as e:
|
| 36 |
+
return f"Inference notice: {e}"
|
| 37 |
|
| 38 |
+
# 2. Gradio Interface (Provides the @spaces.GPU hook for ZeroGPU supervisor)
|
| 39 |
with gr.Blocks(title="SanjeevaniAI Healthcare Intelligence") as demo:
|
| 40 |
gr.Markdown("# 🏥 SanjeevaniAI — Healthcare Intelligence Engine")
|
| 41 |
gr.Markdown(
|
|
|
|
| 50 |
btn = gr.Button("⚡ Run ZeroGPU Clinical NER", variant="primary")
|
| 51 |
btn.click(fn=predict_ner, inputs=inp, outputs=out)
|
| 52 |
|
| 53 |
+
# 3. Mount Gradio under /gradio so FastAPI controls root / and /api/v1/ with ZERO SvelteKit interference
|
| 54 |
+
# Hugging Face's supervisor (Process [1]) automatically serves this exported `app` on port 7860!
|
| 55 |
+
app = gr.mount_gradio_app(fastapi_app, demo, path="/gradio")
|
|
|
|
|
|
|
|
|