山越貴耀 commited on
Commit
dc95541
1 Parent(s): 2d56324

multiclicks

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -123,6 +123,15 @@ def pre_render_images(df,input_sent_id):
123
  fig_list.append(img)
124
  return sent_list,fig_list
125
 
 
 
 
 
 
 
 
 
 
126
 
127
  if __name__=='__main__':
128
  # Config
@@ -186,8 +195,8 @@ if __name__=='__main__':
186
 
187
  if 'df' in st.session_state:
188
  df = st.session_state.df
189
- sent_id = st.sidebar.slider(label='2. Select a position in the chain to start exploring',
190
- min_value=0,max_value=len(df)-1,value=0)
191
 
192
  if input_type=='Use one of the example sentences':
193
  explore_type = st.sidebar.radio('3. Choose the way to explore',options=['In fixed increments','Click through each step','Autoplay'])
@@ -221,12 +230,14 @@ if __name__=='__main__':
221
  st.video(f)
222
  else:
223
  if explore_type=='In fixed increments':
224
- button_labels = ['-500','-100','-10','-1','0','+1','+10','+100','+500']
225
- increment = st.sidebar.radio(label='select increment',options=button_labels,index=4)
226
- sent_id += int(increment.replace('+',''))
227
- sent_id = min(len(df)-1,max(0,sent_id))
 
 
228
  elif explore_type=='Click through each step':
229
- sent_id = st.sidebar.number_input(label='step number',value=sent_id)
230
 
231
  x_tsne, y_tsne = df.x_tsne, df.y_tsne
232
  xscale_unit = (max(x_tsne)-min(x_tsne))/10
@@ -235,6 +246,7 @@ if __name__=='__main__':
235
  ylims = [(min(y_tsne)//yscale_unit-1)*yscale_unit,(max(y_tsne)//yscale_unit+1)*yscale_unit]
236
  color_list = sns.color_palette('flare',n_colors=int(len(df)*1.2))
237
 
 
238
  fig = plt.figure(figsize=(5,5),dpi=200)
239
  ax = fig.add_subplot(1,1,1)
240
  ax.plot(x_tsne[:sent_id+1],y_tsne[:sent_id+1],linewidth=0.2,color='gray',zorder=1)
 
123
  fig_list.append(img)
124
  return sent_list,fig_list
125
 
126
+ def update_sent_id(increment_value=0):
127
+ sent_id = st.session_state.sent_id
128
+ sent_id += increment_value
129
+ sent_id = min(len(st.session_state.df)-1,max(0,sent_id))
130
+ st.session_state.sent_id = sent_id
131
+
132
+ def initialize_sent_id():
133
+ st.session_state.sent_id = st.session_state.sent_id_from_slider
134
+
135
 
136
  if __name__=='__main__':
137
  # Config
 
195
 
196
  if 'df' in st.session_state:
197
  df = st.session_state.df
198
+ st.sidebar.slider(label='2. Select a position in the chain to start exploring',
199
+ min_value=0,max_value=len(df)-1,value=0,key='sent_id_from_slider')
200
 
201
  if input_type=='Use one of the example sentences':
202
  explore_type = st.sidebar.radio('3. Choose the way to explore',options=['In fixed increments','Click through each step','Autoplay'])
 
230
  st.video(f)
231
  else:
232
  if explore_type=='In fixed increments':
233
+ button_options = [-500,-100,-10,-1,1,10,100,500]
234
+ button_labels = ['-500','-100','-10','-1','+1','+10','+100','+500']
235
+ cols = st.sidebar.columns(len(button_options))
236
+ for col_id,col in enumerate(cols):
237
+ with col:
238
+ st.button(button_labels[col_id],on_click=update_sent_id,kwargs=dict(increment_value=button_options[col_id]))
239
  elif explore_type=='Click through each step':
240
+ st.session_state.sent_id = st.sidebar.number_input(label='step number',value=sent_id)
241
 
242
  x_tsne, y_tsne = df.x_tsne, df.y_tsne
243
  xscale_unit = (max(x_tsne)-min(x_tsne))/10
 
246
  ylims = [(min(y_tsne)//yscale_unit-1)*yscale_unit,(max(y_tsne)//yscale_unit+1)*yscale_unit]
247
  color_list = sns.color_palette('flare',n_colors=int(len(df)*1.2))
248
 
249
+ sent_id = st.session_state.sent_id
250
  fig = plt.figure(figsize=(5,5),dpi=200)
251
  ax = fig.add_subplot(1,1,1)
252
  ax.plot(x_tsne[:sent_id+1],y_tsne[:sent_id+1],linewidth=0.2,color='gray',zorder=1)