Astral.AI / app.py
SilverDragon9's picture
Update app.py
3e74825 verified
# ==============================
# 🩺 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()