jitesh commited on
Commit
5d1e3ac
1 Parent(s): 877913f

adds "turn" column

Browse files
Files changed (3) hide show
  1. app.py +2 -1
  2. requirements.txt +2 -1
  3. story_gen.py +25 -13
app.py CHANGED
@@ -64,7 +64,8 @@ if mode == 'Create Statistics':
64
  for si, story in enumerate(gen.data):
65
  st.markdown(f'### Story no. {si}:', unsafe_allow_html=False)
66
  for i, sentence in enumerate(story):
67
- col_sentence, col_emo = st.columns([3,1])
 
68
  col_sentence.markdown(sentence['sentence'], unsafe_allow_html=False)
69
  col_emo.markdown(f'{sentence["emotion"]} {np.round(sentence["confidence_score"], 3)}', unsafe_allow_html=False)
70
  st.table(data=gen.stats_df, )
 
64
  for si, story in enumerate(gen.data):
65
  st.markdown(f'### Story no. {si}:', unsafe_allow_html=False)
66
  for i, sentence in enumerate(story):
67
+ col_turn, col_sentence, col_emo = st.columns([1,8,2])
68
+ col_turn.markdown(sentence['turn'], unsafe_allow_html=False)
69
  col_sentence.markdown(sentence['sentence'], unsafe_allow_html=False)
70
  col_emo.markdown(f'{sentence["emotion"]} {np.round(sentence["confidence_score"], 3)}', unsafe_allow_html=False)
71
  st.table(data=gen.stats_df, )
requirements.txt CHANGED
@@ -7,4 +7,5 @@ numpy==1.22.2
7
  nltk==3.7
8
  xlsxwriter==3.0.2
9
  plotly
10
- seaborn
 
 
7
  nltk==3.7
8
  xlsxwriter==3.0.2
9
  plotly
10
+ seaborn
11
+ # streamlit
story_gen.py CHANGED
@@ -117,6 +117,17 @@ class StoryGenerator:
117
  'emotion': emotion_user['label'],
118
  'confidence_score': emotion_user['score'],
119
  })
 
 
 
 
 
 
 
 
 
 
 
120
  # Text generation for Robot
121
  last_length = len(story_till_now)
122
  printj.cyan(story_till_now)
@@ -125,26 +136,27 @@ class StoryGenerator:
125
  genreate_robot_sentence = self.generator(story_till_now, max_length=self.get_num_token(
126
  story_till_now)+length, num_return_sequences=1)
127
  story_till_now = genreate_robot_sentence[0]['generated_text']
128
- new_sentence = story_till_now[last_length:]
129
- emotion = self.get_emotion(new_sentence)
130
 
131
  story_data.append({
132
- 'sentence': new_sentence,
133
  'turn': 'robot',
134
- 'emotion': emotion['label'],
135
- 'confidence_score': emotion['score'],
136
  })
137
-
138
  stats_dict['sentence_no'] = i
139
- stats_dict['sentence'] = new_sentence_user
140
- stats_dict['show_emotion'] = show_emotion_user
141
- stats_dict['emotion_label'] = emotion_user['label']
142
- stats_dict['emotion_score'] = emotion_user['score']
143
- stats_dict['num_reactions'] = num_reactions
144
- stats_dict['reaction_frequency'] = reaction_frequency
145
- stats_dict['reaction_weight'] = reaction_weight
 
146
  stats_df = pd.concat(
147
  [stats_df, pd.DataFrame(stats_dict, index=[f'idx_{i}'])])
 
148
  return stats_df, story_till_now, story_data
149
 
150
  def get_stats(self,
 
117
  'emotion': emotion_user['label'],
118
  'confidence_score': emotion_user['score'],
119
  })
120
+ stats_dict['sentence_no'] = i
121
+ stats_dict['turn'] = 'user'
122
+ stats_dict['sentence'] = new_sentence_user
123
+ stats_dict['show_emotion'] = show_emotion_user
124
+ stats_dict['emotion_label'] = emotion_user['label']
125
+ stats_dict['emotion_score'] = emotion_user['score']
126
+ stats_dict['num_reactions'] = num_reactions
127
+ stats_dict['reaction_frequency'] = reaction_frequency
128
+ stats_dict['reaction_weight'] = reaction_weight
129
+ stats_df = pd.concat(
130
+ [stats_df, pd.DataFrame(stats_dict, index=[f'idx_{i}'])])
131
  # Text generation for Robot
132
  last_length = len(story_till_now)
133
  printj.cyan(story_till_now)
 
136
  genreate_robot_sentence = self.generator(story_till_now, max_length=self.get_num_token(
137
  story_till_now)+length, num_return_sequences=1)
138
  story_till_now = genreate_robot_sentence[0]['generated_text']
139
+ new_sentence_robot = story_till_now[last_length:]
140
+ emotion_robot = self.get_emotion(new_sentence_robot)
141
 
142
  story_data.append({
143
+ 'sentence': new_sentence_robot,
144
  'turn': 'robot',
145
+ 'emotion': emotion_robot['label'],
146
+ 'confidence_score': emotion_robot['score'],
147
  })
 
148
  stats_dict['sentence_no'] = i
149
+ stats_dict['turn'] = 'robot'
150
+ stats_dict['sentence'] = new_sentence_robot
151
+ stats_dict['show_emotion'] = None
152
+ stats_dict['emotion_label'] = emotion_robot['label']
153
+ stats_dict['emotion_score'] = emotion_robot['score']
154
+ stats_dict['num_reactions'] = None
155
+ stats_dict['reaction_frequency'] = None
156
+ stats_dict['reaction_weight'] = None
157
  stats_df = pd.concat(
158
  [stats_df, pd.DataFrame(stats_dict, index=[f'idx_{i}'])])
159
+
160
  return stats_df, story_till_now, story_data
161
 
162
  def get_stats(self,