Spaces:
Sleeping
Sleeping
山越貴耀
commited on
Commit
•
a4a2091
1
Parent(s):
f238964
fixed multiclick
Browse files
app.py
CHANGED
@@ -175,7 +175,7 @@ if __name__=='__main__':
|
|
175 |
|
176 |
if input_type=='Use one of the example sentences':
|
177 |
sentence = st.sidebar.selectbox("Select the inital sentence",
|
178 |
-
('
|
179 |
'About 170 campers attend the camps each week.',
|
180 |
'She grew up with three brothers and ten sisters.'))
|
181 |
if sentence!='--Please select one from below--':
|
@@ -233,19 +233,19 @@ if __name__=='__main__':
|
|
233 |
else:
|
234 |
if explore_type=='In fixed increments':
|
235 |
button_labels = ['+1','+10','+100','+500']
|
236 |
-
cols = st.sidebar.columns([
|
237 |
for col_id,col in enumerate(cols):
|
238 |
with col:
|
239 |
st.button(button_labels[col_id],key=button_labels[col_id],
|
240 |
on_click=update_sent_id,kwargs=dict(increment_value=int(button_labels[col_id].replace('+',''))))
|
241 |
button_labels = ['-1','-10','-100','-500']
|
242 |
-
cols = st.sidebar.columns([
|
243 |
for col_id,col in enumerate(cols):
|
244 |
with col:
|
245 |
st.button(button_labels[col_id],key=button_labels[col_id],
|
246 |
on_click=update_sent_id,kwargs=dict(increment_value=int(button_labels[col_id].replace('+',''))))
|
247 |
elif explore_type=='Click through each step':
|
248 |
-
st.session_state.sent_id = st.sidebar.number_input(label='step number',value=
|
249 |
|
250 |
x_tsne, y_tsne = df.x_tsne, df.y_tsne
|
251 |
xscale_unit = (max(x_tsne)-min(x_tsne))/10
|
@@ -282,15 +282,17 @@ if __name__=='__main__':
|
|
282 |
_,candidates_df = sample_words(probs, word_id+1, input_sent)
|
283 |
st.table(candidates_df)
|
284 |
else:
|
285 |
-
disp_style = '"font-family:san serif; color:Black; font-size: 20px
|
286 |
if explore_type=='Click through each step' and input_type=='Use your own initial sentence' and sent_id>0 and 'finished_sampling' in st.session_state:
|
287 |
sampled_loc = df.next_sample_loc.to_list()[sent_id-1]
|
288 |
-
|
|
|
289 |
new_word = f'<span style="color:Red">{decoded_sent[sampled_loc]}</span>'
|
290 |
-
disp_sent_after = ' '.join(decoded_sent[sampled_loc+1:-1])+'</p>'
|
291 |
st.markdown(disp_sent_before+' '+new_word+' '+disp_sent_after,unsafe_allow_html=True)
|
292 |
else:
|
293 |
-
|
|
|
294 |
cols = st.columns([1,2,1])
|
295 |
with cols[1]:
|
296 |
st.pyplot(fig)
|
|
|
175 |
|
176 |
if input_type=='Use one of the example sentences':
|
177 |
sentence = st.sidebar.selectbox("Select the inital sentence",
|
178 |
+
('--- Please select one from below ---',
|
179 |
'About 170 campers attend the camps each week.',
|
180 |
'She grew up with three brothers and ten sisters.'))
|
181 |
if sentence!='--Please select one from below--':
|
|
|
233 |
else:
|
234 |
if explore_type=='In fixed increments':
|
235 |
button_labels = ['+1','+10','+100','+500']
|
236 |
+
cols = st.sidebar.columns([4,5,6,6])
|
237 |
for col_id,col in enumerate(cols):
|
238 |
with col:
|
239 |
st.button(button_labels[col_id],key=button_labels[col_id],
|
240 |
on_click=update_sent_id,kwargs=dict(increment_value=int(button_labels[col_id].replace('+',''))))
|
241 |
button_labels = ['-1','-10','-100','-500']
|
242 |
+
cols = st.sidebar.columns([4,5,6,6])
|
243 |
for col_id,col in enumerate(cols):
|
244 |
with col:
|
245 |
st.button(button_labels[col_id],key=button_labels[col_id],
|
246 |
on_click=update_sent_id,kwargs=dict(increment_value=int(button_labels[col_id].replace('+',''))))
|
247 |
elif explore_type=='Click through each step':
|
248 |
+
st.session_state.sent_id = st.sidebar.number_input(label='step number',value=st.session_state.sent_id_from_slider)
|
249 |
|
250 |
x_tsne, y_tsne = df.x_tsne, df.y_tsne
|
251 |
xscale_unit = (max(x_tsne)-min(x_tsne))/10
|
|
|
282 |
_,candidates_df = sample_words(probs, word_id+1, input_sent)
|
283 |
st.table(candidates_df)
|
284 |
else:
|
285 |
+
disp_style = '"font-family:san serif; color:Black; font-size: 20px"'
|
286 |
if explore_type=='Click through each step' and input_type=='Use your own initial sentence' and sent_id>0 and 'finished_sampling' in st.session_state:
|
287 |
sampled_loc = df.next_sample_loc.to_list()[sent_id-1]
|
288 |
+
disp_step = f'<p style={disp_style}>Step {st.session_state.sent_id}: '
|
289 |
+
disp_sent_before = f'{disp_step}<span style="font-weight:bold">'+' '.join(decoded_sent[1:sampled_loc])
|
290 |
new_word = f'<span style="color:Red">{decoded_sent[sampled_loc]}</span>'
|
291 |
+
disp_sent_after = ' '.join(decoded_sent[sampled_loc+1:-1])+'</span></p>'
|
292 |
st.markdown(disp_sent_before+' '+new_word+' '+disp_sent_after,unsafe_allow_html=True)
|
293 |
else:
|
294 |
+
disp_step = f'<p style={disp_style}>Step {st.session_state.sent_id}'
|
295 |
+
st.markdown(f'{disp_step}<span style="font-weight:bold">{sentence}</span></p>',unsafe_allow_html=True)
|
296 |
cols = st.columns([1,2,1])
|
297 |
with cols[1]:
|
298 |
st.pyplot(fig)
|