Spaces:
Sleeping
Sleeping
File size: 2,061 Bytes
3e74825 dcea53e 3e74825 dcea53e 3e74825 d74c5e6 3e74825 |
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 |
# ==============================
# π©Ί 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() |