Spaces:
Paused
Paused
Update app.py via AI Editor
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from docx import Document
|
|
6 |
from io import BytesIO
|
7 |
import dash
|
8 |
import dash_bootstrap_components as dbc
|
9 |
-
from dash import html, dcc, Input, Output, State, callback_context, ALL
|
10 |
from dash.dash_table import DataTable
|
11 |
from PyPDF2 import PdfReader
|
12 |
import logging
|
@@ -261,7 +261,8 @@ def get_right_col_content(selected_type, store_data):
|
|
261 |
},
|
262 |
multiple=True
|
263 |
),
|
264 |
-
file_list_component()
|
|
|
265 |
])
|
266 |
)
|
267 |
elif selected_type in doc_dependencies:
|
@@ -270,6 +271,7 @@ def get_right_col_content(selected_type, store_data):
|
|
270 |
label = ""
|
271 |
loaded_preview = None
|
272 |
store_var = store_data.get(src)
|
|
|
273 |
if src == "shred":
|
274 |
label = "Shred (Requirements)"
|
275 |
loaded_preview = markdown_table_preview(store_var)
|
@@ -305,7 +307,7 @@ def get_right_col_content(selected_type, store_data):
|
|
305 |
},
|
306 |
multiple=False
|
307 |
),
|
308 |
-
html.Div(id=
|
309 |
dbc.RadioItems(
|
310 |
id={'type': 'radio-doc-source', 'subtype': src, 'index': selected_type},
|
311 |
options=[
|
@@ -454,7 +456,7 @@ def update_right_col(selected_type, shred, pink, pink_review, red, red_review, g
|
|
454 |
[
|
455 |
Output('store-shred', 'data'),
|
456 |
Output('file-list', 'children'),
|
457 |
-
Output(
|
458 |
],
|
459 |
[
|
460 |
Input({'type': 'upload-doc-type', 'subtype': 'shred', 'index': 'Shred'}, 'contents')
|
@@ -503,6 +505,14 @@ def handle_shred_upload(contents, filenames, current_shred, file_list):
|
|
503 |
Output('store-gold-review', 'data'),
|
504 |
Output('store-loe', 'data'),
|
505 |
Output('store-virtual-board', 'data'),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
506 |
],
|
507 |
[
|
508 |
Input({'type': 'upload-doc-type', 'subtype': ALL, 'index': ALL}, 'contents')
|
@@ -514,8 +524,9 @@ def handle_shred_upload(contents, filenames, current_shred, file_list):
|
|
514 |
)
|
515 |
def handle_dep_upload_to_stores(contents_list, filenames_list):
|
516 |
stores = [dash.no_update]*8
|
|
|
517 |
if not contents_list or not filenames_list:
|
518 |
-
return stores
|
519 |
for i, (contents, filenames) in enumerate(zip(contents_list, filenames_list)):
|
520 |
if contents and filenames:
|
521 |
if isinstance(contents, str):
|
@@ -523,55 +534,32 @@ def handle_dep_upload_to_stores(contents_list, filenames_list):
|
|
523 |
filenames = [filenames]
|
524 |
for content, name in zip(contents, filenames):
|
525 |
file_text = process_document(content, name)
|
526 |
-
|
527 |
-
|
528 |
-
elif 'pink_review' in name.lower():
|
529 |
stores[1] = file_text
|
530 |
-
|
531 |
-
|
|
|
|
|
532 |
elif 'red_review' in name.lower():
|
533 |
stores[3] = file_text
|
534 |
-
|
535 |
-
|
|
|
|
|
536 |
elif 'gold_review' in name.lower():
|
537 |
stores[5] = file_text
|
|
|
|
|
|
|
|
|
538 |
elif 'loe' in name.lower():
|
539 |
stores[6] = file_text
|
|
|
540 |
elif 'virtual' in name.lower():
|
541 |
stores[7] = file_text
|
542 |
-
|
543 |
-
|
544 |
-
@app.callback(
|
545 |
-
[
|
546 |
-
Output({'type': 'uploaded-doc-name', 'subtype': MATCH, 'index': MATCH}, 'children'),
|
547 |
-
Output({'type': 'uploaded-doc-name', 'subtype': 'shred', 'index': 'Shred'}, 'children')
|
548 |
-
],
|
549 |
-
[
|
550 |
-
Input({'type': 'upload-doc-type', 'subtype': MATCH, 'index': MATCH}, 'filename'),
|
551 |
-
Input({'type': 'upload-doc-type', 'subtype': 'shred', 'index': 'Shred'}, 'filename')
|
552 |
-
],
|
553 |
-
prevent_initial_call=True
|
554 |
-
)
|
555 |
-
def update_uploaded_doc_name_combined(filename_match, filename_shred):
|
556 |
-
ctx = callback_context
|
557 |
-
triggered_id = None
|
558 |
-
if ctx.triggered and ctx.triggered[0]['prop_id']:
|
559 |
-
triggered_id = ctx.triggered[0]['prop_id'].split('.')[0]
|
560 |
-
match_value = ""
|
561 |
-
shred_value = ""
|
562 |
-
if isinstance(filename_match, list):
|
563 |
-
match_value = filename_match[-1] if filename_match else ""
|
564 |
-
elif filename_match:
|
565 |
-
match_value = filename_match
|
566 |
-
if isinstance(filename_shred, list):
|
567 |
-
shred_value = filename_shred[-1] if filename_shred else ""
|
568 |
-
elif filename_shred:
|
569 |
-
shred_value = filename_shred
|
570 |
-
# Only update the output that was triggered, leave the other as dash.no_update
|
571 |
-
if triggered_id and '"subtype":"shred"' in triggered_id and '"index":"Shred"' in triggered_id:
|
572 |
-
return dash.no_update, shred_value
|
573 |
-
else:
|
574 |
-
return match_value, dash.no_update
|
575 |
|
576 |
@app.callback(
|
577 |
Output('document-preview', 'children'),
|
|
|
6 |
from io import BytesIO
|
7 |
import dash
|
8 |
import dash_bootstrap_components as dbc
|
9 |
+
from dash import html, dcc, Input, Output, State, callback_context, ALL
|
10 |
from dash.dash_table import DataTable
|
11 |
from PyPDF2 import PdfReader
|
12 |
import logging
|
|
|
261 |
},
|
262 |
multiple=True
|
263 |
),
|
264 |
+
file_list_component(),
|
265 |
+
html.Div(id='uploaded-doc-name-shred')
|
266 |
])
|
267 |
)
|
268 |
elif selected_type in doc_dependencies:
|
|
|
271 |
label = ""
|
272 |
loaded_preview = None
|
273 |
store_var = store_data.get(src)
|
274 |
+
doc_name_id = f"uploaded-doc-name-{src}"
|
275 |
if src == "shred":
|
276 |
label = "Shred (Requirements)"
|
277 |
loaded_preview = markdown_table_preview(store_var)
|
|
|
307 |
},
|
308 |
multiple=False
|
309 |
),
|
310 |
+
html.Div(id=doc_name_id),
|
311 |
dbc.RadioItems(
|
312 |
id={'type': 'radio-doc-source', 'subtype': src, 'index': selected_type},
|
313 |
options=[
|
|
|
456 |
[
|
457 |
Output('store-shred', 'data'),
|
458 |
Output('file-list', 'children'),
|
459 |
+
Output('uploaded-doc-name-shred', 'children')
|
460 |
],
|
461 |
[
|
462 |
Input({'type': 'upload-doc-type', 'subtype': 'shred', 'index': 'Shred'}, 'contents')
|
|
|
505 |
Output('store-gold-review', 'data'),
|
506 |
Output('store-loe', 'data'),
|
507 |
Output('store-virtual-board', 'data'),
|
508 |
+
Output('uploaded-doc-name-pink', 'children'),
|
509 |
+
Output('uploaded-doc-name-pink_review', 'children'),
|
510 |
+
Output('uploaded-doc-name-red', 'children'),
|
511 |
+
Output('uploaded-doc-name-red_review', 'children'),
|
512 |
+
Output('uploaded-doc-name-gold', 'children'),
|
513 |
+
Output('uploaded-doc-name-gold_review', 'children'),
|
514 |
+
Output('uploaded-doc-name-loe', 'children'),
|
515 |
+
Output('uploaded-doc-name-virtual_board', 'children'),
|
516 |
],
|
517 |
[
|
518 |
Input({'type': 'upload-doc-type', 'subtype': ALL, 'index': ALL}, 'contents')
|
|
|
524 |
)
|
525 |
def handle_dep_upload_to_stores(contents_list, filenames_list):
|
526 |
stores = [dash.no_update]*8
|
527 |
+
names = [dash.no_update]*8
|
528 |
if not contents_list or not filenames_list:
|
529 |
+
return stores + names
|
530 |
for i, (contents, filenames) in enumerate(zip(contents_list, filenames_list)):
|
531 |
if contents and filenames:
|
532 |
if isinstance(contents, str):
|
|
|
534 |
filenames = [filenames]
|
535 |
for content, name in zip(contents, filenames):
|
536 |
file_text = process_document(content, name)
|
537 |
+
# Assign to correct store and name output
|
538 |
+
if 'pink_review' in name.lower():
|
|
|
539 |
stores[1] = file_text
|
540 |
+
names[1] = name
|
541 |
+
elif 'pink' in name.lower() and 'review' not in name.lower():
|
542 |
+
stores[0] = file_text
|
543 |
+
names[0] = name
|
544 |
elif 'red_review' in name.lower():
|
545 |
stores[3] = file_text
|
546 |
+
names[3] = name
|
547 |
+
elif 'red' in name.lower() and 'review' not in name.lower():
|
548 |
+
stores[2] = file_text
|
549 |
+
names[2] = name
|
550 |
elif 'gold_review' in name.lower():
|
551 |
stores[5] = file_text
|
552 |
+
names[5] = name
|
553 |
+
elif 'gold' in name.lower() and 'review' not in name.lower():
|
554 |
+
stores[4] = file_text
|
555 |
+
names[4] = name
|
556 |
elif 'loe' in name.lower():
|
557 |
stores[6] = file_text
|
558 |
+
names[6] = name
|
559 |
elif 'virtual' in name.lower():
|
560 |
stores[7] = file_text
|
561 |
+
names[7] = name
|
562 |
+
return stores + names
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
|
564 |
@app.callback(
|
565 |
Output('document-preview', 'children'),
|