m. polinsky commited on
Commit
e037e33
·
unverified ·
1 Parent(s): 1075df3

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +57 -55
streamlit_app.py CHANGED
@@ -176,58 +176,60 @@ article_dict, clusters = initialize(LIMIT, USE_CACHE)
176
  # We now have clusters and cluster data. Redundancy.
177
  # We call a display function and get the user input.
178
  # For this its still streamlit.
179
-
180
- selections = []
181
- choices = list(clusters.keys())
182
- choices.insert(0,'None')
183
- # Form used to take 3 menu inputs
184
- with st.form(key='columns_in_form'):
185
- cols = st.columns(3)
186
- for i, col in enumerate(cols):
187
- selections.append(col.selectbox(f'Make a Selection', choices, key=i))
188
- submitted = st.form_submit_button('Submit')
189
- if submitted:
190
- selections = [i for i in selections if i is not None]
191
- with st.spinner(text="Digesting...please wait, this will take a few moments...Maybe check some messages or start reading the latest papers on summarization with transformers...."):
192
- found = False
193
-
194
- # Check if we already have this digest.
195
- for i in digests:
196
- if set(selections) == set(list(i)):
197
- digestor = digests[i]
198
- found = True
199
- break
200
-
201
- # If we need a new digest
202
- if not found:
203
- chosen = []
204
- # Why not just use answers.values()?
205
- for i in selections: # i is supposed to be a list of stubs, mostly one
206
- if i != 'None':
207
- for j in clusters[i]:
208
- if j not in chosen:
209
- chosen.append(j) # j is supposed to be a stub.
210
-
211
- # Article dict contains stubs for unprocessed articles and lists of summarized chunks for processed ones.
212
- # Here we put together a list of article stubs and/or summary chunks and let the digestor sort out what it does with them,
213
- chosen = [i if isinstance(article_dict[i.hed], stub) else article_dict[i.hed] for i in chosen]
214
- # Digestor uses 'chosen', passed through 'stubs' to create digest.
215
- # 'user_choicese' is passed for reference.
216
- # Passing list(answers.values()) includes 'None' choices.
217
- digestor = Digestor(timer=Timer(), cache = USE_CACHE, stubs=chosen, user_choices=list(selections))
218
- # happens internally but may be used differently so it isn't automatic upon digestor creation.
219
- # Easily turn caching off for testing.
220
- digestor.digest() # creates summaries and stores them associated with the digest
221
-
222
-
223
-
224
- # Get displayable digest and digest data
225
- digestor.build_digest()# only returns for data collection
226
- digests[tuple(digestor.user_choices)] = digestor
227
-
228
- if len(digestor.text) == 0:
229
- st.write("You didn't select a topic!")
230
- else:
231
- st.write("Your digest is ready:\n")
232
-
233
- st.write(digestor.text)
 
 
 
176
  # We now have clusters and cluster data. Redundancy.
177
  # We call a display function and get the user input.
178
  # For this its still streamlit.
179
+ loop_control = 'y'
180
+ while loop_control == 'y':
181
+ selections = []
182
+ choices = list(clusters.keys())
183
+ choices.insert(0,'None')
184
+ # Form used to take 3 menu inputs
185
+ with st.form(key='columns_in_form'):
186
+ cols = st.columns(3)
187
+ for i, col in enumerate(cols):
188
+ selections.append(col.selectbox(f'Make a Selection', choices, key=i))
189
+ submitted = st.form_submit_button('Submit')
190
+ if submitted:
191
+ selections = [i for i in selections if i is not None]
192
+ with st.spinner(text="Digesting...please wait, this will take a few moments...Maybe check some messages or start reading the latest papers on summarization with transformers...."):
193
+ found = False
194
+
195
+ # Check if we already have this digest.
196
+ for i in digests:
197
+ if set(selections) == set(list(i)):
198
+ digestor = digests[i]
199
+ found = True
200
+ break
201
+
202
+ # If we need a new digest
203
+ if not found:
204
+ chosen = []
205
+ # Why not just use answers.values()?
206
+ for i in selections: # i is supposed to be a list of stubs, mostly one
207
+ if i != 'None':
208
+ for j in clusters[i]:
209
+ if j not in chosen:
210
+ chosen.append(j) # j is supposed to be a stub.
211
+
212
+ # Article dict contains stubs for unprocessed articles and lists of summarized chunks for processed ones.
213
+ # Here we put together a list of article stubs and/or summary chunks and let the digestor sort out what it does with them,
214
+ chosen = [i if isinstance(article_dict[i.hed], stub) else article_dict[i.hed] for i in chosen]
215
+ # Digestor uses 'chosen', passed through 'stubs' to create digest.
216
+ # 'user_choicese' is passed for reference.
217
+ # Passing list(answers.values()) includes 'None' choices.
218
+ digestor = Digestor(timer=Timer(), cache = USE_CACHE, stubs=chosen, user_choices=list(selections))
219
+ # happens internally but may be used differently so it isn't automatic upon digestor creation.
220
+ # Easily turn caching off for testing.
221
+ digestor.digest() # creates summaries and stores them associated with the digest
222
+
223
+
224
+
225
+ # Get displayable digest and digest data
226
+ digestor.build_digest()# only returns for data collection
227
+ digests[tuple(digestor.user_choices)] = digestor
228
+
229
+ if len(digestor.text) == 0:
230
+ st.write("You didn't select a topic!")
231
+ else:
232
+ st.write("Your digest is ready:\n")
233
+
234
+ st.write(digestor.text)
235
+ loop_control = input('Y to continue...')