vsrinivas commited on
Commit
55acba8
1 Parent(s): 8e789f9

Update funcs.py

Browse files
Files changed (1) hide show
  1. funcs.py +99 -12
funcs.py CHANGED
@@ -70,13 +70,7 @@ def generate_triggers_img(items):
70
  triggers_img = Image.open('triggeres.png')
71
  return triggers_img
72
 
73
-
74
- class process_session():
75
- def __init__(self):
76
- self.session_conversation=[]
77
-
78
- def get_doc_response_emotions(self, user_message, therapy_session_conversation):
79
-
80
  user_messages = []
81
  user_messages.append(user_message)
82
  emotion_set = detect_emotions(user_message)
@@ -95,7 +89,7 @@ class process_session():
95
 
96
  therapy_session_conversation.append(["User: "+user_message, "Therapist: "+doc_response])
97
 
98
- self.session_conversation.extend(["User: "+user_message, "Therapist: "+doc_response])
99
 
100
  print(f"User's message: {user_message}")
101
  print(f"RAG Matching message: {dials_embeddings.iloc[top_match_index]['Patient']}")
@@ -103,7 +97,9 @@ class process_session():
103
 
104
  return '', therapy_session_conversation, emotions_msg
105
 
106
- def summarize_and_recommend(self):
 
 
107
 
108
  session_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
109
  session_conversation_processed = self.session_conversation.copy()
@@ -116,7 +112,7 @@ class process_session():
116
  model="tiiuae/falcon-180b-chat",
