healthguide / app.py
Muhammadtaha12's picture
Update app.py
978364c verified
raw
history blame
9.11 kB
import streamlit as st
# Define the healthcare knowledge base with a wider set of diseases and conditions
{
"flu": {
"symptoms": ["fever", "cough", "sore throat", "body aches", "fatigue"],
"treatment": "Rest, fluids, pain relievers, and anti-viral medications if prescribed."
},
"headache": {
"symptoms": ["head pain", "nausea", "sensitivity to light"],
"treatment": "Rest, hydration, over-the-counter painkillers, and avoid triggers."
},
"diabetes": {
"symptoms": ["increased thirst", "frequent urination", "fatigue", "blurred vision"],
"treatment": "Insulin therapy, lifestyle changes, and dietary management."
},
"cold": {
"symptoms": ["sore throat", "runny nose", "cough", "sneezing", "mild body aches"],
"treatment": "Rest, hydration, decongestants, and over-the-counter pain relief."
},
"asthma": {
"symptoms": ["shortness of breath", "wheezing", "chest tightness", "coughing"],
"treatment": "Inhalers, bronchodilators, corticosteroids, and avoiding triggers."
},
"pneumonia": {
"symptoms": ["cough with mucus", "fever", "shortness of breath", "chest pain"],
"treatment": "Antibiotics for bacterial pneumonia, rest, fluids, and pain relievers."
},
"hypertension": {
"symptoms": ["headaches", "dizziness", "shortness of breath", "nosebleeds"],
"treatment": "Medications like beta-blockers, ACE inhibitors, lifestyle changes including exercise and diet."
},
"anxiety": {
"symptoms": ["excessive worry", "restlessness", "fatigue", "difficulty concentrating", "irritability"],
"treatment": "Cognitive-behavioral therapy (CBT), medications like SSRIs, relaxation techniques."
},
"depression": {
"symptoms": ["persistent sadness", "loss of interest", "fatigue", "changes in appetite or sleep patterns"],
"treatment": "Antidepressants, therapy (CBT), exercise, and social support."
},
"arthritis": {
"symptoms": ["joint pain", "swelling", "stiffness", "reduced range of motion"],
"treatment": "Pain relievers, anti-inflammatory drugs, physical therapy, and joint protection."
},
"covid-19": {
"symptoms": ["fever", "dry cough", "fatigue", "loss of taste or smell", "shortness of breath"],
"treatment": "Rest, fluids, over-the-counter medications, and antiviral drugs if prescribed."
},
"abdominal_aortic_aneurysm": {
"symptoms": ["back pain", "abdominal pain", "pulsating mass in the abdomen"],
"treatment": "Surgical intervention, blood pressure control, and monitoring."
},
"acute_lymphoblastic_leukemia": {
"symptoms": ["fever", "pale skin", "unexplained weight loss", "easy bruising"],
"treatment": "Chemotherapy, bone marrow transplant, and supportive care."
},
"acute_myeloid_leukemia": {
"symptoms": ["fatigue", "fever", "easy bruising or bleeding", "shortness of breath"],
"treatment": "Chemotherapy, stem cell transplant, and supportive care."
},
"acromegaly": {
"symptoms": ["enlarged hands and feet", "joint pain", "thickened skin", "enlarged facial features"],
"treatment": "Surgery, radiation therapy, and medication to control growth hormone production."
},
"actinomycosis": {
"symptoms": ["abscesses", "fever", "painful lumps", "swelling"],
"treatment": "Long-term antibiotics such as penicillin."
},
"acute_renal_failure": {
"symptoms": ["decreased urine output", "fatigue", "swelling in the legs", "confusion"],
"treatment": "Dialysis, fluid management, and treatment of underlying causes."
},
"addisons_disease": {
"symptoms": ["fatigue", "muscle weakness", "low blood pressure", "darkening of the skin"],
"treatment": "Corticosteroid therapy and lifestyle modifications."
},
"adhd": {
"symptoms": ["impulsivity", "difficulty focusing", "hyperactivity", "forgetfulness"],
"treatment": "Stimulant medications, therapy (CBT), and lifestyle management."
},
"aids": {
"symptoms": ["weight loss", "fever", "night sweats", "fatigue", "recurrent infections"],
"treatment": "Antiretroviral therapy (ART) to manage the virus and prevent complications."
},
"albinism": {
"symptoms": ["pale skin", "light-colored eyes", "vision problems", "sensitivity to light"],
"treatment": "UV protection, corrective lenses for vision, and skin protection."
},
"alcoholic_hepatitis": {
"symptoms": ["nausea", "abdominal pain", "yellowing of the skin (jaundice)", "loss of appetite"],
"treatment": "Avoid alcohol, medications to manage symptoms, and possible liver transplant."
},
"alcoholism": {
"symptoms": ["strong cravings for alcohol", "inability to control drinking", "neglect of responsibilities"],
"treatment": "Behavioral therapy, support groups, medications like disulfiram, and rehabilitation."
},
"alkaptonuria": {
"symptoms": ["dark urine", "arthritis", "heart disease", "darkening of the ears or eyes"],
"treatment": "Managing symptoms, physical therapy, and joint replacement if necessary."
},
"allergies": {
"symptoms": ["sneezing", "itchy eyes", "runny nose", "hives", "swelling"],
"treatment": "Antihistamines, decongestants, and avoiding triggers."
},
"alzheimers_disease": {
"symptoms": ["memory loss", "difficulty with tasks", "confusion", "personality changes"],
"treatment": "Cognitive-enhancing drugs, therapy, and support for caregivers."
},
"amyotrophic_lateral_sclerosis": {
"symptoms": ["muscle weakness", "difficulty speaking or swallowing", "breathing problems"],
"treatment": "Symptom management, physical therapy, and breathing support."
},
"anemia": {
"symptoms": ["fatigue", "pale skin", "dizziness", "shortness of breath"],
"treatment": "Iron supplements, B12 injections, or blood transfusions depending on the cause."
},
"aneurysm": {
"symptoms": ["severe headache", "nausea", "blurred vision", "pain in the chest or abdomen"],
"treatment": "Surgical repair, blood pressure control, and monitoring."
},
"angelman_syndrome": {
"symptoms": ["delayed development", "lack of speech", "seizures", "smiling and laughter"],
"treatment": "Physical therapy, speech therapy, and medications for seizures."
},
"anorexia_nervosa": {
"symptoms": ["extreme weight loss", "fear of gaining weight", "distorted body image", "restricted eating"],
"treatment": "Nutritional rehabilitation, psychotherapy, and medical monitoring."
},
"anthrax": {
"symptoms": ["fever", "cough", "chest pain", "difficulty breathing", "swelling"],
"treatment": "Antibiotics and in some cases, vaccination."
},
"antiphospholipid_syndrome": {
"symptoms": ["recurrent miscarriages", "blood clots", "stroke", "rashes"],
"treatment": "Blood thinners and management of clotting disorders."
},
"aortic_stenosis": {
"symptoms": ["chest pain", "shortness of breath", "fatigue", "fainting"],
"treatment": "Surgical valve replacement or balloon valvuloplasty."
},
"aortic_dissection": {
"symptoms": ["severe chest or back pain", "difficulty breathing", "sweating", "loss of consciousness"],
"treatment": "Emergency surgery, blood pressure control, and monitoring."
},
"apraxia": {
"symptoms": ["difficulty planning and coordinating muscle movements", "speech and motor difficulties"],
"treatment": "Speech therapy, physical therapy, and occupational therapy."
}
}
# Function to search for health information in the knowledge base
def get_health_info(query):
query = query.lower()
# List to store matching results
matching_conditions = []
# Search for conditions that match the query
for condition, info in health_knowledge_base.items():
if condition in query or any(symptom in query for symptom in info['symptoms']):
matching_conditions.append(f"Condition: {condition.title()}\n"
f"Symptoms: {', '.join(info['symptoms'])}\n"
f"Treatment: {info['treatment']}\n")
# If we have matching conditions, return all of them, otherwise return a message
if matching_conditions:
return "\n\n".join(matching_conditions)
else:
return "Sorry, I couldn't find information on that condition. Please try another query."
# Set up the Streamlit app interface
st.title("Healthcare Knowledge Chatbot")
st.write("Ask me about health conditions, symptoms, treatments, and I'll provide relevant information.")
# Input field for user queries
user_input = st.text_input("Ask a healthcare-related question...")
# Display response based on user input
if user_input:
response = get_health_info(user_input)
st.write(response)