SilverDragon9 commited on
Commit
3e74825
Β·
verified Β·
1 Parent(s): 6ef3377

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -67
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
- # ───── Configuration ───── #
9
- OUTPUT_DIR = "outputs"
10
- MODEL_PATH = "model_assets/model.pkl"
11
- os.makedirs(OUTPUT_DIR, exist_ok=True)
12
- logging.basicConfig(level=logging.INFO)
13
- logger = logging.getLogger(__name__)
14
-
15
- # ───── Dummy Generator ───── #
16
- def generate_image_from_text(prompt, model=None):
17
- image = Image.new("RGB", (512, 512), color="white")
18
- draw = ImageDraw.Draw(image)
19
- draw.text((10, 250), prompt, fill="#ff00cc")
20
- return image
21
-
22
- # ───── Load Model ───── #
23
- def load_model():
24
- try:
25
- return joblib.load(MODEL_PATH) if os.path.exists(MODEL_PATH) else None
26
- except Exception as e:
27
- logger.error(f"Model load error: {e}")
28
- return None
29
-
30
- model = load_model()
31
-
32
- # ───── Prediction Logic ───── #
33
- def predict(prompt):
34
- try:
35
- image = generate_image_from_text(prompt, model)
36
- image_id = str(uuid.uuid4())
37
- output_path = os.path.join(OUTPUT_DIR, f"{image_id}.png")
38
- image.save(output_path)
39
- return image, output_path
40
- except Exception as e:
41
- logger.error(f"Prediction error: {e}")
42
- return None, None
43
-
44
- # ───── CSS ───── #
45
- cyber_light_css = """
46
- .gradio-container {
47
- background: linear-gradient(135deg, #f0f0f0, #fafafa);
48
- color: #ff00cc;
49
- font-family: 'Orbitron', sans-serif;
50
- }
51
- button, input, .gr-button {
52
- background-color: #ffffff;
53
- color: #ff00cc;
54
- border: 2px solid #ff00cc;
55
- font-weight: bold;
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
- demo.launch()
 
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()