Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -236,20 +236,15 @@ Now, generate the {document_type}:
|
|
236 |
Output('document-choice', 'style'),
|
237 |
Output('btn-generate-document', 'style'),
|
238 |
[Input(f'btn-{doc_type.lower().replace(" ", "-")}', 'n_clicks') for doc_type in document_types.keys()],
|
239 |
-
Input('btn-generate-document', 'n_clicks'),
|
240 |
-
State('document-source', 'value'),
|
241 |
-
State('specific-document-name', 'children'),
|
242 |
-
State('file-list', 'children'),
|
243 |
prevent_initial_call=True
|
244 |
)
|
245 |
-
def
|
246 |
-
global
|
247 |
ctx = dash.callback_context
|
248 |
if not ctx.triggered:
|
249 |
raise dash.exceptions.PreventUpdate
|
250 |
|
251 |
triggered_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
252 |
-
file_list = args[-1]
|
253 |
|
254 |
if triggered_id.startswith('btn-'):
|
255 |
document_type = triggered_id.replace('btn-', '').replace('-', ' ').title()
|
@@ -259,74 +254,86 @@ def generate_document_preview(*args):
|
|
259 |
return html.Div(f"Ready to generate {document_type} document."), "", dash.no_update, {'display': 'block'}, {'display': 'flex'}, {'display': 'block'}
|
260 |
elif document_type in ["Pink Review", "Red Review", "Gold Review", "Virtual Board", "Loe"]:
|
261 |
return html.Div(f"Ready to generate {document_type}."), "", dash.no_update, {'display': 'block'}, {'display': 'flex'}, {'display': 'block'}
|
262 |
-
|
|
|
263 |
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
if shredded_document is None:
|
281 |
-
return html.Div("Please shred a document first."), "", "Please shred a document first.", {'display': 'none'}, {'display': 'none'}, {'display': 'none'}
|
282 |
-
|
283 |
try:
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
return html.Div("Please complete Red Review first."), "", "Please complete Red Review first.", {'display': 'none'}, {'display': 'none'}, {'display': 'none'}
|
299 |
-
if document_source == 'uploaded' and specific_document:
|
300 |
-
current_document = generate_document(document_type, [specific_document, generated_documents['Red Review'], shredded_document])
|
301 |
-
else:
|
302 |
-
current_document = generate_document(document_type, [generated_documents['Red Review'], shredded_document])
|
303 |
-
elif document_type in ["Pink Review", "Red Review", "Gold Review"]:
|
304 |
-
previous_document = generated_documents.get(document_type.split(' ')[0], None)
|
305 |
-
if not previous_document:
|
306 |
-
return html.Div(f"Please generate {document_type.split(' ')[0]} document first."), "", f"Please generate {document_type.split(' ')[0]} document first.", {'display': 'none'}, {'display': 'none'}, {'display': 'none'}
|
307 |
-
if document_source == 'uploaded' and specific_document:
|
308 |
-
current_document = generate_document(document_type, [specific_document, previous_document, shredded_document])
|
309 |
-
else:
|
310 |
-
current_document = generate_document(document_type, [previous_document, shredded_document])
|
311 |
-
elif document_type in ["Virtual Board", "Loe"]:
|
312 |
-
if 'Gold' not in generated_documents:
|
313 |
-
return html.Div("Please complete Gold document first."), "", "Please complete Gold document first.", {'display': 'none'}, {'display': 'none'}, {'display': 'none'}
|
314 |
-
if document_source == 'uploaded' and specific_document:
|
315 |
-
current_document = generate_document(document_type, [specific_document, generated_documents['Gold'], shredded_document])
|
316 |
-
else:
|
317 |
-
current_document = generate_document(document_type, [generated_documents['Gold'], shredded_document])
|
318 |
else:
|
319 |
current_document = generate_document(document_type, [shredded_document])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
|
321 |
-
|
322 |
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
|
328 |
-
return dash.no_update, dash.no_update, dash.no_update, dash.no_update, dash.no_update, dash.no_update
|
329 |
-
|
330 |
@app.callback(
|
331 |
Output('specific-document-name', 'children'),
|
332 |
Input('upload-specific-document', 'contents'),
|
@@ -374,7 +381,7 @@ def download_document(n_clicks):
|
|
374 |
if current_document is None:
|
375 |
raise dash.exceptions.PreventUpdate
|
376 |
|
377 |
-
if document_type in ["LOE", "
|
378 |
# Create a pandas DataFrame for spreadsheet-type documents
|
379 |
df = pd.read_csv(StringIO(current_document))
|
380 |
|
|
|
236 |
Output('document-choice', 'style'),
|
237 |
Output('btn-generate-document', 'style'),
|
238 |
[Input(f'btn-{doc_type.lower().replace(" ", "-")}', 'n_clicks') for doc_type in document_types.keys()],
|
|
|
|
|
|
|
|
|
239 |
prevent_initial_call=True
|
240 |
)
|
241 |
+
def update_document_type(*args):
|
242 |
+
global document_type
|
243 |
ctx = dash.callback_context
|
244 |
if not ctx.triggered:
|
245 |
raise dash.exceptions.PreventUpdate
|
246 |
|
247 |
triggered_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
|
|
248 |
|
249 |
if triggered_id.startswith('btn-'):
|
250 |
document_type = triggered_id.replace('btn-', '').replace('-', ' ').title()
|
|
|
254 |
return html.Div(f"Ready to generate {document_type} document."), "", dash.no_update, {'display': 'block'}, {'display': 'flex'}, {'display': 'block'}
|
255 |
elif document_type in ["Pink Review", "Red Review", "Gold Review", "Virtual Board", "Loe"]:
|
256 |
return html.Div(f"Ready to generate {document_type}."), "", dash.no_update, {'display': 'block'}, {'display': 'flex'}, {'display': 'block'}
|
257 |
+
|
258 |
+
return dash.no_update, dash.no_update, dash.no_update, dash.no_update, dash.no_update, dash.no_update
|
259 |
|
260 |
+
@app.callback(
|
261 |
+
Output('document-preview', 'children', allow_duplicate=True),
|
262 |
+
Output('loading-output', 'children', allow_duplicate=True),
|
263 |
+
Output('status-bar', 'children', allow_duplicate=True),
|
264 |
+
Input('btn-generate-document', 'n_clicks'),
|
265 |
+
State('document-source', 'value'),
|
266 |
+
State('specific-document-name', 'children'),
|
267 |
+
prevent_initial_call=True
|
268 |
+
)
|
269 |
+
def generate_document_preview(n_clicks, document_source, specific_document):
|
270 |
+
global current_document, document_type, shredded_document, generated_documents
|
271 |
+
|
272 |
+
if document_type == "Shred":
|
273 |
+
if not uploaded_files:
|
274 |
+
return html.Div("Please upload a document before shredding."), "", "Please upload a document before shredding."
|
275 |
+
file_contents = list(uploaded_files.values())
|
|
|
|
|
|
|
276 |
try:
|
277 |
+
shredded_document = generate_document(document_type, file_contents)
|
278 |
+
generated_documents['Shred'] = shredded_document
|
279 |
+
return dcc.Markdown(shredded_document), f"{document_type} generated", "Document shredded successfully."
|
280 |
+
except Exception as e:
|
281 |
+
print(f"Error generating document: {str(e)}")
|
282 |
+
return html.Div(f"Error generating document: {str(e)}"), "Error", "An error occurred while shredding the document."
|
283 |
+
|
284 |
+
if shredded_document is None:
|
285 |
+
return html.Div("Please shred a document first."), "", "Please shred a document first."
|
286 |
+
|
287 |
+
try:
|
288 |
+
if document_type == "Pink":
|
289 |
+
if document_source == 'uploaded' and specific_document:
|
290 |
+
current_document = generate_document(document_type, [specific_document, shredded_document])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
291 |
else:
|
292 |
current_document = generate_document(document_type, [shredded_document])
|
293 |
+
elif document_type == "Red":
|
294 |
+
if 'Pink Review' not in generated_documents:
|
295 |
+
return html.Div("Please complete Pink Review first."), "", "Please complete Pink Review first."
|
296 |
+
if document_source == 'uploaded' and specific_document:
|
297 |
+
current_document = generate_document(document_type, [specific_document, generated_documents['Pink Review'],
|
298 |
+
elif document_type == "Red":
|
299 |
+
if 'Pink Review' not in generated_documents:
|
300 |
+
return html.Div("Please complete Pink Review first."), "", "Please complete Pink Review first."
|
301 |
+
if document_source == 'uploaded' and specific_document:
|
302 |
+
current_document = generate_document(document_type, [specific_document, generated_documents['Pink Review'], shredded_document])
|
303 |
+
else:
|
304 |
+
current_document = generate_document(document_type, [generated_documents['Pink Review'], shredded_document])
|
305 |
+
elif document_type == "Gold":
|
306 |
+
if 'Red Review' not in generated_documents:
|
307 |
+
return html.Div("Please complete Red Review first."), "", "Please complete Red Review first."
|
308 |
+
if document_source == 'uploaded' and specific_document:
|
309 |
+
current_document = generate_document(document_type, [specific_document, generated_documents['Red Review'], shredded_document])
|
310 |
+
else:
|
311 |
+
current_document = generate_document(document_type, [generated_documents['Red Review'], shredded_document])
|
312 |
+
elif document_type in ["Pink Review", "Red Review", "Gold Review"]:
|
313 |
+
previous_document = generated_documents.get(document_type.split(' ')[0], None)
|
314 |
+
if not previous_document:
|
315 |
+
return html.Div(f"Please generate {document_type.split(' ')[0]} document first."), "", f"Please generate {document_type.split(' ')[0]} document first."
|
316 |
+
if document_source == 'uploaded' and specific_document:
|
317 |
+
current_document = generate_document(document_type, [specific_document, previous_document, shredded_document])
|
318 |
+
else:
|
319 |
+
current_document = generate_document(document_type, [previous_document, shredded_document])
|
320 |
+
elif document_type in ["Virtual Board", "Loe"]:
|
321 |
+
if 'Gold' not in generated_documents:
|
322 |
+
return html.Div("Please complete Gold document first."), "", "Please complete Gold document first."
|
323 |
+
if document_source == 'uploaded' and specific_document:
|
324 |
+
current_document = generate_document(document_type, [specific_document, generated_documents['Gold'], shredded_document])
|
325 |
+
else:
|
326 |
+
current_document = generate_document(document_type, [generated_documents['Gold'], shredded_document])
|
327 |
+
else:
|
328 |
+
current_document = generate_document(document_type, [shredded_document])
|
329 |
|
330 |
+
generated_documents[document_type] = current_document
|
331 |
|
332 |
+
return dcc.Markdown(current_document), f"{document_type} generated", f"{document_type} document generated successfully."
|
333 |
+
except Exception as e:
|
334 |
+
print(f"Error generating document: {str(e)}")
|
335 |
+
return html.Div(f"Error generating document: {str(e)}"), "Error", "An error occurred while generating the document."
|
336 |
|
|
|
|
|
337 |
@app.callback(
|
338 |
Output('specific-document-name', 'children'),
|
339 |
Input('upload-specific-document', 'contents'),
|
|
|
381 |
if current_document is None:
|
382 |
raise dash.exceptions.PreventUpdate
|
383 |
|
384 |
+
if document_type in ["LOE", "Pink Review", "Red Review", "Gold Review", "Virtual Board"]:
|
385 |
# Create a pandas DataFrame for spreadsheet-type documents
|
386 |
df = pd.read_csv(StringIO(current_document))
|
387 |
|