Paula Leonova commited on
Commit
abaf1c5
1 Parent(s): 08183e3

Create a separate example button to populate form with sample text

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -24,24 +24,30 @@ st.write("__Inputs__: User enters their own custom text and labels.")
24
  st.write("__Outputs__: A summary of the text, likelihood percentages for each label and a downloadable csv of the results. \
25
  Includes additional options to generate a list of keywords and/or evaluate results against a list of ground truth labels, if available.")
26
 
27
- with st.form(key='my_form'):
 
28
  example_text = ex_long_text #ex_text
29
  display_text = 'Excerpt from Frankenstein:' + example_text + '"\n\n' + "[This is an excerpt from Project Gutenberg's Frankenstein. " + ex_license + "]"
30
- text_input = st.text_area("Input any text you want to summarize & classify here (keep in mind very long text will take a while to process):", display_text)
 
 
 
 
 
31
 
32
- if text_input == display_text:
33
- text_input = example_text
34
 
 
 
 
35
  gen_keywords = st.radio(
36
  "Generate keywords from text?",
37
  ('Yes', 'No')
38
  )
39
 
40
- # labels = st.text_input('Enter possible topic labels, which can be either keywords and/or general themes (comma-separated). The output will be the likelihood that these labels represent the text.:',ex_labels, max_chars=1000)
41
- labels = st.text_input('Enter possible topic labels, which can be either keywords and/or general themes (comma-separated):',ex_labels, max_chars=1000)
42
  labels = list(set([x.strip() for x in labels.strip().split(',') if len(x.strip()) > 0]))
43
 
44
- glabels = st.text_input('If available, enter ground truth topic labels to evaluate results, otherwise leave blank (comma-separated):',ex_glabels, max_chars=1000)
45
  glabels = list(set([x.strip() for x in glabels.strip().split(',') if len(x.strip()) > 0]))
46
 
47
  threshold_value = st.slider(
@@ -51,7 +57,6 @@ with st.form(key='my_form'):
51
  submit_button = st.form_submit_button(label='Submit')
52
 
53
 
54
-
55
  with st.spinner('Loading pretrained models...'):
56
  start = time.time()
57
  summarizer = md.load_summary_model()
@@ -67,9 +72,10 @@ with st.spinner('Loading pretrained models...'):
67
 
68
  st.success(f'Time taken to load KeyBERT model: {k_time}s & BART summarizer mnli model: {s_time}s & BART classifier mnli model: {c_time}s')
69
 
70
- if submit_button:
 
71
  if len(text_input) == 0:
72
- st.write("Enter some text to generate a summary")
73
  else:
74
  with st.spinner('Breaking up text into more reasonable chunks (tranformers cannot exceed a 1024 token max)...'):
75
  # For each body of text, create text chunks of a certain token size required for the transformer
@@ -119,7 +125,7 @@ if submit_button:
119
  st.markdown(final_summary)
120
 
121
  if len(text_input) == 0 or len(labels) == 0:
122
- st.write('Enter some text and at least one possible topic to see predictions.')
123
  else:
124
  st.markdown("### Top Label Predictions on Summary vs Full Text")
125
  with st.spinner('Matching labels...'):
 
24
  st.write("__Outputs__: A summary of the text, likelihood percentages for each label and a downloadable csv of the results. \
25
  Includes additional options to generate a list of keywords and/or evaluate results against a list of ground truth labels, if available.")
26
 
27
+ example_button = st.button(label='See Example')
28
+ if example_button:
29
  example_text = ex_long_text #ex_text
30
  display_text = 'Excerpt from Frankenstein:' + example_text + '"\n\n' + "[This is an excerpt from Project Gutenberg's Frankenstein. " + ex_license + "]"
31
+ input_labels = ex_labels
32
+ input_glabels = ex_glabels
33
+ else:
34
+ display_text = ''
35
+ input_labels = ''
36
+ input_glabels = ''
37
 
 
 
38
 
39
+ with st.form(key='my_form'):
40
+ text_input = st.text_area("Input any text you want to summarize & classify here (keep in mind very long text will take a while to process):", display_text)
41
+
42
  gen_keywords = st.radio(
43
  "Generate keywords from text?",
44
  ('Yes', 'No')
45
  )
46
 
47
+ labels = st.text_input('Enter possible topic labels, which can be either keywords and/or general themes (comma-separated):',input_labels, max_chars=1000)
 
48
  labels = list(set([x.strip() for x in labels.strip().split(',') if len(x.strip()) > 0]))
49
 
50
+ glabels = st.text_input('If available, enter ground truth topic labels to evaluate results, otherwise leave blank (comma-separated):',input_glabels, max_chars=1000)
51
  glabels = list(set([x.strip() for x in glabels.strip().split(',') if len(x.strip()) > 0]))
52
 
53
  threshold_value = st.slider(
 
57
  submit_button = st.form_submit_button(label='Submit')
58
 
59
 
 
60
  with st.spinner('Loading pretrained models...'):
61
  start = time.time()
62
  summarizer = md.load_summary_model()
 
72
 
73
  st.success(f'Time taken to load KeyBERT model: {k_time}s & BART summarizer mnli model: {s_time}s & BART classifier mnli model: {c_time}s')
74
 
75
+
76
+ if submit_button or example_button:
77
  if len(text_input) == 0:
78
+ st.error("Enter some text to generate a summary")
79
  else:
80
  with st.spinner('Breaking up text into more reasonable chunks (tranformers cannot exceed a 1024 token max)...'):
81
  # For each body of text, create text chunks of a certain token size required for the transformer
 
125
  st.markdown(final_summary)
126
 
127
  if len(text_input) == 0 or len(labels) == 0:
128
+ st.error('Enter some text and at least one possible topic to see label predictions.')
129
  else:
130
  st.markdown("### Top Label Predictions on Summary vs Full Text")
131
  with st.spinner('Matching labels...'):