mindspark121 commited on
Commit
990b877
Β·
verified Β·
1 Parent(s): d9adb77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -7
app.py CHANGED
@@ -75,15 +75,25 @@ def generate_empathetic_response(user_input, retrieved_question):
75
  # βœ… Function to detect disorders
76
  def detect_disorders(chat_history):
77
  """Detect psychiatric disorders from full chat history."""
78
- full_chat_text = " ".join(chat_history)
79
- text_embedding = similarity_model.encode([full_chat_text], convert_to_numpy=True)
80
- distances, indices = index.search(text_embedding, 3)
81
 
82
- if indices[0][0] == -1:
83
- return ["No matching disorder found."]
 
 
 
 
 
84
 
85
- disorders = [recommendations_df["Disorder"].iloc[i] for i in indices[0]]
86
- return disorders
 
 
 
 
 
 
87
 
88
  # βœ… Function to get treatment recommendations
89
  def get_treatment(detected_disorders):
 
75
  # βœ… Function to detect disorders
76
  def detect_disorders(chat_history):
77
  """Detect psychiatric disorders from full chat history."""
78
+ if not chat_history: # βœ… Handle empty chat history
79
+ return ["No input provided."]
 
80
 
81
+ full_chat_text = " ".join(chat_history).strip()
82
+ if not full_chat_text: # βœ… Handle case where all messages are empty strings
83
+ return ["No meaningful text provided."]
84
+
85
+ try:
86
+ text_embedding = similarity_model.encode([full_chat_text], convert_to_numpy=True)
87
+ distances, indices = index.search(text_embedding, 3)
88
 
89
+ if indices is None or indices[0][0] == -1:
90
+ return ["No matching disorder found."]
91
+
92
+ disorders = [recommendations_df["Disorder"].iloc[i] for i in indices[0]]
93
+ return disorders
94
+
95
+ except Exception as e:
96
+ return [f"Error detecting disorders: {str(e)}"] # βœ… Catch unexpected errors
97
 
98
  # βœ… Function to get treatment recommendations
99
  def get_treatment(detected_disorders):