Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ index = faiss.IndexFlatL2(embedding_dim)
|
|
36 |
# Function to Check Query Category
|
37 |
def preprocess_query(query):
|
38 |
tokens = query.lower().split()
|
39 |
-
epilepsy_keywords = ["seizure", "epilepsy", "convulsion", "neurology", "brain activity"]
|
40 |
healthcare_keywords = ["headache", "fever", "blood pressure", "diabetes", "cough", "flu", "nutrition", "mental health", "pain", "legs", "body pain", "health", "medical", "symptoms", "treatment", "disease"] # Extended healthcare keywords
|
41 |
|
42 |
is_epilepsy_related = any(k in tokens for k in epilepsy_keywords)
|
@@ -112,27 +112,40 @@ def generate_response(user_query, chat_history):
|
|
112 |
|
113 |
return f"**NeuroGuard:** β
**Analysis:**\n{pubmedbert_insights}\n\n**Response:**\n{model_response}"
|
114 |
|
115 |
-
# If Healthcare Related but Not Epilepsy - Provide General Wellness Tips
|
116 |
elif is_healthcare_related:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
general_health_tips = (
|
118 |
-
"For general health and well-being:\n"
|
119 |
"- π§ Stay hydrated by drinking plenty of water throughout the day.\n"
|
120 |
"- π Maintain a balanced diet rich in fruits, vegetables, and whole grains.\n"
|
121 |
"- πΆββοΈ Incorporate regular physical activity into your daily routine.\n"
|
122 |
"- π΄ Ensure you get adequate sleep to allow your body to rest and recover.\n"
|
123 |
"- π§ Practice stress-reducing activities such as deep breathing or meditation.\n"
|
124 |
-
"- π©Ί **Important:** These tips are for general wellness. Always consult a healthcare professional for any specific health concerns or before making significant changes to your health regimen."
|
125 |
-
)
|
126 |
-
return (
|
127 |
-
f"**NeuroGuard:** π©Ί It sounds like your question '{user_query}' is about general health. While I specialize in epilepsy, here are some general wellness tips that might be helpful:\n\n" # Use original user_query in response
|
128 |
-
f"{general_health_tips}"
|
129 |
)
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
# If General Query (Not Healthcare or Epilepsy Related) - Provide a different response
|
133 |
elif is_general:
|
134 |
return (
|
135 |
-
f"**NeuroGuard:** π‘ My expertise is focused on epilepsy and general health. For topics outside of these areas, like '{user_query}', I may not be the best resource. \n\n"
|
136 |
"**Tip:** For general knowledge questions, you might find better answers using a general search engine or a chatbot trained on a broader range of topics."
|
137 |
)
|
138 |
|
|
|
36 |
# Function to Check Query Category
|
37 |
def preprocess_query(query):
|
38 |
tokens = query.lower().split()
|
39 |
+
epilepsy_keywords = ["seizure", "epilepsy", "convulsion", "neurology", "brain activity", "headache related to epilepsy"] # Added specific phrase
|
40 |
healthcare_keywords = ["headache", "fever", "blood pressure", "diabetes", "cough", "flu", "nutrition", "mental health", "pain", "legs", "body pain", "health", "medical", "symptoms", "treatment", "disease"] # Extended healthcare keywords
|
41 |
|
42 |
is_epilepsy_related = any(k in tokens for k in epilepsy_keywords)
|
|
|
112 |
|
113 |
return f"**NeuroGuard:** β
**Analysis:**\n{pubmedbert_insights}\n\n**Response:**\n{model_response}"
|
114 |
|
115 |
+
# If Healthcare Related but Not Epilepsy - Provide General Wellness Tips and Basic Remedies
|
116 |
elif is_healthcare_related:
|
117 |
+
remedy_suggestions = {
|
118 |
+
"headache": "For headaches, you can try resting in a quiet, dark room, staying hydrated, and applying a cold compress to your forehead. Over-the-counter pain relievers like ibuprofen or acetaminophen may also help.",
|
119 |
+
"pain": "For general pain, rest, gentle stretching, and applying heat or ice to the affected area can provide relief. Over-the-counter pain relievers might also be beneficial. ",
|
120 |
+
"legs pain": "For leg pain, try elevating your legs, applying heat or ice, and gentle stretching exercises. Staying hydrated and ensuring good circulation can also help. "
|
121 |
+
# Add more specific remedies as needed
|
122 |
+
}
|
123 |
+
suggested_remedy = "For general wellness:\n" # Default if no specific remedy keyword is found
|
124 |
+
for keyword, remedy in remedy_suggestions.items():
|
125 |
+
if keyword in corrected_query: # Check corrected query for keywords
|
126 |
+
suggested_remedy = remedy + "\n\n" # Use specific remedy if keyword found
|
127 |
+
break # Use only the first matching remedy for now
|
128 |
+
|
129 |
general_health_tips = (
|
|
|
130 |
"- π§ Stay hydrated by drinking plenty of water throughout the day.\n"
|
131 |
"- π Maintain a balanced diet rich in fruits, vegetables, and whole grains.\n"
|
132 |
"- πΆββοΈ Incorporate regular physical activity into your daily routine.\n"
|
133 |
"- π΄ Ensure you get adequate sleep to allow your body to rest and recover.\n"
|
134 |
"- π§ Practice stress-reducing activities such as deep breathing or meditation.\n"
|
135 |
+
"- π©Ί **Important:** These tips are for general wellness and informational purposes only, and are not medical advice. Always consult a healthcare professional for any specific health concerns or before making significant changes to your health regimen."
|
|
|
|
|
|
|
|
|
136 |
)
|
137 |
|
138 |
+
response_content = f"**NeuroGuard:** π©Ί It seems your question '{user_query}' is about general health. While I focus on epilepsy, here's some information that might help:\n\n" # Use original user_query
|
139 |
+
response_content += suggested_remedy
|
140 |
+
response_content += general_health_tips # Always include general tips
|
141 |
+
|
142 |
+
return response_content
|
143 |
+
|
144 |
|
145 |
# If General Query (Not Healthcare or Epilepsy Related) - Provide a different response
|
146 |
elif is_general:
|
147 |
return (
|
148 |
+
f"**NeuroGuard:** π‘ My expertise is focused on epilepsy and general health. For topics outside of these areas, like '{user_query}', I may not be the best resource. \n\n" # Use original user_query
|
149 |
"**Tip:** For general knowledge questions, you might find better answers using a general search engine or a chatbot trained on a broader range of topics."
|
150 |
)
|
151 |
|