Karthikeyan commited on
Commit
921625c
1 Parent(s): f738eef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -9
app.py CHANGED
@@ -26,7 +26,7 @@ class SentimentAnalyzer:
26
  return sentiment_scores_str
27
  def emotion_analysis(self,text):
28
  prompt = f""" Your task is find the top 1 emotion : <Sadness, Happiness, Joy, Fear, Disgust, Anger> and it's emotion score of the text.\
29
- your are analyze the text and provide the output in the following dict format: '''emotions: scores''' [with top 1 result having the highest score]
30
  The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion.\
31
  analyze the text : '''{text}'''
32
  """
@@ -57,12 +57,19 @@ class SentimentAnalyzer:
57
 
58
  def emotion_analysis_for_graph(self,text):
59
 
60
- list_of_emotion=text.split(":")
61
- label=list_of_emotion[0]
62
- score=list_of_emotion[1]
63
- score_dict={
64
- label:score
65
- }
 
 
 
 
 
 
 
66
  print(score_dict)
67
  return score_dict
68
 
@@ -128,7 +135,11 @@ class LangChain_Document_QA:
128
  fig.update_traces(texttemplate='%{x:.2f}%', textposition='outside')
129
  fig.update_layout(height=500, width=200)
130
  return fig
131
-
 
 
 
 
132
  def _history_of_chat(self):
133
  history = history_state.value
134
  formatted_history = ""
@@ -199,7 +210,7 @@ class LangChain_Document_QA:
199
 
200
  customer_emotion_score = sentiment.emotion_analysis_for_graph(customer_emotion)
201
 
202
- customer_emotion_fig=self._display_graph(customer_emotion_score)
203
  customer_emotion_fig.update_layout(title="Emotion Analysis",width=770)
204
  print("scores :{}",scores)
205
  print("customer_fig :{}",customer_fig)
 
26
  return sentiment_scores_str
27
  def emotion_analysis(self,text):
28
  prompt = f""" Your task is find the top 1 emotion : <Sadness, Happiness, Joy, Fear, Disgust, Anger> and it's emotion score of the text.\
29
+ your are analyze the text and provide the output in the following list format: [emotions][scores]''' [with top 1 result having the highest score]
30
  The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion.\
31
  analyze the text : '''{text}'''
32
  """
 
57
 
58
  def emotion_analysis_for_graph(self,text):
59
 
60
+ # list_of_emotion=text.split(":")
61
+ # label=list_of_emotion[0]
62
+ # score=list_of_emotion[1]
63
+ # score_dict={
64
+ # label:score
65
+ # }
66
+ # print(score_dict)
67
+ emotions_match = re.search(r"<(.*?)>", text)
68
+ emotions = emotions_match.group(1).split(", ")
69
+ scores_match = re.search(r"\[.*?\]\[(.*?)\]", text)
70
+ scores = scores_match.group(1).split(", ")
71
+ scores = [float(score.strip()) for score in scores]
72
+ score_dict={"Emotion": emotions, "Score": scores}
73
  print(score_dict)
74
  return score_dict
75
 
 
135
  fig.update_traces(texttemplate='%{x:.2f}%', textposition='outside')
136
  fig.update_layout(height=500, width=200)
137
  return fig
138
+ def _display_graph_emotion(self,customer_emotion_score)
139
+ fig = px.pie(customer_emotion_score, values='Score', names='Emotion', title='Emotion Distribution')
140
+ fig.update_traces(texttemplate='%{x:.2f}%', textposition='outside')
141
+ fig.update_layout(height=500, width=200)
142
+ return fig
143
  def _history_of_chat(self):
144
  history = history_state.value
145
  formatted_history = ""
 
210
 
211
  customer_emotion_score = sentiment.emotion_analysis_for_graph(customer_emotion)
212
 
213
+ customer_emotion_fig=self._display_graph_emotion(customer_emotion_score)
214
  customer_emotion_fig.update_layout(title="Emotion Analysis",width=770)
215
  print("scores :{}",scores)
216
  print("customer_fig :{}",customer_fig)