Karthikeyan commited on
Commit
141b4a5
1 Parent(s): b11473c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -24
app.py CHANGED
@@ -177,39 +177,27 @@ class LangChain_Document_QA:
177
 
178
 
179
 
180
- def _text_box(self,customer_emotion,agent_emotion,agent_sentiment_score,customer_sentiment_score):
181
- agent_score = ", ".join([f"{key}: {value:.2f}" for key, value in agent_sentiment_score.items()])
182
  customer_score = ", ".join([f"{key}: {value:.2f}" for key, value in customer_sentiment_score.items()])
183
- return f"customer_emotion:{customer_emotion}\nagent_emotion:{agent_emotion}\nAgent_Sentiment_score:{agent_score}\nCustomer_sentiment_score:{customer_score}"
184
 
185
  def _on_sentiment_btn_click(self):
186
- client,agent=self._history_of_chat()
187
 
188
  customer_emotion=sentiment.emotion_analysis(client)
189
  customer_sentiment_score = sentiment.analyze_sentiment_for_graph(client)
190
 
191
- agent_emotion=sentiment.emotion_analysis(agent)
192
- agent_sentiment_score = sentiment.analyze_sentiment_for_graph(agent)
193
-
194
- scores=self._text_box(customer_emotion,agent_emotion,agent_sentiment_score,customer_sentiment_score)
195
 
196
  customer_fig=self._display_graph(customer_sentiment_score)
197
  customer_fig.update_layout(title="Sentiment Analysis",width=770)
198
 
199
- agent_fig=self._display_graph(agent_sentiment_score)
200
- agent_fig.update_layout(title="Sentiment Analysis",width=770)
201
-
202
- agent_emotion_score = sentiment.emotion_analysis_for_graph(agent_emotion)
203
-
204
- agent_emotion_fig=self._display_graph(agent_emotion_score)
205
- agent_emotion_fig.update_layout(title="Emotion Analysis",width=770)
206
-
207
  customer_emotion_score = sentiment.emotion_analysis_for_graph(customer_emotion)
208
 
209
  customer_emotion_fig=self._display_graph(customer_emotion_score)
210
  customer_emotion_fig.update_layout(title="Emotion Analysis",width=770)
211
 
212
- return scores,customer_fig,agent_fig,customer_emotion_fig,agent_emotion_fig
213
 
214
 
215
  def clear_func(self):
@@ -255,7 +243,8 @@ class LangChain_Document_QA:
255
  lines=4,
256
  placeholder="Sentiment",
257
  ).style(container=False)
258
-
 
259
  end_btn=gr.Button(
260
  value="End",
261
  )
@@ -270,11 +259,6 @@ class LangChain_Document_QA:
270
  plot =gr.Plot(label="Patient", size=(500, 600))
271
  with gr.Column(scale=0.50, min_width=0):
272
  plot_3 =gr.Plot(label="Patient_Emotion", size=(500, 600))
273
- with gr.Row():
274
- with gr.Column(scale=0.50, min_width=0):
275
- plot_2 =gr.Plot(label="Psychotherapist", size=(500, 600))
276
- with gr.Column(scale=0.50, min_width=0):
277
- plot_4 =gr.Plot(label="Psychotherapist_Emotion", size=(500, 600))
278
 
279
 
280
  txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
@@ -285,7 +269,7 @@ class LangChain_Document_QA:
285
  emptyBtn.click(self.clear_func,[],[])
286
  emptyBtn.click(lambda: None, None, chatbot, queue=False)
287
 
288
- Sentiment_btn.click(self._on_sentiment_btn_click,[],[txt5,plot,plot_2,plot_3,plot_4])
289
 
290
  demo.title = "AI Mental Healthcare ChatBot"
291
  demo.launch()
 
177
 
178
 
179
 
180
+ def _text_box(self,customer_emotion,customer_sentiment_score):
 
181
  customer_score = ", ".join([f"{key}: {value:.2f}" for key, value in customer_sentiment_score.items()])
182
+ return f"customer_emotion:{customer_emotion}\nCustomer_sentiment_score:{customer_score}"
183
 
184
  def _on_sentiment_btn_click(self):
185
+ client=self._history_of_chat()
186
 
187
  customer_emotion=sentiment.emotion_analysis(client)
188
  customer_sentiment_score = sentiment.analyze_sentiment_for_graph(client)
189
 
190
+ scores=self._text_box(customer_emotion,customer_sentiment_score)
 
 
 
191
 
192
  customer_fig=self._display_graph(customer_sentiment_score)
193
  customer_fig.update_layout(title="Sentiment Analysis",width=770)
194
 
 
 
 
 
 
 
 
 
195
  customer_emotion_score = sentiment.emotion_analysis_for_graph(customer_emotion)
196
 
197
  customer_emotion_fig=self._display_graph(customer_emotion_score)
198
  customer_emotion_fig.update_layout(title="Emotion Analysis",width=770)
199
 
200
+ return scores,customer_fig,customer_emotion_fig
201
 
202
 
203
  def clear_func(self):
 
243
  lines=4,
244
  placeholder="Sentiment",
245
  ).style(container=False)
246
+ with gr.Row():
247
+ with gr.Column(scale=0.50, min_width=0):
248
  end_btn=gr.Button(
249
  value="End",
250
  )
 
259
  plot =gr.Plot(label="Patient", size=(500, 600))
260
  with gr.Column(scale=0.50, min_width=0):
261
  plot_3 =gr.Plot(label="Patient_Emotion", size=(500, 600))
 
 
 
 
 
262
 
263
 
264
  txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
 
269
  emptyBtn.click(self.clear_func,[],[])
270
  emptyBtn.click(lambda: None, None, chatbot, queue=False)
271
 
272
+ Sentiment_btn.click(self._on_sentiment_btn_click,[],[txt5,plot,plot_3])
273
 
274
  demo.title = "AI Mental Healthcare ChatBot"
275
  demo.launch()