Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,71 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from PIL import Image, ImageDraw
|
| 3 |
-
import os
|
| 4 |
-
import uuid
|
| 5 |
-
import logging
|
| 6 |
import joblib
|
|
|
|
| 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 |
-
border-radius: 5px;
|
| 57 |
-
}
|
| 58 |
-
"""
|
| 59 |
-
|
| 60 |
-
# βββββ UI βββββ #
|
| 61 |
-
with gr.Blocks(css=cyber_light_css) as demo:
|
| 62 |
-
gr.Markdown("## π Cyberpunk T2I Generator (Light Mode)")
|
| 63 |
-
prompt = gr.Textbox(label="Describe your neon dream π")
|
| 64 |
-
generate = gr.Button("β‘ Generate")
|
| 65 |
-
output_img = gr.Image()
|
| 66 |
-
download = gr.File(label="Download")
|
| 67 |
-
|
| 68 |
-
generate.click(fn=predict, inputs=prompt, outputs=[output_img, download])
|
| 69 |
-
|
| 70 |
if __name__ == "__main__":
|
| 71 |
-
|
|
|
|
| 1 |
+
# ==============================
|
| 2 |
+
# π©Ί Pediatric Respiratory Triage Assistant (Gradio App)
|
| 3 |
+
# ==============================
|
| 4 |
+
|
| 5 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import joblib
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
+
# ------------------------------
|
| 10 |
+
# π¦ Load Trained Model
|
| 11 |
+
# ------------------------------
|
| 12 |
+
MODEL_PATH = "best_model_decision_tree.joblib"
|
| 13 |
+
|
| 14 |
+
if not os.path.exists(MODEL_PATH):
|
| 15 |
+
raise FileNotFoundError(f"Model file not found: {MODEL_PATH}")
|
| 16 |
+
|
| 17 |
+
model = joblib.load(MODEL_PATH)
|
| 18 |
+
|
| 19 |
+
# ------------------------------
|
| 20 |
+
# π¬ Triage Prediction Function
|
| 21 |
+
# ------------------------------
|
| 22 |
+
def triage_chatbot(symptom_text):
|
| 23 |
+
if not symptom_text or len(symptom_text.strip()) < 5:
|
| 24 |
+
return "β οΈ Please provide more detailed symptoms."
|
| 25 |
+
|
| 26 |
+
prediction = model.predict([symptom_text])[0] # already returns string label
|
| 27 |
+
|
| 28 |
+
# Friendly message mapping
|
| 29 |
+
messages = {
|
| 30 |
+
"Monitor at Home": "π’ Symptoms appear mild. It's okay to monitor at home unless they worsen.",
|
| 31 |
+
"Consult GP": "π‘ Please consult your GP. These symptoms may require medical evaluation.",
|
| 32 |
+
"Use Inhaler": "π« Consider using a prescribed inhaler if applicable. Monitor response closely.",
|
| 33 |
+
"Visit Emergency": "π΄ Seek emergency care immediately. These symptoms may be serious."
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
return messages.get(prediction, f"Triage Result: {prediction}")
|
| 37 |
+
|
| 38 |
+
# ------------------------------
|
| 39 |
+
# π¨ Gradio Interface
|
| 40 |
+
# ------------------------------
|
| 41 |
+
interface = gr.Interface(
|
| 42 |
+
fn=triage_chatbot,
|
| 43 |
+
inputs=gr.Textbox(
|
| 44 |
+
label="Describe your child's symptoms",
|
| 45 |
+
placeholder="e.g. My child is wheezing after running outside...",
|
| 46 |
+
lines=4
|
| 47 |
+
),
|
| 48 |
+
outputs=gr.Textbox(label="Triage Recommendation"),
|
| 49 |
+
title="π©Ί Pediatric Respiratory Triage Assistant",
|
| 50 |
+
description="This AI assistant offers non-diagnostic guidance based on described respiratory symptoms. Always consult a doctor for professional care.",
|
| 51 |
+
allow_flagging="never"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# ------------------------------
|
| 55 |
+
# π Launch App
|
| 56 |
+
# ------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if __name__ == "__main__":
|
| 58 |
+
interface.launch()
|