Karthikeyan commited on
Commit
d831be2
1 Parent(s): d28eb66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -56,20 +56,12 @@ class SentimentAnalyzer:
56
  return sentiment_scores
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_str = emotions_match.group(1)
69
- emotions = emotions_str.split(', ')
70
- scores_match = re.search(r'\[(.*?)\]', text, re.DOTALL)
71
- scores_str = scores_match.group(1)
72
- scores = list(map(float, scores_str.split(', ')))
73
  score_dict={"Emotion": emotions, "Score": scores}
74
  print(score_dict)
75
  return score_dict
 
56
  return sentiment_scores
57
 
58
  def emotion_analysis_for_graph(self,text):
59
+ start_index = text.find("[")
60
+ end_index = text.find("]")
61
+ list1_text = text[start_index + 1: end_index]
62
+ list2_text = text[end_index + 2:-1]
63
+ emotions = list(map(str.strip, list1_text.split(",")))
64
+ scores = list(map(float, list2_text.split(",")))
 
 
 
 
 
 
 
 
65
  score_dict={"Emotion": emotions, "Score": scores}
66
  print(score_dict)
67
  return score_dict