taka-yamakoshi commited on
Commit
2b66ae3
1 Parent(s): 6316b49
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -64,16 +64,16 @@ def annotate_mask(sent_id,sent):
64
  decoded_sent = [tokenizer.decode([token]) for token in input_sent[1:-1]]
65
  char_nums = [len(word)+2 for word in decoded_sent]
66
  cols = st.columns(char_nums)
67
- mask_locs = []
 
68
  for word_id,(col,word) in enumerate(zip(cols,decoded_sent)):
69
  with col:
70
  if st.button(word,key=f'word_{sent_id}_{word_id}'):
71
- if word_id not in mask_locs:
72
- mask_locs.append(word_id)
73
  else:
74
- mask_locs.remove(word_id)
75
- st.markdown(show_annotated_sentence(decoded_sent,mask_locs=mask_locs), unsafe_allow_html = True)
76
- st.session_state[f'mask_locs_{sent_id}'] = mask_locs
77
 
78
  def annotate_options(sent_id,sent):
79
  st.write(f'Sentence {sent_id}')
@@ -136,10 +136,8 @@ if __name__=='__main__':
136
  sent_2 = st.session_state['sent_2']
137
 
138
  st.write('2. Select sites to mask out and click "Confirm"')
139
- with empty():
140
- annotate_mask(1,sent_1)
141
- with empty():
142
- annotate_mask(2,sent_2)
143
  st.write(st.session_state['mask_locs_1'])
144
  st.write(st.session_state['mask_locs_2'])
145
  if st.button('Confirm'):
 
64
  decoded_sent = [tokenizer.decode([token]) for token in input_sent[1:-1]]
65
  char_nums = [len(word)+2 for word in decoded_sent]
66
  cols = st.columns(char_nums)
67
+ if f'mask_locs_{sent_id}' not in st.session_state:
68
+ st.session_state[f'mask_locs_{sent_id}'] = []
69
  for word_id,(col,word) in enumerate(zip(cols,decoded_sent)):
70
  with col:
71
  if st.button(word,key=f'word_{sent_id}_{word_id}'):
72
+ if word_id not in st.session_state[f'mask_locs_{sent_id}']:
73
+ st.session_state[f'mask_locs_{sent_id}'].append(word_id)
74
  else:
75
+ st.session_state[f'mask_locs_{sent_id}'].remove(word_id)
76
+ st.markdown(show_annotated_sentence(decoded_sent,mask_locs=st.session_state[f'mask_locs_{sent_id}']), unsafe_allow_html = True)
 
77
 
78
  def annotate_options(sent_id,sent):
79
  st.write(f'Sentence {sent_id}')
 
136
  sent_2 = st.session_state['sent_2']
137
 
138
  st.write('2. Select sites to mask out and click "Confirm"')
139
+ annotate_mask(1,sent_1)
140
+ annotate_mask(2,sent_2)
 
 
141
  st.write(st.session_state['mask_locs_1'])
142
  st.write(st.session_state['mask_locs_2'])
143
  if st.button('Confirm'):