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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -37,18 +37,12 @@ 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", "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
@@ -116,7 +110,7 @@ def generate_response(user_query, chat_history):
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,7 +135,7 @@ def generate_response(user_query, chat_history):
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,8 +145,8 @@ def generate_response(user_query, chat_history):
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
 
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
 
110
  except Exception as e:
111
  model_response = f"⚠️ Error generating response with LLaMA: {e}"
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:
 
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
 
 
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
 
152
  # Fallback - should ideally not reach here