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 - Development Zone") 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 ", 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()