File size: 3,791 Bytes
80ffae0
 
99032ef
80ffae0
 
 
 
 
 
 
 
 
 
 
 
 
99032ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80ffae0
 
 
 
 
 
be9ce02
 
 
80ffae0
 
be9ce02
 
 
 
80ffae0
be9ce02
 
 
 
 
80ffae0
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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()
    
    # 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)