KarthickAdopleAI commited on
Commit
61c8fd7
1 Parent(s): 3706742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -151,9 +151,9 @@ class LangChain_Document_QA:
151
  return client,agent
152
 
153
 
154
- def _suggested_answer(self,text):
155
  try:
156
- history = self._chat_history()
157
  try:
158
  file_path = "patient_details.json"
159
  with open(file_path) as file:
@@ -167,7 +167,7 @@ class LangChain_Document_QA:
167
  first start the conversation ask existing patient or new patient. if new patient get name,age,gender,contact,address from the patient and start. \
168
  if existing customer get name,age,gender,contact,address details and start the chat about existing issues and current issues. \
169
  if patient say thanking tone message to end the conversation with a thanking greeting when the patient expresses gratitude. \
170
- Chat History:['''{history}''']
171
  Patient: ['''{text}''']
172
  Perform as Mental Healthcare Doctor Chatbot
173
  """
@@ -184,9 +184,13 @@ class LangChain_Document_QA:
184
  message = response.choices[0].text.strip()
185
  if ":" in message:
186
  message = re.sub(r'^.*:', '', message)
187
- return message.strip()
 
 
188
  except:
189
- return "How can I help you?"
 
 
190
 
191
 
192
  def _text_box(self,customer_emotion,customer_sentiment_score):
@@ -269,7 +273,7 @@ class LangChain_Document_QA:
269
 
270
  txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
271
  txt_msg.then(lambda: gr.update(interactive=True), None, [txt])
272
- txt.submit(self._suggested_answer,txt,chatbot)
273
  button.click(self._agent_text, [chatbot,txt3], chatbot)
274
  end_btn.click(self._display_history, [], txt4)
275
  emptyBtn.click(self.clear_func,[],[])
 
151
  return client,agent
152
 
153
 
154
+ def _suggested_answer(self,history, text):
155
  try:
156
+ history_list = self._chat_history()
157
  try:
158
  file_path = "patient_details.json"
159
  with open(file_path) as file:
 
167
  first start the conversation ask existing patient or new patient. if new patient get name,age,gender,contact,address from the patient and start. \
168
  if existing customer get name,age,gender,contact,address details and start the chat about existing issues and current issues. \
169
  if patient say thanking tone message to end the conversation with a thanking greeting when the patient expresses gratitude. \
170
+ Chat History:['''{history_list}''']
171
  Patient: ['''{text}''']
172
  Perform as Mental Healthcare Doctor Chatbot
173
  """
 
184
  message = response.choices[0].text.strip()
185
  if ":" in message:
186
  message = re.sub(r'^.*:', '', message)
187
+ history[-1][1] = message.strip()
188
+ history_state.value = history
189
+ return history
190
  except:
191
+ history[-1][1] = "How can I help you?"
192
+ history_state.value = history
193
+ return history
194
 
195
 
196
  def _text_box(self,customer_emotion,customer_sentiment_score):
 
273
 
274
  txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
275
  txt_msg.then(lambda: gr.update(interactive=True), None, [txt])
276
+ txt.submit(self._suggested_answer, [chatbot,txt],chatbot)
277
  button.click(self._agent_text, [chatbot,txt3], chatbot)
278
  end_btn.click(self._display_history, [], txt4)
279
  emptyBtn.click(self.clear_func,[],[])