Inosen-Infinity commited on
Commit
2b2a1be
·
verified ·
1 Parent(s): 2b9bf45

Output a message when no title or abstract provided

Browse files
Files changed (1) hide show
  1. app.py +20 -17
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
- result = predict_and_decode(model, title=title, abstract=abstract)
68
-
69
- cnt = st.container(border=True)
70
- with cnt:
71
- st.markdown("#### Top category")
72
- st.markdown(f"**{result.tag[0]}** -- {result.name[0]}")
73
- st.markdown(f"Probability: {result.probability[0]*100:.2f}%")
74
-
75
- threshold = 0.55
76
- st.text("Other top categories:")
77
- max_len = min(max(1, sum(result.iloc[1:].probability > threshold)), 5)
78
-
79
- def format_p(example):
80
- example.probability = f"{example.probability * 100 :.2f}%"
81
- return example
82
- st.table(result.iloc[1:1 + max_len].apply(format_p, axis=1))
 
 
 
 
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!")