ajitrajasekharan
commited on
Commit
•
3f2b07b
1
Parent(s):
33d77c3
Update app.py
Browse files
app.py
CHANGED
@@ -88,10 +88,19 @@ def run_test(sent,top_k,model_name):
|
|
88 |
st.stop()
|
89 |
if start is not None:
|
90 |
st.text(f"prediction took {time.time() - start:.2f}s")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
def init_selectbox():
|
93 |
option = st.selectbox(
|
94 |
-
'Choose any of these sentences or type any text below',
|
95 |
('', "[MASK] who lives in New York and works for XCorp suffers from Parkinson's", "Lou Gehrig who lives in [MASK] and works for XCorp suffers from Parkinson's","Lou Gehrig who lives in New York and works for [MASK] suffers from Parkinson's","Lou Gehrig who lives in New York and works for XCorp suffers from [MASK]","[MASK] who lives in New York and works for XCorp suffers from Lou Gehrig's", "Parkinson who lives in [MASK] and works for XCorp suffers from Lou Gehrig's","Parkinson who lives in New York and works for [MASK] suffers from Lou Gehrig's","Parkinson who lives in New York and works for XCorp suffers from [MASK]","Lou Gehrig","Parkinson","Lou Gehrigh's is a [MASK]","Parkinson is a [MASK]","New York is a [MASK]","New York","XCorp","XCorp is a [MASK]","acute lymphoblastic leukemia","acute lymphoblastic leukemia is a [MASK]"))
|
96 |
return option
|
97 |
|
@@ -107,7 +116,6 @@ top_k = st.sidebar.slider("Select how many predictions do you need", 1 , 50, 20)
|
|
107 |
print(top_k)
|
108 |
|
109 |
|
110 |
-
|
111 |
|
112 |
#if st.button("Submit"):
|
113 |
|
@@ -116,18 +124,17 @@ try:
|
|
116 |
|
117 |
model_name = 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'], index=0, key = "model_name")
|
118 |
option = init_selectbox()
|
119 |
-
input_text = st.text_input("Enter text below", "")
|
120 |
custom_model_name = st.text_input("Model not listed on left? Type the model name (fill-mask BERT models only)", "")
|
121 |
if (len(custom_model_name) > 0):
|
122 |
model_name = custom_model_name
|
123 |
st.info("Custom model selected: " + model_name)
|
124 |
bert_tokenizer, bert_model = load_bert_model(model_name)
|
125 |
-
if len(input_text) > 0:
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
run_test(option,top_k,model_name)
|
131 |
if (bert_tokenizer is None):
|
132 |
bert_tokenizer, bert_model = load_bert_model(model_name)
|
133 |
|
|
|
88 |
st.stop()
|
89 |
if start is not None:
|
90 |
st.text(f"prediction took {time.time() - start:.2f}s")
|
91 |
+
|
92 |
+
def on_text_change():
|
93 |
+
global input_text,top_k,model_name
|
94 |
+
run_test(input_text,top_k,model_name)
|
95 |
+
|
96 |
+
def on_option_change():
|
97 |
+
global option,top_k,model_name
|
98 |
+
run_test(option,top_k,model_name)
|
99 |
+
|
100 |
|
101 |
def init_selectbox():
|
102 |
option = st.selectbox(
|
103 |
+
'Choose any of these sentences or type any text below',on_change=on_option_change
|
104 |
('', "[MASK] who lives in New York and works for XCorp suffers from Parkinson's", "Lou Gehrig who lives in [MASK] and works for XCorp suffers from Parkinson's","Lou Gehrig who lives in New York and works for [MASK] suffers from Parkinson's","Lou Gehrig who lives in New York and works for XCorp suffers from [MASK]","[MASK] who lives in New York and works for XCorp suffers from Lou Gehrig's", "Parkinson who lives in [MASK] and works for XCorp suffers from Lou Gehrig's","Parkinson who lives in New York and works for [MASK] suffers from Lou Gehrig's","Parkinson who lives in New York and works for XCorp suffers from [MASK]","Lou Gehrig","Parkinson","Lou Gehrigh's is a [MASK]","Parkinson is a [MASK]","New York is a [MASK]","New York","XCorp","XCorp is a [MASK]","acute lymphoblastic leukemia","acute lymphoblastic leukemia is a [MASK]"))
|
105 |
return option
|
106 |
|
|
|
116 |
print(top_k)
|
117 |
|
118 |
|
|
|
119 |
|
120 |
#if st.button("Submit"):
|
121 |
|
|
|
124 |
|
125 |
model_name = 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'], index=0, key = "model_name")
|
126 |
option = init_selectbox()
|
127 |
+
input_text = st.text_input("Enter text below", "",on_change=on_text_change)
|
128 |
custom_model_name = st.text_input("Model not listed on left? Type the model name (fill-mask BERT models only)", "")
|
129 |
if (len(custom_model_name) > 0):
|
130 |
model_name = custom_model_name
|
131 |
st.info("Custom model selected: " + model_name)
|
132 |
bert_tokenizer, bert_model = load_bert_model(model_name)
|
133 |
+
#if len(input_text) > 0:
|
134 |
+
# run_test(input_text,top_k,model_name)
|
135 |
+
#else:
|
136 |
+
# if len(option) > 0:
|
137 |
+
# run_test(option,top_k,model_name)
|
|
|
138 |
if (bert_tokenizer is None):
|
139 |
bert_tokenizer, bert_model = load_bert_model(model_name)
|
140 |
|