m. polinsky
commited on
Update streamlit_app.py
Browse files- 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 |
-
|
181 |
-
|
182 |
-
choices.
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
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...')
|