taka-yamakoshi commited on
Commit
8f32fbf
1 Parent(s): 8616365

show sentence

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -58,6 +58,21 @@ def clear_data():
58
  for key in st.session_state:
59
  del st.session_state[key]
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  if __name__=='__main__':
62
  wide_setup()
63
  load_css('style.css')
@@ -101,7 +116,7 @@ if __name__=='__main__':
101
  st.session_state['masked_pos_1'].append(word_id)
102
  else:
103
  st.session_state['masked_pos_1'].remove(word_id)
104
- st.write(f'Masked words: {", ".join([decoded_sent[word_id] for word_id in np.sort(st.session_state["masked_pos_1"])])}')
105
 
106
 
107
  if st.session_state['page_status']=='analysis':
 
58
  for key in st.session_state:
59
  del st.session_state[key]
60
 
61
+ def show_annotated_sentence(sent,option_locs=[],mask_locs=[]):
62
+ disp_style = '"font-family:san serif; color:Black; font-size: 20px"'
63
+ prefix = f'<p style={disp_style}><span style="font-weight:bold">'
64
+ style_list = []
65
+ for i, word in enumerate(sent):
66
+ if i in mask_locs:
67
+ style_list.append(f'<span style="color:Red">{word}</span>')
68
+ elif i in option_locs:
69
+ style_list.append(f'<span style="color:Blue">{word}</span>')
70
+ else:
71
+ style_list.append(f'{word}')
72
+ disp = ' '.join(style_list)
73
+ suffix = '</span></p>'
74
+ return prefix + disp + suffix
75
+
76
  if __name__=='__main__':
77
  wide_setup()
78
  load_css('style.css')
 
116
  st.session_state['masked_pos_1'].append(word_id)
117
  else:
118
  st.session_state['masked_pos_1'].remove(word_id)
119
+ st.markdown(show_annotated_sentence(decoded_sent,mask_locs=st.session_state['masked_pos_1']), unsafe_allow_html = True)
120
 
121
 
122
  if st.session_state['page_status']=='analysis':