Zhonathon commited on
Commit
bda8a8b
1 Parent(s): 638f79a

add a chat history box

Browse files
app.py CHANGED
@@ -73,6 +73,8 @@ def start(modelName):
73
  st.session_state['g_t_id'] = 408203
74
  if 'stop' not in st.session_state:
75
  st.session_state['stop'] = 0
 
 
76
  if 'turn' not in st.session_state or st.session_state['stop'] == 1:
77
  st.session_state['turn'] = 0
78
  st.session_state['r_t'] = 0
@@ -103,6 +105,8 @@ def start(modelName):
103
  st.write('ranker ready')
104
  st.session_state['ranker'] = ranker_test
105
 
 
 
106
 
107
  # st.write(st.session_state)
108
  st.write(st.session_state['model'] + ' loaded')
@@ -112,8 +116,6 @@ def start(modelName):
112
  st.session_state['turn'] += 1
113
  st.session_state['r_t'] = int(r_t)
114
  g_t_id = st.session_state['g_t_id']
115
- # st.image(Image.open('./imgs/' + str(g_t_id) + '.jpg').resize((224, 224)), caption='g_t', use_column_width='auto')
116
-
117
 
118
  # st.write(st.session_state)
119
  def model(r_t, fg_t, fp_t):
@@ -178,7 +180,9 @@ def start(modelName):
178
  g_t_id_next = run_model(r_t, fg_t, fp_t)
179
  st.session_state['g_t_id'] = g_t_id_next
180
  # st.write(st.session_state)
181
-
 
 
182
 
183
  fp_t = st.text_input('Input text(positive)', value=' ')
184
  fg_t = st.text_input('Input text(negative)', value=' ')
@@ -188,10 +192,30 @@ def start(modelName):
188
  fg_t = ' '
189
  r_t = st.text_input('Input reward', value='0')
190
  st.button('Interactive', on_click=interactive, args=(r_t, fg_t, fp_t))
 
191
  g_t_id = st.session_state['g_t_id']
192
  st.image(Image.open('./imgs/' + str(g_t_id) + '.jpg'),
193
  caption='g_t_next:' + str(g_t_id), use_column_width='auto')
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
 
197
  def main():
 
73
  st.session_state['g_t_id'] = 408203
74
  if 'stop' not in st.session_state:
75
  st.session_state['stop'] = 0
76
+ if 'chat_history' not in st.session_state or st.session_state['stop'] == 1:
77
+ st.session_state['chat_history'] = []
78
  if 'turn' not in st.session_state or st.session_state['stop'] == 1:
79
  st.session_state['turn'] = 0
80
  st.session_state['r_t'] = 0
 
105
  st.write('ranker ready')
106
  st.session_state['ranker'] = ranker_test
107
 
108
+ def stop():
109
+ st.session_state['stop'] = 1
110
 
111
  # st.write(st.session_state)
112
  st.write(st.session_state['model'] + ' loaded')
 
116
  st.session_state['turn'] += 1
117
  st.session_state['r_t'] = int(r_t)
118
  g_t_id = st.session_state['g_t_id']
 
 
119
 
120
  # st.write(st.session_state)
121
  def model(r_t, fg_t, fp_t):
 
180
  g_t_id_next = run_model(r_t, fg_t, fp_t)
181
  st.session_state['g_t_id'] = g_t_id_next
182
  # st.write(st.session_state)
183
+ st.session_state.chat_history.append(
184
+ {"user": "(positive)" + fp_t + ';(negative)' + fg_t,
185
+ "bot": str(st.session_state['g_t_id']), "reward": r_t})
186
 
187
  fp_t = st.text_input('Input text(positive)', value=' ')
188
  fg_t = st.text_input('Input text(negative)', value=' ')
 
192
  fg_t = ' '
193
  r_t = st.text_input('Input reward', value='0')
194
  st.button('Interactive', on_click=interactive, args=(r_t, fg_t, fp_t))
195
+ st.button('Stop', on_click=stop)
196
  g_t_id = st.session_state['g_t_id']
197
  st.image(Image.open('./imgs/' + str(g_t_id) + '.jpg'),
198
  caption='g_t_next:' + str(g_t_id), use_column_width='auto')
199
 
200
+ for i in range(len(st.session_state.chat_history)):
201
+ st.sidebar.write("User: " + st.session_state.chat_history[i]['user'])
202
+ st.sidebar.write("reward: " + st.session_state.chat_history[i]['reward'])
203
+ st.sidebar.write("turn: " + str(i))
204
+ st.sidebar.write('---------------------------------------------------')
205
+ st.sidebar.image(Image.open('./imgs/' + st.session_state.chat_history[i]['bot'] + '.jpg'),
206
+ caption='g_t_next:' + str(g_t_id), width=224)
207
+ st.sidebar.write('---------------------------------------------------')
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
 
220
 
221
  def main():
recommendation/utils/__pycache__/ranker_1.cpython-38.pyc CHANGED
Binary files a/recommendation/utils/__pycache__/ranker_1.cpython-38.pyc and b/recommendation/utils/__pycache__/ranker_1.cpython-38.pyc differ