Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,53 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 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 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 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()
|