VyLala commited on
Commit
354c243
Β·
verified Β·
1 Parent(s): 615fc65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +230 -71
app.py CHANGED
@@ -26,8 +26,7 @@ custom_css = """
26
  width: 100%; height: 100%;
27
  background: rgba(0,0,0,0.6);
28
  z-index: 9999;
29
- display: flex;
30
- flex-direction: column;
31
  justify-content: center;
32
  align-items: center;
33
  }
@@ -41,6 +40,7 @@ custom_css = """
41
  }
42
  """
43
 
 
44
  with gr.Blocks() as interface:
45
  # with gr.Tab("CURIOUS ABOUT THIS PRODUCT?"):
46
  # gr.HTML(value=pricing_html)
@@ -73,6 +73,16 @@ with gr.Blocks() as interface:
73
 
74
  status = gr.Markdown(visible=False)
75
 
 
 
 
 
 
 
 
 
 
 
76
  with gr.Group(visible=False) as results_group:
77
  # with gr.Accordion("Open to See the Result", open=False) as results:
78
  # with gr.Row():
@@ -97,10 +107,10 @@ with gr.Blocks() as interface:
97
  submit_report_button = gr.Button("Submit", visible=False)
98
  status_report = gr.Markdown(visible=False)
99
 
100
- nps_question = gr.Markdown("### How likely are you to recommend this tool to a colleague or peer (0 = Not at all, 10 = Definitely)?")
101
- nps_slider = gr.Slider(minimum=0, maximum=10, step=1, label="Your NPS Score (0-10)")
102
- nps_button = gr.Button("Submit")
103
- nps_output = gr.Textbox(label="", interactive=False, visible=True) # Start empty
104
 
105
  download_file = gr.File(label="Download File Here", visible=False, interactive=True)
106
  progress_box = gr.Textbox(label="Live Processing Log", lines=20, interactive=False)
@@ -488,17 +498,26 @@ with gr.Blocks() as interface:
488
  )
489
  return
490
  limited_acc = int(max_allowed-usage_count)
 
 
 
 
491
  yield (
492
- "",
493
- gr.update(visible=False),
494
- gr.update(visible=False), # show stop button
495
- "",
 
 
 
 
 
 
 
496
  gr.update(value=f"Processed/Input accessions: {', '.join(accessions)}", visible=True), # processed_info
497
- "⏳ Processing...",
498
  )
499
 
500
- # Step 1: Parse input
501
- accessions, error = extract_accessions_from_input(file, text)
502
  log_submission_to_gsheet(email, accessions)
503
 
504
  print("πŸ§ͺ Accessions received:", accessions)
@@ -569,26 +588,59 @@ with gr.Blocks() as interface:
569
  else:
570
  usage_text = f"The limited accession is 30. The user has used {processed_accessions}, and only {30 - processed_accessions} left."
571
 
 
 
 
 
 
 
 
 
 
572
  yield (
573
  make_html_table(all_rows),
574
- gr.update(visible=True),
575
- #gr.update(value=output_file_path, visible=True),
576
- gr.update(value=output_file_path, visible=bool(output_file_path)),
577
- gr.update(value=usage_text, visible=True),
578
- "πŸ›‘ Stopped",
579
- "\n".join(log_lines)
 
 
 
 
 
 
580
  )
 
581
  return
582
 
583
  log_lines.append(f"[{i+1}/{total}] Processing {acc}")
 
 
 
 
 
 
 
 
 
584
  yield (
585
- make_html_table(all_rows),
586
- gr.update(visible=True),
587
- gr.update(visible=False),
588
- "",
589
- "⏳ Processing...",
590
- "\n".join(log_lines)
 
 
 
 
 
 
 
591
  )
 
592
 
593
  # try:
594
  # print("πŸ“„ Processing accession:", acc)
@@ -611,14 +663,30 @@ with gr.Blocks() as interface:
611
  # If stop was pressed during this accession
612
  if not success and global_stop_flag.value:
613
  log_lines.append(f"πŸ›‘ Cancelled {acc} before completion")
 
 
 
 
 
 
 
 
614
  yield (
615
  make_html_table(all_rows),
616
- gr.update(visible=True),
617
- gr.update(visible=False),
618
- "",
619
- "πŸ›‘ Stopped",
620
- "\n".join(log_lines)
 
 
 
 
 
 
 
621
  )
 
622
  break # stop processing entirely
623
 
624
  # If it finished normally
@@ -634,14 +702,29 @@ with gr.Blocks() as interface:
634
  log_lines.append(f"⚠️ Skipped {acc} due to timeout or error")
635
 
636
  # Always yield updated logs after each attempt
 
 
 
 
 
 
 
 
637
  yield (
638
- make_html_table(all_rows),
639
- gr.update(visible=True),
640
- gr.update(visible=False),
641
- "",
642
- "⏳ Processing...",
643
- "\n".join(log_lines)
644
- )
 
 
 
 
 
 
 
645
 
646
  # except Exception as e:
647
  # log_lines.append(f"❌ Failed to process {acc}: {e}")
@@ -666,14 +749,29 @@ with gr.Blocks() as interface:
666
  elif not email.strip():
667
  usage_text = f"The limited accession is 30. The user has used {processed_accessions}, and only {30 - processed_accessions} left."
668
 
 
 
 
 
 
 
 
 
 
669
  yield (
670
  make_html_table(all_rows),
671
- gr.update(visible=True),
672
- #gr.update(value=output_file_path, visible=True),
673
- gr.update(value=output_file_path, visible=bool(output_file_path)),
674
- gr.update(value=usage_text, visible=True),
675
- "βœ… Done",
676
- "\n".join(log_lines)
 
 
 
 
 
 
677
  )
678
 
679
  # SUBMIT REPORT UI
@@ -811,25 +909,43 @@ with gr.Blocks() as interface:
811
  # gr.update(value="", visible=False), # usage_display
812
  # gr.update(value="", visible=False), # progress_box
813
  # )
814
- def reset_fields():
815
- global_stop_flag.value = True # Reset the stop flag
816
 
817
- return (
818
- gr.update(value=""), # raw_text
819
- gr.update(value=None), # file_upload
820
- gr.update(value=[], visible=True), # output_table
821
- gr.update(value="", visible=True), # status β€” reset and make visible again
822
- gr.update(visible=False), # results_group
823
- gr.update(value="", visible=True), # usage_display β€” reset and make visible again
824
- gr.update(value="", visible=True), # progress_box οΏ½οΏ½ reset AND visible!
825
- # report-related reset below
826
- gr.update(value="", visible=False), # report_textbox
827
- gr.update(visible=False), # submit_report_button
828
- gr.update(value="", visible=False), # status_report
829
- gr.update(value=0), # nps_slider
830
- gr.update(value="", visible=False) # nps_output
831
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
832
  )
 
833
 
834
  #inputMode.change(fn=toggle_input_mode, inputs=inputMode, outputs=[single_input_group, batch_input_group])
835
  #run_button.click(fn=classify_with_loading, inputs=[], outputs=[status])
@@ -878,14 +994,36 @@ with gr.Blocks() as interface:
878
  # )
879
  interface.queue() # No arguments here!
880
 
 
 
 
 
 
 
 
 
881
  run_button.click(
882
  fn=threaded_batch_runner,
883
  inputs=[file_upload, raw_text, user_email],
884
- outputs=[output_table, results_group, download_file, usage_display, status, progress_box],
885
- concurrency_limit=1, # βœ… correct in Gradio 5.x
886
- queue=True, # βœ… ensure the queue is used
887
- #every=0.5
 
 
 
 
 
 
 
 
 
 
 
 
 
888
  )
 
889
 
890
 
891
 
@@ -907,15 +1045,34 @@ with gr.Blocks() as interface:
907
  # )
908
  #stop_button.click(fn=lambda sf: (gr.update(value="❌ Stopping...", visible=True), setattr(sf, "value", True) or sf), inputs=[gr.State(stop_flag)], outputs=[status, gr.State(stop_flag)])
909
 
 
 
 
 
 
 
 
 
 
910
  reset_button.click(
911
  fn=reset_fields,
912
  inputs=[],
913
- #outputs=[raw_text, file_upload, resume_file, output_table, status, results_group, usage_display, progress_box]
914
- outputs=[raw_text, file_upload, output_table, status, results_group, usage_display, progress_box,
915
- report_textbox,
916
- submit_report_button,
917
- status_report, nps_slider, nps_output]
918
- )
 
 
 
 
 
 
 
 
 
 
919
 
920
  # download_button.click(
921
  # fn=mtdna_backend.save_batch_output,
@@ -936,8 +1093,10 @@ with gr.Blocks() as interface:
936
  outputs=[feedback_status]
937
  )
938
 
939
- nps_button.click(fn=submit_nps, inputs=[user_email, nps_slider], outputs=nps_output)
940
-
 
 
941
 
942
  gr.HTML("""
