Muhammadtaha12 commited on
Commit
95309d0
·
verified ·
1 Parent(s): 978364c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -152
app.py CHANGED
@@ -1,7 +1,5 @@
1
- import streamlit as st
2
-
3
- # Define the healthcare knowledge base with a wider set of diseases and conditions
4
- {
5
  "flu": {
6
  "symptoms": ["fever", "cough", "sore throat", "body aches", "fatigue"],
7
  "treatment": "Rest, fluids, pain relievers, and anti-viral medications if prescribed."
@@ -25,158 +23,72 @@ import streamlit as st
25
  "pneumonia": {
26
  "symptoms": ["cough with mucus", "fever", "shortness of breath", "chest pain"],
27
  "treatment": "Antibiotics for bacterial pneumonia, rest, fluids, and pain relievers."
28
- },
29
- "hypertension": {
30
- "symptoms": ["headaches", "dizziness", "shortness of breath", "nosebleeds"],
31
- "treatment": "Medications like beta-blockers, ACE inhibitors, lifestyle changes including exercise and diet."
32
- },
33
- "anxiety": {
34
- "symptoms": ["excessive worry", "restlessness", "fatigue", "difficulty concentrating", "irritability"],
35
- "treatment": "Cognitive-behavioral therapy (CBT), medications like SSRIs, relaxation techniques."
36
- },
37
- "depression": {
38
- "symptoms": ["persistent sadness", "loss of interest", "fatigue", "changes in appetite or sleep patterns"],
39
- "treatment": "Antidepressants, therapy (CBT), exercise, and social support."
40
- },
41
- "arthritis": {
42
- "symptoms": ["joint pain", "swelling", "stiffness", "reduced range of motion"],
43
- "treatment": "Pain relievers, anti-inflammatory drugs, physical therapy, and joint protection."
44
- },
45
- "covid-19": {
46
- "symptoms": ["fever", "dry cough", "fatigue", "loss of taste or smell", "shortness of breath"],
47
- "treatment": "Rest, fluids, over-the-counter medications, and antiviral drugs if prescribed."
48
- },
49
- "abdominal_aortic_aneurysm": {
50
- "symptoms": ["back pain", "abdominal pain", "pulsating mass in the abdomen"],
51
- "treatment": "Surgical intervention, blood pressure control, and monitoring."
52
- },
53
- "acute_lymphoblastic_leukemia": {
54
- "symptoms": ["fever", "pale skin", "unexplained weight loss", "easy bruising"],
55
- "treatment": "Chemotherapy, bone marrow transplant, and supportive care."
56
- },
57
- "acute_myeloid_leukemia": {
58
- "symptoms": ["fatigue", "fever", "easy bruising or bleeding", "shortness of breath"],
59
- "treatment": "Chemotherapy, stem cell transplant, and supportive care."
60
- },
61
- "acromegaly": {
62
- "symptoms": ["enlarged hands and feet", "joint pain", "thickened skin", "enlarged facial features"],
63
- "treatment": "Surgery, radiation therapy, and medication to control growth hormone production."
64
- },
65
- "actinomycosis": {
66
- "symptoms": ["abscesses", "fever", "painful lumps", "swelling"],
67
- "treatment": "Long-term antibiotics such as penicillin."
68
- },
69
- "acute_renal_failure": {
70
- "symptoms": ["decreased urine output", "fatigue", "swelling in the legs", "confusion"],
71
- "treatment": "Dialysis, fluid management, and treatment of underlying causes."
72
- },
73
- "addisons_disease": {
74
- "symptoms": ["fatigue", "muscle weakness", "low blood pressure", "darkening of the skin"],
75
- "treatment": "Corticosteroid therapy and lifestyle modifications."
76
- },
77
- "adhd": {
78
- "symptoms": ["impulsivity", "difficulty focusing", "hyperactivity", "forgetfulness"],
79
- "treatment": "Stimulant medications, therapy (CBT), and lifestyle management."
80
- },
81
- "aids": {
82
- "symptoms": ["weight loss", "fever", "night sweats", "fatigue", "recurrent infections"],
83
- "treatment": "Antiretroviral therapy (ART) to manage the virus and prevent complications."
84
- },
85
- "albinism": {
86
- "symptoms": ["pale skin", "light-colored eyes", "vision problems", "sensitivity to light"],
87
- "treatment": "UV protection, corrective lenses for vision, and skin protection."
88
- },
89
- "alcoholic_hepatitis": {
90
- "symptoms": ["nausea", "abdominal pain", "yellowing of the skin (jaundice)", "loss of appetite"],
91
- "treatment": "Avoid alcohol, medications to manage symptoms, and possible liver transplant."
92
- },
93
- "alcoholism": {
94
- "symptoms": ["strong cravings for alcohol", "inability to control drinking", "neglect of responsibilities"],
95
- "treatment": "Behavioral therapy, support groups, medications like disulfiram, and rehabilitation."
96
- },
97
- "alkaptonuria": {
98
- "symptoms": ["dark urine", "arthritis", "heart disease", "darkening of the ears or eyes"],
99
- "treatment": "Managing symptoms, physical therapy, and joint replacement if necessary."
100
- },
101
- "allergies": {
102
- "symptoms": ["sneezing", "itchy eyes", "runny nose", "hives", "swelling"],
103
- "treatment": "Antihistamines, decongestants, and avoiding triggers."
104
- },
105
- "alzheimers_disease": {
106
- "symptoms": ["memory loss", "difficulty with tasks", "confusion", "personality changes"],
107
- "treatment": "Cognitive-enhancing drugs, therapy, and support for caregivers."
108
- },
109
- "amyotrophic_lateral_sclerosis": {
110
- "symptoms": ["muscle weakness", "difficulty speaking or swallowing", "breathing problems"],
111
- "treatment": "Symptom management, physical therapy, and breathing support."
112
- },
113
- "anemia": {
114
- "symptoms": ["fatigue", "pale skin", "dizziness", "shortness of breath"],
115
- "treatment": "Iron supplements, B12 injections, or blood transfusions depending on the cause."
116
- },
117
- "aneurysm": {
118
- "symptoms": ["severe headache", "nausea", "blurred vision", "pain in the chest or abdomen"],
119
- "treatment": "Surgical repair, blood pressure control, and monitoring."
120
- },
121
- "angelman_syndrome": {
122
- "symptoms": ["delayed development", "lack of speech", "seizures", "smiling and laughter"],
123
- "treatment": "Physical therapy, speech therapy, and medications for seizures."
124
- },
125
- "anorexia_nervosa": {
126
- "symptoms": ["extreme weight loss", "fear of gaining weight", "distorted body image", "restricted eating"],
127
- "treatment": "Nutritional rehabilitation, psychotherapy, and medical monitoring."
128
- },
129
- "anthrax": {
130
- "symptoms": ["fever", "cough", "chest pain", "difficulty breathing", "swelling"],
131
- "treatment": "Antibiotics and in some cases, vaccination."
132
- },
133
- "antiphospholipid_syndrome": {
134
- "symptoms": ["recurrent miscarriages", "blood clots", "stroke", "rashes"],
135
- "treatment": "Blood thinners and management of clotting disorders."
136
- },
137
- "aortic_stenosis": {
138
- "symptoms": ["chest pain", "shortness of breath", "fatigue", "fainting"],
139
- "treatment": "Surgical valve replacement or balloon valvuloplasty."
140
- },
141
- "aortic_dissection": {
142
- "symptoms": ["severe chest or back pain", "difficulty breathing", "sweating", "loss of consciousness"],
143
- "treatment": "Emergency surgery, blood pressure control, and monitoring."
144
- },
145
- "apraxia": {
146
- "symptoms": ["difficulty planning and coordinating muscle movements", "speech and motor difficulties"],
147
- "treatment": "Speech therapy, physical therapy, and occupational therapy."
148
  }
 
149
  }
150
 
151
-
152
- # Function to search for health information in the knowledge base
153
- def get_health_info(query):
154
- query = query.lower()
155
-
156
- # List to store matching results
157
- matching_conditions = []
158
-
159
- # Search for conditions that match the query
160
- for condition, info in health_knowledge_base.items():
161
- if condition in query or any(symptom in query for symptom in info['symptoms']):
162
- matching_conditions.append(f"Condition: {condition.title()}\n"
163
- f"Symptoms: {', '.join(info['symptoms'])}\n"
164
- f"Treatment: {info['treatment']}\n")
165
-
166
- # If we have matching conditions, return all of them, otherwise return a message
167
- if matching_conditions:
168
- return "\n\n".join(matching_conditions)
169
  else:
170
- return "Sorry, I couldn't find information on that condition. Please try another query."
171
 
172
- # Set up the Streamlit app interface
173
- st.title("Healthcare Knowledge Chatbot")
174
- st.write("Ask me about health conditions, symptoms, treatments, and I'll provide relevant information.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
- # Input field for user queries
177
- user_input = st.text_input("Ask a healthcare-related question...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
- # Display response based on user input
180
- if user_input:
181
- response = get_health_info(user_input)
182
- st.write(response)
 
1
+ # Disease Information Dictionary
2
+ diseases = {
 
 
3
  "flu": {
4
  "symptoms": ["fever", "cough", "sore throat", "body aches", "fatigue"],
5
  "treatment": "Rest, fluids, pain relievers, and anti-viral medications if prescribed."
 
23
  "pneumonia": {
24
  "symptoms": ["cough with mucus", "fever", "shortness of breath", "chest pain"],
25
  "treatment": "Antibiotics for bacterial pneumonia, rest, fluids, and pain relievers."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
+ # Add more diseases here if needed
28
  }
29
 
30
+ # Function to display disease information
31
+ def display_disease_info(disease_name):
32
+ disease_name = disease_name.lower()
33
+ if disease_name in diseases:
34
+ disease = diseases[disease_name]
35
+ print(f"\nDisease: {disease_name.title()}")
36
+ print("Symptoms:")
37
+ for symptom in disease["symptoms"]:
38
+ print(f" - {symptom}")
39
+ print(f"\nTreatment: {disease['treatment']}")
 
 
 
 
 
 
 
 
40
  else:
41
+ print("Disease not found. Please check the name and try again.")
42
 
43
+ # Function to handle chat feature
44
+ def chat_bot():
45
+ print("\nChat Bot is active. Type 'exit' to quit.\n")
46
+ while True:
47
+ user_input = input("You: ").strip().lower()
48
+
49
+ # Responding to the "cha hal aa?" query with "khair aa"
50
+ if user_input == "cha hal aa?":
51
+ print("Bot: khair aa")
52
+
53
+ # Check if the user wants to know about a disease
54
+ elif user_input in diseases:
55
+ display_disease_info(user_input)
56
+
57
+ # Exit the chat bot if the user types 'exit'
58
+ elif user_input == "exit":
59
+ print("Exiting chat...")
60
+ break
61
+
62
+ # If the input is unrecognized
63
+ else:
64
+ print("Bot: Sorry, I didn't understand that. Please ask about a disease or type 'exit' to quit.")
65
 
66
+ # Main menu to choose between disease info or chat
67
+ def main():
68
+ print("Welcome to the Disease Information and Chat Bot!\n")
69
+
70
+ while True:
71
+ print("\nChoose an option:")
72
+ print("1. Disease Information")
73
+ print("2. Chat with Bot")
74
+ print("3. Exit")
75
+
76
+ option = input("Enter your choice (1/2/3): ").strip()
77
+
78
+ if option == "1":
79
+ disease_name = input("Enter the name of the disease: ").strip().lower()
80
+ display_disease_info(disease_name)
81
+
82
+ elif option == "2":
83
+ chat_bot()
84
+
85
+ elif option == "3":
86
+ print("Exiting the program...")
87
+ break
88
+
89
+ else:
90
+ print("Invalid choice. Please try again.")
91
 
92
+ # Run the program
93
+ if __name__ == "__main__":
94
+ main()