Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
79 |
-
|
80 |
-
distances, indices = index.search(text_embedding, 3)
|
81 |
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|