943
  <style>
 
26
  width: 100%; height: 100%;
27
  background: rgba(0,0,0,0.6);
28
  z-index: 9999;
29
+ display: none; /* hidden by default */
 
30
  justify-content: center;
31
  align-items: center;
32
  }
 
40
  }
41
  """
42
 
43
+
44
  with gr.Blocks() as interface:
45
  # with gr.Tab("CURIOUS ABOUT THIS PRODUCT?"):
46
  # gr.HTML(value=pricing_html)
 
73
 
74
  status = gr.Markdown(visible=False)
75
 
76
+ with gr.Group(visible=False, elem_id="nps-overlay") as nps_modal:
77
+ with gr.Column(elem_id="nps-box"):
78
+ gr.Markdown("### How likely are you to recommend this tool to a colleague or peer?")
79
+ nps_slider = gr.Slider(minimum=0, maximum=10, step=1, label="Your NPS Score (0-10)")
80
+ nps_text = gr.Textbox(label="Any feedback?", lines=3)
81
+ with gr.Row():
82
+ nps_submit = gr.Button("Submit")
83
+ nps_close = gr.Button("X", elem_id="nps-close")
84
+
85
+
86
  with gr.Group(visible=False) as results_group:
87
  # with gr.Accordion("Open to See the Result", open=False) as results:
88
  # with gr.Row():
 
107
  submit_report_button = gr.Button("Submit", visible=False)
108
  status_report = gr.Markdown(visible=False)
109
 
110
+ # nps_question = gr.Markdown("### How likely are you to recommend this tool to a colleague or peer (0 = Not at all, 10 = Definitely)?")
111
+ # nps_slider = gr.Slider(minimum=0, maximum=10, step=1, label="Your NPS Score (0-10)")
112
+ # nps_button = gr.Button("Submit")
113
+ # nps_output = gr.Textbox(label="", interactive=False, visible=True) # Start empty
114
 
115
  download_file = gr.File(label="Download File Here", visible=False, interactive=True)
116
  progress_box = gr.Textbox(label="Live Processing Log", lines=20, interactive=False)
 
498
  )
499
  return
500
  limited_acc = int(max_allowed-usage_count)
501
+
502
+ # Step 1: Parse input
503
+ accessions, error = extract_accessions_from_input(file, text)
504
+ ### NEW: Hide inputs, show processed_info at start
505
  yield (
506
+ make_html_table(all_rows), # output_table
507
+ gr.update(visible=False), # results_group
508
+ gr.update(visible=False), # download_file
509
+ "", # usage_display
510
+ "⏳ Processing...", # status
511
+ "", # progess_box
512
+ gr.update(visible=True), # run_button,
513
+ gr.update(visible=True), # show stop button
514
+ gr.update(visible=True), # show reset button
515
+ gr.update(visible=False), # hide raw_text
516
+ gr.update(visible=False), # hide file_upload
517
  gr.update(value=f"Processed/Input accessions: {', '.join(accessions)}", visible=True), # processed_info
518
+ gr.update(visible=False) # hide NPS modal at start
519
  )
520
 
 
 
521
  log_submission_to_gsheet(email, accessions)
522
 
523
  print("πŸ§ͺ Accessions received:", accessions)
 
588
  else:
589
  usage_text = f"The limited accession is 30. The user has used {processed_accessions}, and only {30 - processed_accessions} left."
590
 
591
+ # yield (
592
+ # make_html_table(all_rows),
593
+ # gr.update(visible=True),
594
+ # #gr.update(value=output_file_path, visible=True),
595
+ # gr.update(value=output_file_path, visible=bool(output_file_path)),
596
+ # gr.update(value=usage_text, visible=True),
597
+ # "πŸ›‘ Stopped",
598
+ # "\n".join(log_lines)
599
+ # )
600
  yield (
601
  make_html_table(all_rows),
602
+ gr.update(visible=True), # results_group
603
+ gr.update(value=output_file_path, visible=bool(output_file_path)), # download_file
604
+ gr.update(value=usage_text, visible=True), # usage_display
605
+ "πŸ›‘ Stopped", # "βœ… Done" or "πŸ›‘ Stopped"
606
+ "\n".join(log_lines),
607
+ gr.update(visible=False), # run_button
608
+ gr.update(visible=False), # stop_button
609
+ gr.update(visible=True), # reset_button
610
+ gr.update(visible=False), # raw_text
611
+ gr.update(visible=False), # file_upload
612
+ gr.update(value="", visible=False), # processed_info
613
+ gr.update(visible=True) # NPS modal now visible
614
  )
615
+
616
  return
617
 
618
  log_lines.append(f"[{i+1}/{total}] Processing {acc}")
619
+ # yield (
620
+ # make_html_table(all_rows),
621
+ # gr.update(visible=True),
622
+ # gr.update(visible=False),
623
+ # "",
624
+ # "⏳ Processing...",
625
+ # "\n".join(log_lines)
626
+ # )
627
+ # Hide inputs, show processed_info at start
628
  yield (
629
+ make_html_table(all_rows), # output_table
630
+ gr.update(visible=True), # results_group
631
+ gr.update(visible=False), # download_file
632
+ "", # usage_display
633
+ "⏳ Processing...", # status
634
+ "\n".join(log_lines), # progress_box
635
+ gr.update(visible=True), # run_button
636
+ gr.update(visible=True), # stop_button
637
+ gr.update(visible=True), # reset_button
638
+ gr.update(visible=False), # hide raw_text
639
+ gr.update(visible=False), # hide file_upload
640
+ gr.update(value=f"Processed/Input accessions: {', '.join(accessions)}", visible=True), # processed_info
641
+ gr.update(visible=False) # hide NPS modal at start
642
  )
643
+
644
 
645
  # try:
646
  # print("πŸ“„ Processing accession:", acc)
 
663
  # If stop was pressed during this accession
664
  if not success and global_stop_flag.value:
665
  log_lines.append(f"πŸ›‘ Cancelled {acc} before completion")
666
+ # yield (
667
+ # make_html_table(all_rows),
668
+ # gr.update(visible=True),
669
+ # gr.update(visible=False),
670
+ # "",
671
+ # "πŸ›‘ Stopped",
672
+ # "\n".join(log_lines)
673
+ # )
674
  yield (
675
  make_html_table(all_rows),
676
+ gr.update(visible=True), # results_group
677
+ gr.update(value=output_file_path, visible=bool(output_file_path)), # download_file
678
+ gr.update(value=usage_text, visible=True), # usage_display
679
+ "πŸ›‘ Stopped", # "βœ… Done" or "πŸ›‘ Stopped"
680
+ "\n".join(log_lines),
681
+ gr.update(visible=False), # run_button
682
+ gr.update(visible=False), # stop_button
683
+ gr.update(visible=True), # reset_button
684
+ gr.update(visible=False), # raw_text
685
+ gr.update(visible=False), # file_upload
686
+ gr.update(value="", visible=False), # processed_info
687
+ gr.update(visible=True) # NPS modal now visible
688
  )
689
+
690
  break # stop processing entirely
691
 
692
  # If it finished normally
 
702
  log_lines.append(f"⚠️ Skipped {acc} due to timeout or error")
703
 
704
  # Always yield updated logs after each attempt
705
+ # yield (
706
+ # make_html_table(all_rows),
707
+ # gr.update(visible=True),
708
+ # gr.update(visible=False),
709
+ # "",
710
+ # "⏳ Processing...",
711
+ # "\n".join(log_lines)
712
+ # )
713
  yield (
714
+ make_html_table(all_rows), # output_table
715
+ gr.update(visible=True), # results_group
716
+ gr.update(visible=False), # download_file
717
+ "", # usage_display
718
+ "⏳ Processing...", # status
719
+ "\n".join(log_lines), # progress_box
720
+ gr.update(visible=True), # run_button
721
+ gr.update(visible=True), # stop_button
722
+ gr.update(visible=True), # reset_button
723
+ gr.update(visible=False), # hide raw_text
724
+ gr.update(visible=False), # hide file_upload
725
+ gr.update(value=f"Processed/Input accessions: {', '.join(accessions)}", visible=True), # processed_info
726
+ gr.update(visible=False) # hide NPS modal at start
727
+ )
728
 
729
  # except Exception as e:
730
  # log_lines.append(f"❌ Failed to process {acc}: {e}")
 
749
  elif not email.strip():
750
  usage_text = f"The limited accession is 30. The user has used {processed_accessions}, and only {30 - processed_accessions} left."
751
 
752
+ # yield (
753
+ # make_html_table(all_rows),
754
+ # gr.update(visible=True),
755
+ # #gr.update(value=output_file_path, visible=True),
756
+ # gr.update(value=output_file_path, visible=bool(output_file_path)),
757
+ # gr.update(value=usage_text, visible=True),
758
+ # "βœ… Done",
759
+ # "\n".join(log_lines)
760
+ # )
761
  yield (
762
  make_html_table(all_rows),
763
+ gr.update(visible=True), # results_group
764
+ gr.update(value=output_file_path, visible=bool(output_file_path)), # download_file
765
+ gr.update(value=usage_text, visible=True), # usage_display
766
+ "βœ… Done", # "βœ… Done" or "πŸ›‘ Stopped"
767
+ "\n".join(log_lines),
768
+ gr.update(visible=False), # run_button
769
+ gr.update(visible=False), # stop_button
770
+ gr.update(visible=True), # reset_button
771
+ gr.update(visible=False), # raw_text
772
+ gr.update(visible=False), # file_upload
773
+ gr.update(value="", visible=False), # processed_info
774
+ gr.update(visible=True) # NPS modal now visible
775
  )
776
 
777
  # SUBMIT REPORT UI
 
909
  # gr.update(value="", visible=False), # usage_display
910
  # gr.update(value="", visible=False), # progress_box
911
  # )
912
+ # def reset_fields():
913
+ # global_stop_flag.value = True # Reset the stop flag
914
 
915
+ # return (
916
+ # gr.update(value=""), # raw_text
917
+ # gr.update(value=None), # file_upload
918
+ # gr.update(value=[], visible=True), # output_table
919
+ # gr.update(value="", visible=True), # status β€” reset and make visible again
920
+ # gr.update(visible=False), # results_group
921
+ # gr.update(value="", visible=True), # usage_display β€” reset and make visible again
922
+ # gr.update(value="", visible=True), # progress_box β€” reset AND visible!
923
+ # # report-related reset below
924
+ # gr.update(value="", visible=False), # report_textbox
925
+ # gr.update(visible=False), # submit_report_button
926
+ # gr.update(value="", visible=False), # status_report
927
+ # gr.update(value=0), # nps_slider
928
+ # gr.update(value="", visible=False) # nps_output
929
 
930
+ # )
931
+ def reset_fields():
932
+ global_stop_flag.value = True # Stop any running job
933
+
934
+ return (
935
+ gr.update(value="", visible=True), # raw_text
936
+ gr.update(value=None, visible=True), # file_upload
937
+ gr.update(value=[], visible=True), # output_table
938
+ gr.update(value="", visible=True), # status
939
+ gr.update(visible=False), # results_group
940
+ gr.update(value="", visible=True), # usage_display
941
+ gr.update(value="", visible=True), # progress_box
942
+ gr.update(value="", visible=False), # report_textbox
943
+ gr.update(visible=False), # submit_report_button
944
+ gr.update(value="", visible=False), # status_report
945
+ gr.update(value="", visible=False), # processed_info
946
+ gr.update(visible=False) # hide NPS modal
947
  )
948
+
949
 
950
  #inputMode.change(fn=toggle_input_mode, inputs=inputMode, outputs=[single_input_group, batch_input_group])
951
  #run_button.click(fn=classify_with_loading, inputs=[], outputs=[status])
 
994
  # )
995
  interface.queue() # No arguments here!
996
 
997
+ # run_button.click(
998
+ # fn=threaded_batch_runner,
999
+ # inputs=[file_upload, raw_text, user_email],
1000
+ # outputs=[output_table, results_group, download_file, usage_display, status, progress_box],
1001
+ # concurrency_limit=1, # βœ… correct in Gradio 5.x
1002
+ # queue=True, # βœ… ensure the queue is used
1003
+ # #every=0.5
1004
+ # )
1005
  run_button.click(
1006
  fn=threaded_batch_runner,
1007
  inputs=[file_upload, raw_text, user_email],
1008
+ outputs=[
1009
+ output_table, # 1
1010
+ results_group, # 2
1011
+ download_file, # 3
1012
+ usage_display, # 4
1013
+ status, # 5
1014
+ progress_box, # 6
1015
+ run_button, # 7
1016
+ stop_button, # 8
1017
+ reset_button, # 9
1018
+ raw_text, # 10
1019
+ file_upload, # 11
1020
+ processed_info, # 12
1021
+ nps_modal # 13
1022
+ ],
1023
+ concurrency_limit=1,
1024
+ queue=True
1025
  )
1026
+
1027
 
1028
 
1029
 
 
1045
  # )
1046
  #stop_button.click(fn=lambda sf: (gr.update(value="❌ Stopping...", visible=True), setattr(sf, "value", True) or sf), inputs=[gr.State(stop_flag)], outputs=[status, gr.State(stop_flag)])
1047
 
1048
+ # reset_button.click(
1049
+ # fn=reset_fields,
1050
+ # inputs=[],
1051
+ # #outputs=[raw_text, file_upload, resume_file, output_table, status, results_group, usage_display, progress_box]
1052
+ # outputs=[raw_text, file_upload, output_table, status, results_group, usage_display, progress_box,
1053
+ # report_textbox,
1054
+ # submit_report_button,
1055
+ # status_report, nps_slider, nps_output]
1056
+ # )
1057
  reset_button.click(
1058
  fn=reset_fields,
1059
  inputs=[],
1060
+ outputs=[
1061
+ raw_text,
1062
+ file_upload,
1063
+ output_table,
1064
+ status,
1065
+ results_group,
1066
+ usage_display,
1067
+ progress_box,
1068
+ report_textbox,
1069
+ submit_report_button,
1070
+ status_report,
1071
+ processed_info,
1072
+ nps_modal
1073
+ ]
1074
+ )
1075
+
1076
 
1077
  # download_button.click(
1078
  # fn=mtdna_backend.save_batch_output,
 
1093
  outputs=[feedback_status]
1094
  )
1095
 
1096
+ #nps_button.click(fn=submit_nps, inputs=[user_email, nps_slider], outputs=nps_output)
1097
+ nps_submit.click(fn=submit_nps, inputs=[user_email, nps_slider, nps_text], outputs=[])
1098
+ nps_close.click(fn=lambda: gr.update(visible=False), outputs=[nps_modal])
1099
+
1100
 
1101
  gr.HTML("""
1102
  <style>