VaneshDev commited on
Commit
85f95e2
Β·
verified Β·
1 Parent(s): b60e319

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -63
app.py CHANGED
@@ -1,69 +1,53 @@
1
  import gradio as gr
2
 
3
- # Function to provide health advice based on input
4
- def health_bot(text):
5
- text = text.lower()
 
 
 
 
 
 
 
6
 
7
- if any(word in text for word in ["fever", "temperature", "high temp"]):
8
- return (
9
- "🩺 **Fever Advice**\n"
10
- "- Take Paracetamol (500mg every 4–6 hours)\n"
11
- "- Drink water and rest\n"
12
- "- Use cold compresses\n"
13
- "- See a doctor if it lasts >3 days"
14
- )
15
- elif any(word in text for word in ["cold", "cough", "sneeze", "blocked nose"]):
16
- return (
17
- "🀧 **Cold & Cough Advice**\n"
18
- "- Use Cetirizine or decongestants\n"
19
- "- Drink warm fluids\n"
20
- "- Steam inhalation helps\n"
21
- "- Rest well"
22
- )
23
- elif "headache" in text:
24
- return (
25
- "πŸ’† **Headache Advice**\n"
26
- "- Take Ibuprofen or Paracetamol\n"
27
- "- Rest in a quiet, dark room\n"
28
- "- Avoid screens and loud noise"
29
- )
30
- elif any(word in text for word in ["stomach", "abdominal", "gas", "cramps"]):
31
- return (
32
- "🍽️ **Stomach Pain Advice**\n"
33
- "- Use antacids or simethicone\n"
34
- "- Drink warm water\n"
35
- "- Avoid oily/spicy food\n"
36
- "- If pain is sharp or lasts long, consult a doctor"
37
- )
38
- elif any(word in text for word in ["throat", "sore throat", "hoarse"]):
39
- return (
40
- "πŸ—£οΈ **Sore Throat Advice**\n"
41
- "- Warm salt water gargle\n"
42
- "- Drink warm tea with honey\n"
43
- "- Lozenges or throat spray\n"
44
- "- See a doctor if pain is severe"
45
- )
46
- elif any(word in text for word in ["diarrhea", "loose motion"]):
47
- return (
48
- "🚽 **Diarrhea Advice**\n"
49
- "- Take ORS (oral rehydration salts)\n"
50
- "- Avoid dairy and oily food\n"
51
- "- Use Loperamide if needed\n"
52
- "- Stay hydrated"
53
- )
54
- else:
55
- return (
56
- "❓ Sorry, I don't have advice for that yet.\n"
57
- "Try asking about: fever, cold, cough, headache, stomach pain, sore throat, diarrhea."
58
- )
59
 
60
- # Gradio UI
61
- demo = gr.Interface(
62
- fn=health_bot,
63
- inputs=gr.Textbox(label="Ask your health question"),
64
- outputs=gr.Markdown(label="Advice"),
65
- title="🧠 Smart Health Advisor",
66
- description="Ask about common issues: fever, cold, stomach pain, etc. Get quick, simple advice. Not a substitute for a real doctor!"
67
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ def get_health_advice(query):
4
+ responses = {
5
+ "fever": "🌑️ For fever, take Paracetamol, rest well, and stay hydrated.",
6
+ "cold": "🀧 Use steam inhalation, warm fluids, and over-the-counter cold medicine.",
7
+ "headache": "πŸ’Š Try Ibuprofen, stay in a quiet place, and drink plenty of water.",
8
+ }
9
+ for keyword in responses:
10
+ if keyword in query.lower():
11
+ return responses[keyword]
12
+ return "⚠️ Sorry, I couldn't recognize your condition. Please consult a healthcare professional."
13
 
14
+ with gr.Blocks(css="""
15
+ .gradio-container { background-color: #f4f9ff; font-family: 'Segoe UI', sans-serif; }
16
+ h1 { color: #1e88e5; text-align: center; margin-bottom: 0; }
17
+ h2 { color: #333; text-align: center; font-weight: normal; margin-top: 0; }
18
+ .textbox input, .textbox textarea {
19
+ font-size: 16px; padding: 12px; border-radius: 10px; border: 1px solid #ccc;
20
+ }
21
+ .response-box textarea {
22
+ background-color: #e3f2fd; font-size: 16px; padding: 12px; border-radius: 10px;
23
+ border: 1px solid #90caf9;
24
+ }
25
+ .submit-btn button {
26
+ background-color: #1e88e5; color: white; font-size: 16px; border-radius: 10px; padding: 10px 24px;
27
+ }
28
+ .submit-btn button:hover { background-color: #1565c0; }
29
+ """) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ gr.Markdown("## 🩺 MedicGuide")
32
+ gr.Markdown("### Your AI Health Assistant – Ask any health-related question")
33
+
34
+ with gr.Row():
35
+ with gr.Column():
36
+ user_input = gr.Textbox(
37
+ label="Enter your health question:",
38
+ placeholder="e.g., What medicine should I take for cold?",
39
+ lines=3,
40
+ elem_classes="textbox"
41
+ )
42
+ submit_btn = gr.Button("Get Advice", elem_classes="submit-btn")
43
+ with gr.Column():
44
+ output = gr.Textbox(
45
+ label="MedicGuide Advice:",
46
+ lines=3,
47
+ interactive=False,
48
+ elem_classes="response-box"
49
+ )
50
+
51
+ submit_btn.click(fn=get_health_advice, inputs=user_input, outputs=output)
52
 
53
  demo.launch()