healthguide / app.py
Muhammadtaha12's picture
Update app.py
99032ef verified
raw
history blame
3.43 kB
import streamlit as st
# Define the healthcare knowledge base with a wider set of diseases and conditions
health_knowledge_base = {
"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.",
},
}
# Function to search for health information in the knowledge base
def get_health_info(query):
query = query.lower()
# Search for conditions that match the query
for condition, info in health_knowledge_base.items():
if condition in query:
return f"Condition: {condition.title()}\n" \
f"Symptoms: {', '.join(info['symptoms'])}\n" \
f"Treatment: {info['treatment']}"
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)