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

Group input and output fields into containers

Browse files
Files changed (1) hide show
  1. app.py +24 -20
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
- title_default = "Attention Is All You Need"
56
- abstract_default = (
57
- "The dominant sequence transduction models are based on complex recurrent or convolutional neural networks "
58
- "in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through "
59
- "an attention mechanism. We propose a new simple network architecture, the Transformer..."
60
- )
61
-
62
- line_height = 34
63
- 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
  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!")
 
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!")