Spaces:
Runtime error
Runtime error
Karthikeyan
commited on
Commit
•
cd2d37b
1
Parent(s):
0f31d35
Update app.py
Browse files
app.py
CHANGED
@@ -177,10 +177,10 @@ class LangChain_Document_QA:
|
|
177 |
|
178 |
|
179 |
|
180 |
-
def _text_box(self,customer_emotion,customer_sentiment_score):
|
181 |
-
|
182 |
customer_score = ", ".join([f"{key}: {value:.2f}" for key, value in customer_sentiment_score.items()])
|
183 |
-
return f"customer_emotion:{customer_emotion}\nCustomer_sentiment_score:{customer_score}"
|
184 |
|
185 |
def _on_sentiment_btn_click(self):
|
186 |
client,agent=self._history_of_chat()
|
@@ -188,28 +188,28 @@ class LangChain_Document_QA:
|
|
188 |
customer_emotion=sentiment.emotion_analysis(client)
|
189 |
customer_sentiment_score = sentiment.analyze_sentiment_for_graph(client)
|
190 |
|
191 |
-
|
192 |
-
|
193 |
|
194 |
-
scores=self._text_box(customer_emotion,customer_sentiment_score)
|
195 |
|
196 |
customer_fig=self._display_graph(customer_sentiment_score)
|
197 |
-
customer_fig.update_layout(title="Sentiment Analysis",width=
|
198 |
|
199 |
-
|
200 |
-
|
201 |
|
202 |
-
|
203 |
|
204 |
-
|
205 |
-
|
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=
|
211 |
|
212 |
-
return scores,customer_fig,customer_emotion_fig
|
213 |
|
214 |
|
215 |
def clear_func(self):
|
@@ -255,8 +255,7 @@ class LangChain_Document_QA:
|
|
255 |
lines=4,
|
256 |
placeholder="Sentiment",
|
257 |
).style(container=False)
|
258 |
-
|
259 |
-
with gr.Column(scale=0.50, min_width=0):
|
260 |
end_btn=gr.Button(
|
261 |
value="End",
|
262 |
)
|
@@ -271,7 +270,11 @@ class LangChain_Document_QA:
|
|
271 |
plot =gr.Plot(label="Patient", size=(500, 600))
|
272 |
with gr.Column(scale=0.50, min_width=0):
|
273 |
plot_3 =gr.Plot(label="Patient_Emotion", size=(500, 600))
|
274 |
-
|
|
|
|
|
|
|
|
|
275 |
|
276 |
|
277 |
txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
|
@@ -282,7 +285,7 @@ class LangChain_Document_QA:
|
|
282 |
emptyBtn.click(self.clear_func,[],[])
|
283 |
emptyBtn.click(lambda: None, None, chatbot, queue=False)
|
284 |
|
285 |
-
Sentiment_btn.click(self._on_sentiment_btn_click,[],[txt5,plot,plot_3])
|
286 |
|
287 |
demo.title = "AI Mental Healthcare ChatBot"
|
288 |
demo.launch()
|
|
|
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()
|
|
|
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 |
lines=4,
|
256 |
placeholder="Sentiment",
|
257 |
).style(container=False)
|
258 |
+
|
|
|
259 |
end_btn=gr.Button(
|
260 |
value="End",
|
261 |
)
|
|
|
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 |
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()
|