117
  messages=[
118
  {"role": "system", "content": """You are an Expert Cognitive Behavioural Therapist and Precis writer.
119
- Summarize the below user content <<<session_conversation_processed>>> into useful, ethical, relevant and realistic phrases with a format
120
  Session Time:
121
  Summary of the patient messages: #in two to four sentences
122
  Summary of therapist messages: #in two to three sentences:
@@ -137,7 +133,7 @@ class process_session():
137
  model="tiiuae/falcon-180b-chat",
138
  messages=[
139
  {"role": "system", "content": """You are an expert Cognitive Behavioural Therapist.
140
- Based on the full summary <<<full_summary>>> provide clinically valid, useful, appropriate action plan for the Patient as a bullted list.
141
  The list shall contain both medical and non medical prescriptions, dos and donts. The format of response shall be in passive voice with proper tense.
142
  - The patient is referred to........ #in one sentence
143
  - The patient is advised to ........ #in one sentence
@@ -155,5 +151,96 @@ class process_session():
155
  full_recommendations = full_recommendations.replace('User:', '').strip()
156
  print("\n")
157
  print("Full recommendations:", full_recommendations)
158
- self.session_conversation=[]
159
  return full_summary, full_recommendations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  triggers_img = Image.open('triggeres.png')
71
  return triggers_img
72
 
73
+ def get_doc_response_emotions(self, user_message, therapy_session_conversation):
 
 
 
 
 
 
74
  user_messages = []
75
  user_messages.append(user_message)
76
  emotion_set = detect_emotions(user_message)
 
89
 
90
  therapy_session_conversation.append(["User: "+user_message, "Therapist: "+doc_response])
91
 
92
+ # session_conversation.extend(["User: "+user_message, "Therapist: "+doc_response])
93
 
94
  print(f"User's message: {user_message}")
95
  print(f"RAG Matching message: {dials_embeddings.iloc[top_match_index]['Patient']}")
 
97
 
98
  return '', therapy_session_conversation, emotions_msg
99
 
100
+ def summarize_and_recommend(therapy_session_conversation):
101
+
102
+ session_conversation = [item[0] for item in therapy_session_conversation]
103
 
104
  session_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
105
  session_conversation_processed = self.session_conversation.copy()
 
112
  model="tiiuae/falcon-180b-chat",
113
  messages=[
114
  {"role": "system", "content": """You are an Expert Cognitive Behavioural Therapist and Precis writer.
115
+ Summarize 'STRICTLY' the below user content <<<session_conversation_processed>>> 'ONLY' into useful, ethical, relevant and realistic phrases with a format
116
  Session Time:
117
  Summary of the patient messages: #in two to four sentences
118
  Summary of therapist messages: #in two to three sentences:
 
133
  model="tiiuae/falcon-180b-chat",
134
  messages=[
135
  {"role": "system", "content": """You are an expert Cognitive Behavioural Therapist.
136
+ Based on 'STRICTLY' the full summary <<<full_summary>>> 'ONLY' provide clinically valid, useful, appropriate action plan for the Patient as a bullted list.
137
  The list shall contain both medical and non medical prescriptions, dos and donts. The format of response shall be in passive voice with proper tense.
138
  - The patient is referred to........ #in one sentence
139
  - The patient is advised to ........ #in one sentence
 
151
  full_recommendations = full_recommendations.replace('User:', '').strip()
152
  print("\n")
153
  print("Full recommendations:", full_recommendations)
154
+ therapy_session_conversation=[]
155
  return full_summary, full_recommendations
156
+
157
+
158
+
159
+
160
+
161
+ # class process_session():
162
+ # def __init__(self):
163
+ # self.session_conversation=[]
164
+
165
+ # def get_doc_response_emotions(self, user_message, therapy_session_conversation):
166
+
167
+ # user_messages = []
168
+ # user_messages.append(user_message)
169
+ # emotion_set = detect_emotions(user_message)
170
+ # print(emotion_set)
171
+
172
+ # emotions_msg = generate_triggers_img(emotion_set)
173
+ # user_embedding = embed_model.encode(user_message, device='cuda' if torch.cuda.is_available() else 'cpu')
174
+
175
+ # similarities =[]
176
+ # for v in dials_embeddings['embeddings']:
177
+ # similarities.append(cosine_distance(user_embedding,v))
178
+
179
+ # top_match_index = similarities.index(max(similarities))
180
+ # # doc_response = dials_embeddings.iloc[top_match_index+1]['Doctor']
181
+ # doc_response = dials_embeddings.iloc[top_match_index]['Doctor']
182
+
183
+ # therapy_session_conversation.append(["User: "+user_message, "Therapist: "+doc_response])
184
+
185
+ # self.session_conversation.extend(["User: "+user_message, "Therapist: "+doc_response])
186
+
187
+ # print(f"User's message: {user_message}")
188
+ # print(f"RAG Matching message: {dials_embeddings.iloc[top_match_index]['Patient']}")
189
+ # print(f"Therapist's response: {dials_embeddings.iloc[top_match_index]['Doctor']}\n\n")
190
+
191
+ # return '', therapy_session_conversation, emotions_msg
192
+
193
+ # def summarize_and_recommend(self):
194
+
195
+ # session_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
196
+ # session_conversation_processed = self.session_conversation.copy()
197
+ # session_conversation_processed.insert(0, "Session_time: "+session_time)
198
+ # session_conversation_processed ='\n'.join(session_conversation_processed)
199
+ # print("Session conversation:", session_conversation_processed)
200
+
201
+ # full_summary = ""
202
+ # for chunk in AI71(AI71_API_KEY).chat.completions.create(
203
+ # model="tiiuae/falcon-180b-chat",
204
+ # messages=[
205
+ # {"role": "system", "content": """You are an Expert Cognitive Behavioural Therapist and Precis writer.
206
+ # Summarize the below user content <<<session_conversation_processed>>> into useful, ethical, relevant and realistic phrases with a format
207
+ # Session Time:
208
+ # Summary of the patient messages: #in two to four sentences
209
+ # Summary of therapist messages: #in two to three sentences:
210
+ # Summary of the whole session: # in two to three sentences. Ensure the entire session summary strictly does not exceed 100 tokens."""},
211
+ # {"role": "user", "content": session_conversation_processed},
212
+ # ],
213
+ # stream=True,
214
+ # ):
215
+ # if chunk.choices[0].delta.content:
216
+ # summary = chunk.choices[0].delta.content
217
+ # full_summary += summary
218
+ # full_summary = full_summary.replace('User:', '').strip()
219
+ # print("\n")
220
+ # print("Full summary:", full_summary)
221
+
222
+ # full_recommendations = ""
223
+ # for chunk in AI71(AI71_API_KEY).chat.completions.create(
224
+ # model="tiiuae/falcon-180b-chat",
225
+ # messages=[
226
+ # {"role": "system", "content": """You are an expert Cognitive Behavioural Therapist.
227
+ # Based on the full summary <<<full_summary>>> provide clinically valid, useful, appropriate action plan for the Patient as a bullted list.
228
+ # The list shall contain both medical and non medical prescriptions, dos and donts. The format of response shall be in passive voice with proper tense.
229
+ # - The patient is referred to........ #in one sentence
230
+ # - The patient is advised to ........ #in one sentence
231
+ # - The patient is refrained from........ #in one sentence
232
+ # - It is suggested that tha patient ........ #in one sentence
233
+ # - Scheduled a follow-up session with the patient........#in one sentence
234
+ # *Ensure the list contains NOT MORE THAN 7 points"""},
235
+ # {"role": "user", "content": full_summary},
236
+ # ],
237
+ # stream=True,
238
+ # ):
239
+ # if chunk.choices[0].delta.content:
240
+ # rec = chunk.choices[0].delta.content
241
+ # full_recommendations += rec
242
+ # full_recommendations = full_recommendations.replace('User:', '').strip()
243
+ # print("\n")
244
+ # print("Full recommendations:", full_recommendations)
245
+ # self.session_conversation=[]
246
+ # return full_summary, full_recommendations