bluenevus commited on
Commit
f9ae9b8
·
1 Parent(s): ef148d1

Update app.py via AI Editor

Browse files
Files changed (1) hide show
  1. app.py +70 -12
app.py CHANGED
@@ -449,6 +449,9 @@ def update_selected_doc_type(n_clicks_list, btn_ids):
449
  def update_right_col(selected_type, shred_doc, pink_doc, pink_review_doc, red_doc, red_review_doc, gold_doc):
450
  return get_right_col_content(selected_type, shred_doc, pink_doc, pink_review_doc, red_doc, red_review_doc, gold_doc)
451
 
 
 
 
452
  @app.callback(
453
  Output('file-list', 'children'),
454
  Output('store-shred', 'data'),
@@ -577,11 +580,64 @@ def master_callback(
577
  global uploaded_files, uploaded_doc_contents
578
  ctx = callback_context
579
 
580
- # Outputs: file-list, store-shred, ...names for uploads, ...upload contents, ...radio values, document-preview, loading-output, store-pink, store-pink-review, store-red, store-red-review, store-gold, store-gold-review, store-loe, store-virtual-board, chat-output, download-document
581
- outputs = [dash.no_update] * 32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
582
 
583
  # --- File upload/remove logic ---
584
- # Handle Shred upload
585
  if ctx.triggered and ctx.triggered[0]['prop_id'].startswith('upload-document'):
586
  new_files = []
587
  if upload_contents is not None:
@@ -608,7 +664,6 @@ def master_callback(
608
  outputs[1] = current_shred
609
  return outputs
610
 
611
- # Handle file removal
612
  if ctx.triggered and ctx.triggered[0]['prop_id'].startswith("{\"type\":\"remove-file\""):
613
  try:
614
  import json
@@ -635,7 +690,6 @@ def master_callback(
635
  outputs[1] = remove_current_shred
636
  return outputs
637
 
638
- # Handle all doc-type uploads for preview and radio
639
  doc_upload_types = [
640
  ("shred", upload_shred_contents, upload_shred_filenames, upload_shred_ids, 2, 8, 14),
641
  ("pink", upload_pink_contents, upload_pink_filenames, upload_pink_ids, 3, 9, 15),
@@ -650,13 +704,20 @@ def master_callback(
650
  if content is not None:
651
  uploaded_doc_contents[(src, ids[i]['index'])] = (content, filenames[i])
652
  logging.info(f"{ids[i]['index']} {src} file uploaded: {filenames[i]}")
653
- outputs[name_idx] = [filenames[i] if j==i else "" for j in range(len(contents))]
654
- outputs[content_idx] = [content if j==i else None for j in range(len(contents))]
655
- outputs[radio_idx] = ["uploaded" if j==i else "loaded" for j in range(len(contents))]
 
 
 
 
 
 
 
656
  return outputs
657
 
658
  # --- Document generation/chat/download logic ---
659
- def gemini_generate(prompt, max_tokens=4096, temperature=0.25):
660
  result_holder = {}
661
  def run_gemini():
662
  try:
@@ -710,7 +771,6 @@ Now, generate the {document_type}:
710
  logging.info(f"Generating document for type: {document_type} using Gemini.")
711
  return gemini_generate(prompt, max_tokens=4096, temperature=0.25)
712
 
713
- # Document generation triggers
714
  if ctx.triggered and ctx.triggered[0]['prop_id'].startswith("{\"type\":\"btn-generate-doc\""):
715
  idx = [i for i, x in enumerate(n_clicks_list) if x]
716
  if not idx:
@@ -894,7 +954,6 @@ Now, generate the {document_type}:
894
  outputs[21] = ""
895
  return outputs
896
 
897
- # Chat triggers
898
  if ctx.triggered and (ctx.triggered[0]['prop_id'] == 'btn-send-chat.n_clicks' or ctx.triggered[0]['prop_id'] == 'btn-clear-chat.n_clicks'):
899
  if ctx.triggered[0]['prop_id'] == 'btn-clear-chat.n_clicks':
900
  outputs[30] = ""
@@ -956,7 +1015,6 @@ Now, provide the updated {chat_doc_type}:
956
  outputs[30] = f"Error updating document: {str(e)}"
957
  return outputs
958
 
959
- # Download trigger
960
  if ctx.triggered and ctx.triggered[0]['prop_id'] == "btn-download.n_clicks":
961
  doc_map = {
962
  "Shred": dl_store_shred,
 
449
  def update_right_col(selected_type, shred_doc, pink_doc, pink_review_doc, red_doc, red_review_doc, gold_doc):
450
  return get_right_col_content(selected_type, shred_doc, pink_doc, pink_review_doc, red_doc, red_review_doc, gold_doc)
451
 
452
+ def get_all_lengths(*args):
453
+ return [len(x) if isinstance(x, list) else 0 for x in args]
454
+
455
  @app.callback(
456
  Output('file-list', 'children'),
457
  Output('store-shred', 'data'),
 
580
  global uploaded_files, uploaded_doc_contents
581
  ctx = callback_context
582
 
583
+ # Get lengths for all wildcard outputs for correct no_update list length
584
+ wildcard_lengths = [
585
+ len(upload_shred_ids) if upload_shred_ids is not None else 0,
586
+ len(upload_pink_ids) if upload_pink_ids is not None else 0,
587
+ len(upload_pink_review_ids) if upload_pink_review_ids is not None else 0,
588
+ len(upload_red_ids) if upload_red_ids is not None else 0,
589
+ len(upload_red_review_ids) if upload_red_review_ids is not None else 0,
590
+ len(upload_gold_ids) if upload_gold_ids is not None else 0,
591
+ len(upload_shred_ids) if upload_shred_ids is not None else 0,
592
+ len(upload_pink_ids) if upload_pink_ids is not None else 0,
593
+ len(upload_pink_review_ids) if upload_pink_review_ids is not None else 0,
594
+ len(upload_red_ids) if upload_red_ids is not None else 0,
595
+ len(upload_red_review_ids) if upload_red_review_ids is not None else 0,
596
+ len(upload_gold_ids) if upload_gold_ids is not None else 0,
597
+ len(upload_shred_ids) if upload_shred_ids is not None else 0,
598
+ len(upload_pink_ids) if upload_pink_ids is not None else 0,
599
+ len(upload_pink_review_ids) if upload_pink_review_ids is not None else 0,
600
+ len(upload_red_ids) if upload_red_ids is not None else 0,
601
+ len(upload_red_review_ids) if upload_red_review_ids is not None else 0,
602
+ len(upload_gold_ids) if upload_gold_ids is not None else 0,
603
+ ]
604
+
605
+ outputs = [
606
+ dash.no_update, # file-list
607
+ dash.no_update, # store-shred
608
+ [dash.no_update] * wildcard_lengths[0], # uploaded-doc-name-shred
609
+ [dash.no_update] * wildcard_lengths[1], # uploaded-doc-name-pink
610
+ [dash.no_update] * wildcard_lengths[2], # uploaded-doc-name-pink_review
611
+ [dash.no_update] * wildcard_lengths[3], # uploaded-doc-name-red
612
+ [dash.no_update] * wildcard_lengths[4], # uploaded-doc-name-red_review
613
+ [dash.no_update] * wildcard_lengths[5], # uploaded-doc-name-gold
614
+ [dash.no_update] * wildcard_lengths[6], # upload-doc-type-shred.contents
615
+ [dash.no_update] * wildcard_lengths[7], # upload-doc-type-pink.contents
616
+ [dash.no_update] * wildcard_lengths[8], # upload-doc-type-pink_review.contents
617
+ [dash.no_update] * wildcard_lengths[9], # upload-doc-type-red.contents
618
+ [dash.no_update] * wildcard_lengths[10], # upload-doc-type-red_review.contents
619
+ [dash.no_update] * wildcard_lengths[11], # upload-doc-type-gold.contents
620
+ [dash.no_update] * wildcard_lengths[12], # radio-doc-source-shred.value
621
+ [dash.no_update] * wildcard_lengths[13], # radio-doc-source-pink.value
622
+ [dash.no_update] * wildcard_lengths[14], # radio-doc-source-pink_review.value
623
+ [dash.no_update] * wildcard_lengths[15], # radio-doc-source-red.value
624
+ [dash.no_update] * wildcard_lengths[16], # radio-doc-source-red_review.value
625
+ [dash.no_update] * wildcard_lengths[17], # radio-doc-source-gold.value
626
+ dash.no_update, # document-preview
627
+ dash.no_update, # loading-output
628
+ dash.no_update, # store-pink
629
+ dash.no_update, # store-pink-review
630
+ dash.no_update, # store-red
631
+ dash.no_update, # store-red-review
632
+ dash.no_update, # store-gold
633
+ dash.no_update, # store-gold-review
634
+ dash.no_update, # store-loe
635
+ dash.no_update, # store-virtual-board
636
+ dash.no_update, # chat-output
637
+ dash.no_update # download-document
638
+ ]
639
 
640
  # --- File upload/remove logic ---
 
641
  if ctx.triggered and ctx.triggered[0]['prop_id'].startswith('upload-document'):
642
  new_files = []
643
  if upload_contents is not None:
 
664
  outputs[1] = current_shred
665
  return outputs
666
 
 
667
  if ctx.triggered and ctx.triggered[0]['prop_id'].startswith("{\"type\":\"remove-file\""):
668
  try:
669
  import json
 
690
  outputs[1] = remove_current_shred
691
  return outputs
692
 
 
693
  doc_upload_types = [
694
  ("shred", upload_shred_contents, upload_shred_filenames, upload_shred_ids, 2, 8, 14),
695
  ("pink", upload_pink_contents, upload_pink_filenames, upload_pink_ids, 3, 9, 15),
 
704
  if content is not None:
705
  uploaded_doc_contents[(src, ids[i]['index'])] = (content, filenames[i])
706
  logging.info(f"{ids[i]['index']} {src} file uploaded: {filenames[i]}")
707
+ # For wildcard outputs, always return a list with the correct length
708
+ name_list = ["" for _ in range(len(contents))]
709
+ content_list = [None for _ in range(len(contents))]
710
+ radio_list = ["loaded" for _ in range(len(contents))]
711
+ name_list[i] = filenames[i]
712
+ content_list[i] = content
713
+ radio_list[i] = "uploaded"
714
+ outputs[name_idx] = name_list
715
+ outputs[content_idx] = content_list
716
+ outputs[radio_idx] = radio_list
717
  return outputs
718
 
719
  # --- Document generation/chat/download logic ---
720
+ def gemini_generate(prompt, max_tokens=32798, temperature=0.4):
721
  result_holder = {}
722
  def run_gemini():
723
  try:
 
771
  logging.info(f"Generating document for type: {document_type} using Gemini.")
772
  return gemini_generate(prompt, max_tokens=4096, temperature=0.25)
773
 
 
774
  if ctx.triggered and ctx.triggered[0]['prop_id'].startswith("{\"type\":\"btn-generate-doc\""):
775
  idx = [i for i, x in enumerate(n_clicks_list) if x]
776
  if not idx:
 
954
  outputs[21] = ""
955
  return outputs
956
 
 
957
  if ctx.triggered and (ctx.triggered[0]['prop_id'] == 'btn-send-chat.n_clicks' or ctx.triggered[0]['prop_id'] == 'btn-clear-chat.n_clicks'):
958
  if ctx.triggered[0]['prop_id'] == 'btn-clear-chat.n_clicks':
959
  outputs[30] = ""
 
1015
  outputs[30] = f"Error updating document: {str(e)}"
1016
  return outputs
1017
 
 
1018
  if ctx.triggered and ctx.triggered[0]['prop_id'] == "btn-download.n_clicks":
1019
  doc_map = {
1020
  "Shred": dl_store_shred,