Spaces:
Sleeping
Sleeping
| # ============================== | |
| # π©Ί Pediatric Respiratory Triage Assistant (Gradio App) | |
| # ============================== | |
| import gradio as gr | |
| import joblib | |
| import os | |
| # ------------------------------ | |
| # π¦ Load Trained Model | |
| # ------------------------------ | |
| MODEL_PATH = "best_model_decision_tree.joblib" | |
| if not os.path.exists(MODEL_PATH): | |
| raise FileNotFoundError(f"Model file not found: {MODEL_PATH}") | |
| model = joblib.load(MODEL_PATH) | |
| # ------------------------------ | |
| # π¬ Triage Prediction Function | |
| # ------------------------------ | |
| def triage_chatbot(symptom_text): | |
| if not symptom_text or len(symptom_text.strip()) < 5: | |
| return "β οΈ Please provide more detailed symptoms." | |
| prediction = model.predict([symptom_text])[0] # already returns string label | |
| # Friendly message mapping | |
| messages = { | |
| "Monitor at Home": "π’ Symptoms appear mild. It's okay to monitor at home unless they worsen.", | |
| "Consult GP": "π‘ Please consult your GP. These symptoms may require medical evaluation.", | |
| "Use Inhaler": "π« Consider using a prescribed inhaler if applicable. Monitor response closely.", | |
| "Visit Emergency": "π΄ Seek emergency care immediately. These symptoms may be serious." | |
| } | |
| return messages.get(prediction, f"Triage Result: {prediction}") | |
| # ------------------------------ | |
| # π¨ Gradio Interface | |
| # ------------------------------ | |
| interface = gr.Interface( | |
| fn=triage_chatbot, | |
| inputs=gr.Textbox( | |
| label="Describe your child's symptoms", | |
| placeholder="e.g. My child is wheezing after running outside...", | |
| lines=4 | |
| ), | |
| outputs=gr.Textbox(label="Triage Recommendation"), | |
| title="π©Ί Pediatric Respiratory Triage Assistant", | |
| description="This AI assistant offers non-diagnostic guidance based on described respiratory symptoms. Always consult a doctor for professional care.", | |
| allow_flagging="never" | |
| ) | |
| # ------------------------------ | |
| # π Launch App | |
| # ------------------------------ | |
| if __name__ == "__main__": | |
| interface.launch() |