File size: 3,091 Bytes
4534101 a7555f1 0f41375 4534101 1ab4436 6bc5f56 0b30fcb e4e7be6 0b30fcb 0f41375 6bc5f56 e4e7be6 6bc5f56 dc9781b a7555f1 dc9781b a7555f1 dc9781b a7555f1 dc9781b a7555f1 1ab4436 0f41375 1ab4436 fc72d64 a7555f1 1ab4436 c736f26 1ab4436 a7555f1 c736f26 a7555f1 390d754 1ab4436 a7555f1 1ab4436 c736f26 1ab4436 a7555f1 390d754 a7555f1 dc9781b c736f26 1ab4436 a7555f1 0f41375 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | import os
import sys
sys.path.append(os.path.dirname(__file__))
from crew import run_crewai_lifestyle, run_crewai_audio, run_crewai_news_patient, run_crewai_news_doctor
import gradio as gr
# ================================================================
# Runs the respective crew for each of the 4 functions
# ================================================================
def assess_lifestyle(docID: str):
try:
return run_crewai_lifestyle(docID)
except Exception as e:
return {"status": "error", "message": str(e)}
def assess_audio(docID: str):
try:
return run_crewai_audio(docID)
except Exception as e:
return {"status": "error", "message": str(e)}
def news_patient(count: int = 5):
try:
return run_crewai_news_patient(count=count)
except Exception as e:
return {"status": "error", "message": str(e)}
def news_doctor(count: int = 5):
try:
return run_crewai_news_doctor(count=count)
except Exception as e:
return {"status": "error", "message": str(e)}
# Creates a GUI using gradio to test the functions above
with gr.Blocks() as demo:
# Page title
gr.Markdown("# 🧠 NMS Dementia Risk Assessment API")
with gr.Tabs():
# ================
# Predictions Tab
# ================
with gr.Tab("Predictions"):
gr.Markdown("### 🔮 Risk Assessment (Lifestyle or Audio)")
mode_pred = gr.Radio(
choices=["lifestyle", "audio"],
value="lifestyle",
label="Assessment Type"
)
doc_id_pred = gr.Textbox(
label="Patient Document ID <umWSG13rLSfHqqJlq1WluPzjLB93>",
placeholder="e.g., umWSG13rLSfHqqJlq1WluPzjLB93"
)
output_pred = gr.JSON()
btn_pred = gr.Button("Run Assessment")
btn_pred.click(
fn=lambda doc_id, mode: assess_lifestyle(doc_id) if mode == "lifestyle" else assess_audio(doc_id),
inputs=[doc_id_pred, mode_pred],
outputs=output_pred,
api_name="assess_risk" # this is where the api endpoint name is defined
)
# ================
# News Tab
# ================
with gr.Tab("News"):
gr.Markdown("### 📰 Dementia News for Different Audiences")
mode_news = gr.Radio(
choices=["patientnews", "doctornews"],
value="patientnews",
label="News Audience"
)
output_news = gr.JSON()
btn_news = gr.Button("Fetch News")
btn_news.click(
fn=lambda mode, count: (
news_patient(int(count)) if mode == "patientnews" else news_doctor(int(count))
),
inputs=[mode_news, gr.Number(value=5, label="Number of articles", minimum=1, maximum=10)],
outputs=output_news,
api_name="get_news" # this is where the api endpoint name is defined
)
demo.launch() |