Spaces:
Runtime error
Runtime error
fixed incorect sdk issues
Browse files
app.py
CHANGED
|
@@ -1,41 +1,29 @@
|
|
| 1 |
# app.py
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
-
from fastapi import FastAPI, HTTPException
|
| 5 |
-
from pydantic import BaseModel
|
| 6 |
-
|
| 7 |
-
# Add current dir to path so we can import crew
|
| 8 |
sys.path.append(os.path.dirname(__file__))
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
app = FastAPI(
|
| 14 |
-
title="Dementia Risk Assessment API",
|
| 15 |
-
description="Backend for crewAI-based dementia risk assessment using lifestyle and audio models.",
|
| 16 |
-
version="1.0"
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
class LifestyleRequest(BaseModel):
|
| 20 |
-
docID: str = placeholder_lifestyle_ID
|
| 21 |
|
| 22 |
-
|
| 23 |
-
def health():
|
| 24 |
-
return {"status": "ok"}
|
| 25 |
-
|
| 26 |
-
@app.post("/run/lifestyle")
|
| 27 |
-
def run_lifestyle_crew(request: LifestyleRequest):
|
| 28 |
"""
|
| 29 |
-
|
| 30 |
-
|
| 31 |
"""
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# app.py
|
| 2 |
import os
|
| 3 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
sys.path.append(os.path.dirname(__file__))
|
| 5 |
|
| 6 |
+
from crew import calculate_dementia_risk_lifestyle
|
| 7 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
def assess_risk(docID: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
"""
|
| 11 |
+
Gradio-compatible function that wraps your existing tool.
|
| 12 |
+
Returns a dictionary for JSON output.
|
| 13 |
"""
|
| 14 |
+
result = calculate_dementia_risk_lifestyle(docID)
|
| 15 |
+
if result.startswith("Error"):
|
| 16 |
+
return {"status": "error", "message": result}
|
| 17 |
+
else:
|
| 18 |
+
return {"status": "success", "report": result}
|
| 19 |
+
|
| 20 |
+
# Define Gradio interface
|
| 21 |
+
with gr.Blocks() as demo:
|
| 22 |
+
gr.Markdown("# 🧠 NMS Dementia Risk API (Lifestyle)")
|
| 23 |
+
gr.Markdown("Backend for mobile/web app. Use `/run/predict` to call this endpoint.")
|
| 24 |
+
doc_id = gr.Textbox(label="Document ID", placeholder="e.g., 265e9lboNaBH9bQE0CHR")
|
| 25 |
+
output = gr.JSON()
|
| 26 |
+
btn = gr.Button("Assess Risk")
|
| 27 |
+
btn.click(fn=assess_risk, inputs=doc_id, outputs=output)
|
| 28 |
+
|
| 29 |
+
demo.launch()
|