Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ from transformers import AutoTokenizer, AutoModel, AutoModelForSequenceClassific
|
|
| 4 |
from safetensors.torch import load_file as safe_load
|
| 5 |
|
| 6 |
target_to_ind = {'cs': 0, 'econ': 1, 'eess': 2, 'math': 3, 'phys': 4, 'q-bio': 5, 'q-fin': 6, 'stat': 7}
|
|
|
|
|
|
|
| 7 |
ind_to_target = {ind: target for target, ind in target_to_ind.items()}
|
| 8 |
|
| 9 |
|
|
@@ -42,14 +44,24 @@ def get_predict(title: str, abstract: str) -> (str, float, dict):
|
|
| 42 |
title = st.text_area("Title ", "", height=100)
|
| 43 |
abstract = st.text_area("Abstract ", "", height=150)
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
if len(title) == 0:
|
| 47 |
st.error("Please, provide paper's title")
|
| 48 |
else:
|
| 49 |
with st.spinner("Be patient, I'm doing my best"):
|
| 50 |
predict = get_predict(title, abstract)
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from safetensors.torch import load_file as safe_load
|
| 5 |
|
| 6 |
target_to_ind = {'cs': 0, 'econ': 1, 'eess': 2, 'math': 3, 'phys': 4, 'q-bio': 5, 'q-fin': 6, 'stat': 7}
|
| 7 |
+
target_to_label = {'cs': 'Computer Science', 'econ': 'Economics', 'eess': 'Electrical Engineering and Systems Science', 'math': 'Mathematics', 'phys': 'Physics',
|
| 8 |
+
'q-bio': 'Quantitative Biology', 'q-fin': 'Quantitative Finance', 'stat': 'Statistics'}
|
| 9 |
ind_to_target = {ind: target for target, ind in target_to_ind.items()}
|
| 10 |
|
| 11 |
|
|
|
|
| 44 |
title = st.text_area("Title ", "", height=100)
|
| 45 |
abstract = st.text_area("Abstract ", "", height=150)
|
| 46 |
|
| 47 |
+
|
| 48 |
+
mode = st.radio("Mode: ", ("Best prediction", "Top 95%"))
|
| 49 |
+
|
| 50 |
+
if st.button("Get prediction", key="manual"):
|
| 51 |
if len(title) == 0:
|
| 52 |
st.error("Please, provide paper's title")
|
| 53 |
else:
|
| 54 |
with st.spinner("Be patient, I'm doing my best"):
|
| 55 |
predict = get_predict(title, abstract)
|
| 56 |
+
|
| 57 |
+
tags = []
|
| 58 |
+
threshold = 0 if status == "Best prediction" else 0.95
|
| 59 |
+
sum_p = 0
|
| 60 |
+
for p, tag in predict:
|
| 61 |
+
sum_p += p
|
| 62 |
+
tags.append(target_to_label[tag])
|
| 63 |
+
|
| 64 |
+
if sum_p >= threshold:
|
| 65 |
+
break
|
| 66 |
+
|
| 67 |
+
st.succes(f"{'\n'.join(tags)}")
|