ajitrajasekharan commited on
Commit
24b81ce
·
1 Parent(s): 0d25a6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -95,15 +95,12 @@ def on_results_count_change():
95
  st.session_state['top_k'] = int(st.session_state.my_slider)
96
  st.info("Results count changed " + str(st.session_state['top_k']))
97
 
98
- def on_model_change1():
99
- st.session_state['model_name'] = st.session_state.my_model1
100
- st.info("Pre-selected model chosen: " + st.session_state['model_name'])
101
- st.session_state['bert_tokenizer'], st.session_state['bert_model'] = load_bert_model(st.session_state['model_name'])
102
-
103
- def on_model_change2(model_name):
104
- st.session_state['model_name'] = model_name
105
- st.info("Custom model chosen: " + st.session_state['model_name'])
106
- st.session_state['bert_tokenizer'], st.session_state['bert_model'] = load_bert_model(st.session_state['model_name'])
107
 
108
  def init_selectbox():
109
  return st.selectbox(
@@ -134,35 +131,32 @@ def main():
134
  st.write(" - To examine fill-mask predictions, enter the token [MASK] or <mask> in a sentence")
135
  st.write(" - To examine just the [CLS] vector, enter a word/phrase or sentence. Example: eGFR or EGFR or non small cell lung cancer")
136
  st.write("Pretrained BERT models from three domains (biomedical,PHI [person,location,org, etc.], and legal) are listed on the left. Their performance on domain specific sentences reveal both their strength and weakness.")
137
- st.sidebar.slider("Select count of predictions to display", 1 , 50, 20,key='my_slider',on_change=on_results_count_change) #some times it is possible to have less words
138
 
139
 
140
  try:
141
- st.sidebar.selectbox(label='Select Model to Apply', options=['ajitrajasekharan/biomedical', 'bert-base-cased','bert-large-cased','microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext','allenai/scibert_scivocab_cased','dmis-lab/biobert-v1.1','nlpaueb/legal-bert-base-uncased'], index=0, key = "my_model1",on_change=on_model_change1)
142
-
143
-
144
-
145
-
146
-
147
 
148
- #if (st.session_state['bert_tokenizer'] is None):
149
- # st.session_state['bert_tokenizer'], st.session_state['bert_model'] = load_bert_model(st.session_state['model_name'])
150
 
151
  with st.form('my_form'):
152
  selected_sentence = init_selectbox()
153
  text_input = st.text_input("Type any sentence below", "",key='my_text')
154
- custom_model_selection = st.text_input("Model not listed on left? Type the model name (**fill-mask BERT models only**)", "",key="my_model2")
 
 
155
  submit_button = st.form_submit_button('Submit')
156
 
157
  input_status_area = st.empty()
158
  display_area = st.empty()
159
- display_area.text("Current selections: results count = " + str(st.session_state['top_k']) + ";" + " Model name = " + st.session_state['model_name'])
160
  if submit_button:
161
  start = time.time()
162
  if (len(text_input) == 0):
163
  text_input = selected_sentence
 
164
  if (len(custom_model_selection) != 0):
165
- on_model_change2(custom_model_selection)
 
 
 
166
  input_status_area.text("Input sentence: " + text_input)
167
  results = on_text_change(text_input,display_area)
168
  display_area.empty()
 
95
  st.session_state['top_k'] = int(st.session_state.my_slider)
96
  st.info("Results count changed " + str(st.session_state['top_k']))
97
 
98
+
99
+ def on_model_change(model_name):
100
+ if (model_name != st.session_state['model_name']):
101
+ st.session_state['model_name'] = model_name
102
+ st.info("Custom model chosen: " + st.session_state['model_name'])
103
+ st.session_state['bert_tokenizer'], st.session_state['bert_model'] = load_bert_model(st.session_state['model_name'])
 
 
 
104
 
105
  def init_selectbox():
106
  return st.selectbox(
 
131
  st.write(" - To examine fill-mask predictions, enter the token [MASK] or <mask> in a sentence")
132
  st.write(" - To examine just the [CLS] vector, enter a word/phrase or sentence. Example: eGFR or EGFR or non small cell lung cancer")
133
  st.write("Pretrained BERT models from three domains (biomedical,PHI [person,location,org, etc.], and legal) are listed on the left. Their performance on domain specific sentences reveal both their strength and weakness.")
134
+
135
 
136
 
137
  try:
 
 
 
 
 
 
138
 
 
 
139
 
140
  with st.form('my_form'):
141
  selected_sentence = init_selectbox()
142
  text_input = st.text_input("Type any sentence below", "",key='my_text')
143
+ selected_model = st.selectbox(label='Select Model to Apply', options=['ajitrajasekharan/biomedical', 'bert-base-cased','bert-large-cased','microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract-fulltext','allenai/scibert_scivocab_cased','dmis-lab/biobert-v1.1','nlpaueb/legal-bert-base-uncased'], index=0, key = "my_model1")
144
+ custom_model_selection = st.text_input("Model not listed on above? Type the model name (**fill-mask BERT models only**)", "",key="my_model2")
145
+ results_count = st.slider("Select count of predictions to display", 1 , 50, 20,key='my_slider') #some times it is possible to have less words
146
  submit_button = st.form_submit_button('Submit')
147
 
148
  input_status_area = st.empty()
149
  display_area = st.empty()
 
150
  if submit_button:
151
  start = time.time()
152
  if (len(text_input) == 0):
153
  text_input = selected_sentence
154
+ st.session_state['top_k'] = results_count
155
  if (len(custom_model_selection) != 0):
156
+ on_model_change(custom_model_selection)
157
+ else:
158
+ on_model_change(selected_model)
159
+
160
  input_status_area.text("Input sentence: " + text_input)
161
  results = on_text_change(text_input,display_area)
162
  display_area.empty()