Paula Leonova commited on
Commit
0945896
1 Parent(s): dae3587

Update description and add more spinners

Browse files
Files changed (1) hide show
  1. app.py +27 -25
app.py CHANGED
@@ -15,9 +15,9 @@ ex_long_text = example_long_text_load()
15
 
16
  # if __name__ == '__main__':
17
  st.header("Summzarization & Multi-label Classification for Long Text")
18
- st.write("This app summarizes and then classifies your long text with multiple labels (_Please allow for a minimum of 30secs to load results_).")
19
- st.write("Inputs: User enters their own custom text and labels")
20
- st.write("Outputs: A summary of the text, pre and post summary label likelihood percentages and a downloadable csv of the results")
21
 
22
  with st.form(key='my_form'):
23
  example_text = ex_long_text #ex_text
@@ -31,11 +31,11 @@ with st.form(key='my_form'):
31
  labels = list(set([x.strip() for x in labels.strip().split(',') if len(x.strip()) > 0]))
32
  submit_button = st.form_submit_button(label='Submit')
33
 
 
34
  with st.spinner('Loading pretrained models...'):
35
  summarizer = load_summary_model()
36
  classifier = load_model()
37
- st.success('All Done!')
38
-
39
 
40
  if submit_button:
41
  if len(labels) == 0:
@@ -65,27 +65,29 @@ if submit_button:
65
  # final_summary = summarizer_gen(summarizer, sequence=text_input, maximum_tokens = 30, minimum_tokens = 100)
66
  st.markdown("### Combined Summary")
67
  st.markdown(final_summary)
68
-
69
- topics, scores = classifier_zero(classifier, sequence=final_summary, labels=labels, multi_class=True)
70
- # st.markdown("### Top Label Predictions: Combined Summary")
71
- # plot_result(topics[::-1][:], scores[::-1][:])
72
- # st.markdown("### Download Data")
73
- data = pd.DataFrame({'label': topics, 'scores_from_summary': scores})
74
- # st.dataframe(data)
75
- # coded_data = base64.b64encode(data.to_csv(index = False). encode ()).decode()
76
- # st.markdown(
77
- # f'<a href="data:file/csv;base64, {coded_data}" download = "data.csv">Download Data</a>',
78
- # unsafe_allow_html = True
79
- # )
80
-
81
- st.markdown("### Top Label Predictions: Summary & Full Text")
82
- topics_ex_text, scores_ex_text = classifier_zero(classifier, sequence=example_text, labels=labels, multi_class=True)
83
- plot_dual_bar_chart(topics, scores, topics_ex_text, scores_ex_text)
84
-
85
- data_ex_text = pd.DataFrame({'label': topics_ex_text, 'scores_from_full_text': scores_ex_text})
86
- data2 = pd.merge(data, data_ex_text, on = ['label'])
87
- st.markdown("### Data Table")
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  coded_data = base64.b64encode(data2.to_csv(index = False). encode ()).decode()
90
  st.markdown(
91
  f'<a href="data:file/csv;base64, {coded_data}" download = "data.csv">Click here to download the data</a>',
 
15
 
16
  # if __name__ == '__main__':
17
  st.header("Summzarization & Multi-label Classification for Long Text")
18
+ st.write("This app summarizes and then classifies your long text with multiple labels.")
19
+ st.write("__Inputs__: User enters their own custom text and labels.")
20
+ st.write("__Outputs__: A summary of the text, label likelihood percentages and a downloadable csv of the results.")
21
 
22
  with st.form(key='my_form'):
23
  example_text = ex_long_text #ex_text
 
31
  labels = list(set([x.strip() for x in labels.strip().split(',') if len(x.strip()) > 0]))
32
  submit_button = st.form_submit_button(label='Submit')
33
 
34
+
35
  with st.spinner('Loading pretrained models...'):
36
  summarizer = load_summary_model()
37
  classifier = load_model()
38
+ st.success('Ready for inference...')
 
39
 
40
  if submit_button:
41
  if len(labels) == 0:
 
65
  # final_summary = summarizer_gen(summarizer, sequence=text_input, maximum_tokens = 30, minimum_tokens = 100)
66
  st.markdown("### Combined Summary")
67
  st.markdown(final_summary)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
+ with st.spinner('Matching labels...'):
70
+ topics, scores = classifier_zero(classifier, sequence=final_summary, labels=labels, multi_class=True)
71
+ # st.markdown("### Top Label Predictions: Combined Summary")
72
+ # plot_result(topics[::-1][:], scores[::-1][:])
73
+ # st.markdown("### Download Data")
74
+ data = pd.DataFrame({'label': topics, 'scores_from_summary': scores})
75
+ # st.dataframe(data)
76
+ # coded_data = base64.b64encode(data.to_csv(index = False). encode ()).decode()
77
+ # st.markdown(
78
+ # f'<a href="data:file/csv;base64, {coded_data}" download = "data.csv">Download Data</a>',
79
+ # unsafe_allow_html = True
80
+ # )
81
+
82
+ st.markdown("### Top Label Predictions: Summary & Full Text")
83
+ topics_ex_text, scores_ex_text = classifier_zero(classifier, sequence=example_text, labels=labels, multi_class=True)
84
+ plot_dual_bar_chart(topics, scores, topics_ex_text, scores_ex_text)
85
+
86
+ data_ex_text = pd.DataFrame({'label': topics_ex_text, 'scores_from_full_text': scores_ex_text})
87
+ data2 = pd.merge(data, data_ex_text, on = ['label'])
88
+ st.markdown("### Data Table")
89
+ st.success('Almost done, see download link below.')
90
+
91
  coded_data = base64.b64encode(data2.to_csv(index = False). encode ()).decode()
92
  st.markdown(
93
  f'<a href="data:file/csv;base64, {coded_data}" download = "data.csv">Click here to download the data</a>',