Update app.py
Browse files
app.py
CHANGED
@@ -68,7 +68,7 @@ def predict(text, model, human_readable=True):
|
|
68 |
if not human_readable:
|
69 |
answer.append(result[index][1])
|
70 |
else:
|
71 |
-
answer.append(labels_description[result[index][1]] + " {:.2f}%".format(100 * result[index][0]))
|
72 |
index += 1
|
73 |
|
74 |
return answer
|
@@ -78,17 +78,27 @@ tokenizer = DistilBertTokenizer.from_pretrained(vocab_path)
|
|
78 |
model = torch.load(model_path, map_location=torch.device(device))
|
79 |
|
80 |
st.markdown("### Hi! This is a service for determining the subject of an article.")
|
81 |
-
st.
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
|
85 |
|
86 |
-
|
87 |
|
88 |
if st.button('Analyse'):
|
89 |
with st.spinner("Wait..."):
|
90 |
-
if
|
91 |
-
|
92 |
-
|
|
|
93 |
else:
|
94 |
-
|
|
|
|
68 |
if not human_readable:
|
69 |
answer.append(result[index][1])
|
70 |
else:
|
71 |
+
answer.append(labels_description[result[index][1]] + " - {:.2f}%".format(100 * result[index][0]))
|
72 |
index += 1
|
73 |
|
74 |
return answer
|
|
|
78 |
model = torch.load(model_path, map_location=torch.device(device))
|
79 |
|
80 |
st.markdown("### Hi! This is a service for determining the subject of an article.")
|
81 |
+
st.markdown("It can predict the following topics:\n"
|
82 |
+
"* Computer Science\n"
|
83 |
+
"* Economics\n"
|
84 |
+
"* Electrical Engineering and Systems Science\n"
|
85 |
+
"* Mathematics\n"
|
86 |
+
"* Physics\n"
|
87 |
+
"* Quantitative Biology\n"
|
88 |
+
"* Quantitative Finance\n"
|
89 |
+
"* Statistics\n")
|
90 |
+
st.markdown("#### Just write the title and abstract in the areas below and click the \"Analyze\" button.")
|
91 |
|
92 |
+
title = st.text_area("Title")
|
93 |
|
94 |
+
abstract = st.text_area("Abstract")
|
95 |
|
96 |
if st.button('Analyse'):
|
97 |
with st.spinner("Wait..."):
|
98 |
+
if not title and not abstract:
|
99 |
+
st.error(f"You haven't written anything.")
|
100 |
+
elif not title:
|
101 |
+
st.error(f"You haven't written a title.")
|
102 |
else:
|
103 |
+
pred = predict(title+"\n"+abstract, model.to(device))
|
104 |
+
st.success("\n\n".join(pred))
|