plutoa386 commited on
Commit
0f41375
·
1 Parent(s): ee5d5e6

fixed incorect sdk issues

Browse files
Files changed (1) hide show
  1. app.py +21 -33
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
- # Import your existing crew logic
11
- from crew import crew, placeholder_lifestyle_ID
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
- @app.get("/health")
23
- def health():
24
- return {"status": "ok"}
25
-
26
- @app.post("/run/lifestyle")
27
- def run_lifestyle_crew(request: LifestyleRequest):
28
  """
29
- Runs the CrewAI pipeline for lifestyle-based dementia risk assessment.
30
- Uses the provided docID.
31
  """
32
- try:
33
- # Temporarily override the task description to use the provided docID
34
- from crew import risk_assessment_task_lifestyle
35
- risk_assessment_task_lifestyle.description = f"Calculate dementia risk for patient using the given patient id: {request.docID}"
36
-
37
- # Run crew
38
- result = crew.kickoff()
39
- return {"result": str(result)}
40
- except Exception as e:
41
- raise HTTPException(status_code=500, detail=f"Crew execution failed: {str(e)}")
 
 
 
 
 
 
 
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()