Haseeb-001 commited on
Commit
0da792b
·
verified ·
1 Parent(s): 7e8afef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
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
- is_healthcare_related = False # Initialize to False
43
- for keyword in healthcare_keywords: # Explicitly check for healthcare keywords first
44
- if keyword in tokens:
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:** ✅ **Analysis:**\n{pubmedbert_insights}\n\n**Response:**\n{model_response}"
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:** 🩺 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
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:** 💡 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
160
- "**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."
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