Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -36,17 +36,12 @@ 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", "headache related to epilepsy"]
|
40 |
-
healthcare_keywords = ["headache", "fever", "blood pressure", "diabetes", "cough", "flu", "nutrition", "mental health", "pain", "legs", "body pain", "health", "medical", "symptoms", "treatment", "disease", "illness"]
|
41 |
|
42 |
-
|
43 |
-
for
|
44 |
-
|
45 |
-
is_healthcare_related = True
|
46 |
-
break # Exit loop once a healthcare keyword is found
|
47 |
-
|
48 |
-
is_epilepsy_related = any(k in tokens for k in epilepsy_keywords) and not is_healthcare_related # Epilepsy check AFTER healthcare
|
49 |
-
is_general = not is_epilepsy_related and not is_healthcare_related
|
50 |
|
51 |
print(f"Query: {query}") # Debugging prints
|
52 |
print(f"Tokens: {tokens}")
|
@@ -121,7 +116,7 @@ def generate_response(user_query, chat_history):
|
|
121 |
except Exception as e:
|
122 |
model_response = f"⚠️ Error generating response with LLaMA: {e}"
|
123 |
|
124 |
-
return f"**NeuroGuard:** ✅ **
|
125 |
|
126 |
# If Healthcare Related but Not Epilepsy - Provide General Wellness Tips and Basic Remedies
|
127 |
elif is_healthcare_related:
|
@@ -146,7 +141,7 @@ def generate_response(user_query, chat_history):
|
|
146 |
"- 🩺 **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."
|
147 |
)
|
148 |
|
149 |
-
response_content = f"**NeuroGuard:** 🩺
|
150 |
response_content += suggested_remedy
|
151 |
response_content += general_health_tips # Always include general tips
|
152 |
|
@@ -156,8 +151,8 @@ def generate_response(user_query, chat_history):
|
|
156 |
# If General Query (Not Healthcare or Epilepsy Related) - Provide a different response
|
157 |
elif is_general:
|
158 |
return (
|
159 |
-
f"**NeuroGuard:** 💡
|
160 |
-
"**Tip:** For
|
161 |
)
|
162 |
|
163 |
# Fallback - should ideally not reach here
|
|
|
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", "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}")
|
|
|
116 |
except Exception as e:
|
117 |
model_response = f"⚠️ Error generating response with LLaMA: {e}"
|
118 |
|
119 |
+
return f"**NeuroGuard:** ✅ **Epilepsy Focused Response:**\n{pubmedbert_insights}\n\n**Response:**\n{model_response}" # Modified response intro
|
120 |
|
121 |
# If Healthcare Related but Not Epilepsy - Provide General Wellness Tips and Basic Remedies
|
122 |
elif is_healthcare_related:
|
|
|
141 |
"- 🩺 **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."
|
142 |
)
|
143 |
|
144 |
+
response_content = f"**NeuroGuard:** 🩺 **General Health Assistance:** While my primary focus is epilepsy, this seems to be a general health-related question. Here's some information that might help:\n\n" # Modified response intro
|
145 |
response_content += suggested_remedy
|
146 |
response_content += general_health_tips # Always include general tips
|
147 |
|
|
|
151 |
# If General Query (Not Healthcare or Epilepsy Related) - Provide a different response
|
152 |
elif is_general:
|
153 |
return (
|
154 |
+
f"**NeuroGuard:** 💡 **Not Epilepsy or Health Related:** It seems your question '{user_query}' is outside my areas of expertise, which are epilepsy and general health. \n\n" # Modified response intro
|
155 |
+
"**Tip:** For topics unrelated to epilepsy or health, you might find better answers using a general search engine or a chatbot trained on a broader range of topics."
|
156 |
)
|
157 |
|
158 |
# Fallback - should ideally not reach here
|