Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,12 +37,18 @@ index = faiss.IndexFlatL2(embedding_dim)
|
|
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)
|
43 |
is_healthcare_related = any(k in tokens for k in healthcare_keywords) and not is_epilepsy_related # Healthcare but NOT epilepsy
|
44 |
is_general = not is_epilepsy_related and not is_healthcare_related # Truly general queries
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
return tokens, is_epilepsy_related, is_healthcare_related, is_general
|
47 |
|
48 |
# Function to Generate Response with Chat History
|
@@ -145,7 +151,7 @@ def generate_response(user_query, chat_history):
|
|
145 |
# If General Query (Not Healthcare or Epilepsy Related) - Provide a different response
|
146 |
elif is_general:
|
147 |
return (
|
148 |
-
f"**NeuroGuard:** 💡
|
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 |
|
|
|
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", "illness"] # Extended healthcare keywords - added "illness"
|
41 |
|
42 |
is_epilepsy_related = any(k in tokens for k in epilepsy_keywords)
|
43 |
is_healthcare_related = any(k in tokens for k in healthcare_keywords) and not is_epilepsy_related # Healthcare but NOT epilepsy
|
44 |
is_general = not is_epilepsy_related and not is_healthcare_related # Truly general queries
|
45 |
|
46 |
+
print(f"Query: {query}") # Debugging prints
|
47 |
+
print(f"Tokens: {tokens}")
|
48 |
+
print(f"Is Epilepsy Related: {is_epilepsy_related}")
|
49 |
+
print(f"Is Healthcare Related: {is_healthcare_related}")
|
50 |
+
print(f"Is General: {is_general}")
|
51 |
+
|
52 |
return tokens, is_epilepsy_related, is_healthcare_related, is_general
|
53 |
|
54 |
# Function to Generate Response with Chat History
|
|
|
151 |
# If General Query (Not Healthcare or Epilepsy Related) - Provide a different response
|
152 |
elif is_general:
|
153 |
return (
|
154 |
+
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
|
155 |
"**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."
|
156 |
)
|
157 |
|