Commit
·
b9f419a
1
Parent(s):
9edc4d0
Update app.py
Browse files
app.py
CHANGED
@@ -60,6 +60,23 @@ def get_bert_prediction(input_text,top_k):
|
|
60 |
return res
|
61 |
except Exception as error:
|
62 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
st.markdown("<h3 style='text-align: center;'>Qualitative evaluation of Pretrained BERT models</h3>", unsafe_allow_html=True)
|
65 |
st.markdown("""
|
@@ -73,7 +90,7 @@ top_k = st.sidebar.slider("Select how many predictions do you need", 1 , 50, 20)
|
|
73 |
print(top_k)
|
74 |
|
75 |
|
76 |
-
|
77 |
#if st.button("Submit"):
|
78 |
|
79 |
# with st.spinner("Computing"):
|
@@ -81,7 +98,7 @@ try:
|
|
81 |
|
82 |
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'], index=0, key = "model_name")
|
83 |
option = st.selectbox(
|
84 |
-
'Choose any of these sentences
|
85 |
('', "[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]'"))
|
86 |
bert_tokenizer, bert_model = load_bert_model(model_name)
|
87 |
default_text = "Imatinib is used to [MASK] nsclc"
|
@@ -89,22 +106,13 @@ try:
|
|
89 |
label="Enter text below",
|
90 |
value=default_text,
|
91 |
)
|
92 |
-
if st.button("Submit")
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
st.caption("Results in JSON")
|
98 |
-
st.json(res)
|
99 |
-
|
100 |
-
except Exception as e:
|
101 |
-
st.error("Some error occurred during prediction" + str(e))
|
102 |
-
st.stop()
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
if start is not None:
|
107 |
-
st.text(f"prediction took {time.time() - start:.2f}s")
|
108 |
|
109 |
except Exception as e:
|
110 |
st.error("Some error occurred during loading" + str(e))
|
|
|
60 |
return res
|
61 |
except Exception as error:
|
62 |
pass
|
63 |
+
|
64 |
+
|
65 |
+
def run_test(sent,top_k):
|
66 |
+
start = None
|
67 |
+
with st.spinner("Computing"):
|
68 |
+
start = time.time()
|
69 |
+
try:
|
70 |
+
res = get_bert_prediction(sent,top_k)
|
71 |
+
st.caption("Results in JSON")
|
72 |
+
st.json(res)
|
73 |
+
|
74 |
+
except Exception as e:
|
75 |
+
st.error("Some error occurred during prediction" + str(e))
|
76 |
+
st.stop()
|
77 |
+
if start is not None:
|
78 |
+
st.text(f"prediction took {time.time() - start:.2f}s")
|
79 |
+
|
80 |
|
81 |
st.markdown("<h3 style='text-align: center;'>Qualitative evaluation of Pretrained BERT models</h3>", unsafe_allow_html=True)
|
82 |
st.markdown("""
|
|
|
90 |
print(top_k)
|
91 |
|
92 |
|
93 |
+
|
94 |
#if st.button("Submit"):
|
95 |
|
96 |
# with st.spinner("Computing"):
|
|
|
98 |
|
99 |
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'], index=0, key = "model_name")
|
100 |
option = st.selectbox(
|
101 |
+
'Choose any of these sentences or type any text below',
|
102 |
('', "[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]'"))
|
103 |
bert_tokenizer, bert_model = load_bert_model(model_name)
|
104 |
default_text = "Imatinib is used to [MASK] nsclc"
|
|
|
106 |
label="Enter text below",
|
107 |
value=default_text,
|
108 |
)
|
109 |
+
if st.button("Submit"):
|
110 |
+
run_test(input_text,top_k)
|
111 |
+
else:
|
112 |
+
if len(option) > 0:
|
113 |
+
run_test(option,top_k)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
+
|
|
|
|
|
116 |
|
117 |
except Exception as e:
|
118 |
st.error("Some error occurred during loading" + str(e))
|