Spaces:
Sleeping
Sleeping
Group input and output fields into containers
Browse files
app.py
CHANGED
@@ -52,34 +52,38 @@ def predict_and_decode(model, title='', abstract=''):
|
|
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 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
if title or abstract:
|
68 |
result = predict_and_decode(model, title=title, abstract=abstract)
|
69 |
|
70 |
-
|
71 |
-
with
|
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 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
else:
|
85 |
st.warning("Type a title and/or an abstract to get started!")
|
|
|
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 |
+
input_container = st.container(border=True)
|
56 |
+
with input_container:
|
57 |
+
title_default = "Attention Is All You Need"
|
58 |
+
abstract_default = (
|
59 |
+
"The dominant sequence transduction models are based on complex recurrent or convolutional neural networks "
|
60 |
+
"in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through "
|
61 |
+
"an attention mechanism. We propose a new simple network architecture, the Transformer..."
|
62 |
+
)
|
63 |
+
|
64 |
+
line_height = 34
|
65 |
+
n_lines = 10
|
66 |
+
title = st.text_input("Paper title", value=title_default, help="Type in paper's title")
|
67 |
+
abstract = st.text_area("Paper abstract", value=abstract_default, height=line_height*n_lines, help="Type in paper's abstract")
|
68 |
|
69 |
if title or abstract:
|
70 |
result = predict_and_decode(model, title=title, abstract=abstract)
|
71 |
|
72 |
+
main_cnt = st.container(border=True)
|
73 |
+
with main_cnt:
|
74 |
st.markdown("#### Top category")
|
75 |
st.markdown(f"**{result.tag[0]}** -- {result.name[0]}")
|
76 |
st.markdown(f"Probability: {result.probability[0]*100:.2f}%")
|
77 |
|
78 |
+
rest_cnt = st.container(border=True)
|
79 |
+
with rest_cnt:
|
80 |
+
threshold = 0.55
|
81 |
+
st.text("Other top categories:")
|
82 |
+
max_len = min(max(1, sum(result.iloc[1:].probability > threshold)), 5)
|
83 |
|
84 |
+
def format_p(example):
|
85 |
+
example.probability = f"{example.probability * 100 :.2f}%"
|
86 |
+
return example
|
87 |
+
st.table(result.iloc[1:1 + max_len].apply(format_p, axis=1))
|
88 |
else:
|
89 |
st.warning("Type a title and/or an abstract to get started!")
|