ki33elev commited on
Commit
e999374
1 Parent(s): 5492f24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -37,10 +37,12 @@ def predict(title, summary, tokenizer, model):
37
 
38
  @st.cache(suppress_st_warning=True)
39
  def get_results(prediction, prediction_probs):
40
- ans = "Topic:\t\tConfidence:\n"
41
- for (topic, prob) in zip(prediction, prediction_probs):
42
- ans += topic + "\t\t" + str(prob) + "\n"
43
- return ans
 
 
44
 
45
  label_to_theme = {0: 'Computer science', 1: 'Economics', 2: 'Electrical Engineering and Systems Science', 3: 'Math',
46
  4: 'Quantitative biology', 5: 'Quantitative Finance', 6: 'Statistics', 7: 'Physics'}
@@ -54,6 +56,7 @@ title = st.text_area(label='Title', height=100)
54
  summary = st.text_area(label='Summary (optional)', height=250)
55
  button = st.button('Run')
56
 
57
- prediction, prediction_probs = predict(title, summary, tokenizer, model)
58
- ans = get_results(prediction, prediction_probs)
59
- st.markdown(ans)
 
 
37
 
38
  @st.cache(suppress_st_warning=True)
39
  def get_results(prediction, prediction_probs):
40
+ for prob in prediction_probs:
41
+ prob = str("{:.2f}".format(100 * prob)) + "%"
42
+ return pd.DataFrame({
43
+ 'Topic': prediction,
44
+ 'Confidence': prediction_probs,
45
+ })
46
 
47
  label_to_theme = {0: 'Computer science', 1: 'Economics', 2: 'Electrical Engineering and Systems Science', 3: 'Math',
48
  4: 'Quantitative biology', 5: 'Quantitative Finance', 6: 'Statistics', 7: 'Physics'}
 
56
  summary = st.text_area(label='Summary (optional)', height=250)
57
  button = st.button('Run')
58
 
59
+ if button:
60
+ prediction, prediction_probs = predict(title, summary, tokenizer, model)
61
+ ans = get_results(prediction, prediction_probs)
62
+ st.write('Results: ', ans)