Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
from virtualhealth import handle_user_query, book_appointment # Import functions
|
4 |
+
|
5 |
+
st.set_page_config(page_title="AI Health Assistant", page_icon="🩺")
|
6 |
+
|
7 |
+
st.title("🩺 AI Health Assistant")
|
8 |
+
st.write("Ask any medical-related questions below:")
|
9 |
+
|
10 |
+
# Predefined responses for common medical queries
|
11 |
+
basic_queries = {
|
12 |
+
"what is diabetes": "Diabetes is a chronic disease that affects how your body turns food into energy.",
|
13 |
+
"what are the symptoms of flu": "Common flu symptoms include fever, cough, sore throat, and body aches.",
|
14 |
+
"how to reduce fever": "Drink plenty of fluids, rest, and take fever-reducing medications like paracetamol.",
|
15 |
+
"what is hypertension": "Hypertension, or high blood pressure, is when the force of blood against your artery walls is too high.",
|
16 |
+
}
|
17 |
+
|
18 |
+
# Symptom-Based Advice
|
19 |
+
symptom_advice = {
|
20 |
+
"i have a fever": "Drink fluids, rest, and take paracetamol if needed. If fever persists for more than 3 days, consult a doctor.",
|
21 |
+
"i feel feverish": "Monitor your temperature, drink water, and rest. If it gets worse, see a doctor.",
|
22 |
+
"i have a cough": "Stay hydrated, avoid cold drinks, and try honey with warm water. If severe, consult a doctor.",
|
23 |
+
"i have a headache": "Rest, drink water, and try a mild pain reliever if necessary. Persistent headaches need medical attention.",
|
24 |
+
"i feel dizzy": "Sit down, drink water, and take deep breaths. If dizziness continues, consult a doctor.",
|
25 |
+
"i have stomach pain": "Avoid spicy food, drink warm water, and rest. Severe pain may require a doctor's check-up.",
|
26 |
+
}
|
27 |
+
|
28 |
+
# Critical Symptoms Mapping
|
29 |
+
critical_symptoms = {
|
30 |
+
"I feel heart pain": "Cardiologist",
|
31 |
+
"I have chest pain and shortness of breath": "Cardiologist",
|
32 |
+
"I am experiencing severe headache and dizziness": "Neurologist",
|
33 |
+
"I have slurred speech and numbness on one side": "Neurologist",
|
34 |
+
"I have severe abdominal pain and vomiting blood": "General Physician",
|
35 |
+
}
|
36 |
+
|
37 |
+
# Appointment Booking Data
|
38 |
+
doctor_specialties = {
|
39 |
+
"General Physician": {"doctor": "Dr. Smith", "available_slots": ["2025-03-10 10:00:00", "2025-03-11 14:00:00"]},
|
40 |
+
"Cardiologist": {"doctor": "Dr. Johnson", "available_slots": ["2025-03-12 09:30:00"]},
|
41 |
+
"Dermatologist": {"doctor": "Dr. Lee", "available_slots": ["2025-03-10 11:00:00", "2025-03-11 15:00:00"]},
|
42 |
+
"Neurologist": {"doctor": "Dr. Brown", "available_slots": ["2025-03-13 11:00:00"]},
|
43 |
+
"Pediatrician": {"doctor": "Dr. Wilson", "available_slots": ["2025-03-14 10:00:00"]},
|
44 |
+
"Dentist": {"doctor": "Dr. Davis", "available_slots": ["2025-03-15 12:00:00"]},
|
45 |
+
}
|
46 |
+
|
47 |
+
# User Input
|
48 |
+
user_input = st.text_input("Your Question or Symptoms:")
|
49 |
+
|
50 |
+
if st.button("Ask", key="ask_button"):
|
51 |
+
user_input_lower = user_input.lower().strip()
|
52 |
+
|
53 |
+
# Check if the query matches predefined questions
|
54 |
+
if user_input_lower in basic_queries:
|
55 |
+
st.markdown(f"**🤖 Bot:** {basic_queries[user_input_lower]}")
|
56 |
+
|
57 |
+
# Check if the input matches known symptoms
|
58 |
+
elif user_input_lower in symptom_advice:
|
59 |
+
st.markdown(f"**🩺 Health Advice:** {symptom_advice[user_input_lower]}")
|
60 |
+
|
61 |
+
# Check if it's a critical symptom
|
62 |
+
elif user_input in critical_symptoms:
|
63 |
+
specialty = critical_symptoms[user_input]
|
64 |
+
st.warning(f"🚨 This may be a serious condition! Consider consulting a {specialty}.")
|
65 |
+
|
66 |
+
# Otherwise, use AI response
|
67 |
+
else:
|
68 |
+
bot_response = handle_user_query(user_input)
|
69 |
+
st.markdown(f"**🤖 Bot:** {bot_response}")
|
70 |
+
|
71 |
+
# Doctor Appointment Booking
|
72 |
+
st.subheader("📅 Book a Doctor's Appointment")
|
73 |
+
|
74 |
+
selected_specialty = st.selectbox("Select Doctor Specialty", list(doctor_specialties.keys()))
|
75 |
+
appt_date = st.date_input("Select Appointment Date")
|
76 |
+
appt_time = st.time_input("Select Appointment Time")
|
77 |
+
|
78 |
+
if st.button("Book Appointment"):
|
79 |
+
doctor_info = doctor_specialties[selected_specialty]
|
80 |
+
doctor_name = doctor_info["doctor"]
|
81 |
+
requested_slot = f"{appt_date} {appt_time}"
|
82 |
+
|
83 |
+
if requested_slot in doctor_info["available_slots"]:
|
84 |
+
booking_details = f"{selected_specialty} (Dr. {doctor_name}) on {requested_slot}"
|
85 |
+
book_appointment(booking_details)
|
86 |
+
st.success(f"✅ Appointment confirmed with {doctor_name} on {requested_slot}.")
|
87 |
+
else:
|
88 |
+
nearest_slot = doctor_info["available_slots"][0]
|
89 |
+
st.error(f"❌ No available doctors at that time. Nearest available slot: {nearest_slot} with {doctor_name}.")
|