Spaces:
Sleeping
Sleeping
Output a message when no title or abstract provided
Browse files
app.py
CHANGED
@@ -50,7 +50,7 @@ def predict_and_decode(model, title='', abstract=''):
|
|
50 |
return df.reset_index(drop=True)
|
51 |
|
52 |
st.header("Paper Category Classifier")
|
53 |
-
st.text("Input title and/or abstract of a scientific paper, and get classification according to arxiv.org categories")
|
54 |
|
55 |
title_default = "Attention Is All You Need"
|
56 |
abstract_default = (
|
@@ -64,19 +64,22 @@ n_lines = 10
|
|
64 |
title = st.text_input("Paper title", value=title_default, help="Type in paper's title")
|
65 |
abstract = st.text_area("Paper abstract", value=abstract_default, height=line_height*n_lines, help="Type in paper's abstract")
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
50 |
return df.reset_index(drop=True)
|
51 |
|
52 |
st.header("Paper Category Classifier")
|
53 |
+
st.text("Input a title and/or an abstract of a scientific paper, and get classification according to arxiv.org categories")
|
54 |
|
55 |
title_default = "Attention Is All You Need"
|
56 |
abstract_default = (
|
|
|
64 |
title = st.text_input("Paper title", value=title_default, help="Type in paper's title")
|
65 |
abstract = st.text_area("Paper abstract", value=abstract_default, height=line_height*n_lines, help="Type in paper's abstract")
|
66 |
|
67 |
+
if title or abstract:
|
68 |
+
result = predict_and_decode(model, title=title, abstract=abstract)
|
69 |
+
|
70 |
+
cnt = st.container(border=True)
|
71 |
+
with cnt:
|
72 |
+
st.markdown("#### Top category")
|
73 |
+
st.markdown(f"**{result.tag[0]}** -- {result.name[0]}")
|
74 |
+
st.markdown(f"Probability: {result.probability[0]*100:.2f}%")
|
75 |
+
|
76 |
+
threshold = 0.55
|
77 |
+
st.text("Other top categories:")
|
78 |
+
max_len = min(max(1, sum(result.iloc[1:].probability > threshold)), 5)
|
79 |
+
|
80 |
+
def format_p(example):
|
81 |
+
example.probability = f"{example.probability * 100 :.2f}%"
|
82 |
+
return example
|
83 |
+
st.table(result.iloc[1:1 + max_len].apply(format_p, axis=1))
|
84 |
+
else:
|
85 |
+
st.warning("Type a title and/or an abstract to get started!")
|