DocUA commited on
Commit
36ba4ed
·
1 Parent(s): 346aa2c

Refactor session results retrieval to return a 2D list and update export button visibility logic

Browse files
src/interface/manual_input_interface.py CHANGED
@@ -281,7 +281,7 @@ class ManualInputController(ProgressTrackingMixin):
281
  except Exception as e:
282
  return False, f"❌ Error saving verification: {str(e)}", {}
283
 
284
- def get_session_results(self) -> List[Dict[str, Any]]:
285
  """
286
  Get all results from the current session.
287
 
@@ -296,18 +296,21 @@ class ManualInputController(ProgressTrackingMixin):
296
  if not session:
297
  return []
298
 
299
- results = []
 
 
 
300
  for record in session.verifications:
301
- results.append({
302
- "message": record.original_message,
303
- "classifier_decision": record.classifier_decision.upper(),
304
- "ground_truth": record.ground_truth_label.upper(),
305
- "is_correct": "✓" if record.is_correct else "✗",
306
- "confidence": f"{record.classifier_confidence * 100:.1f}%",
307
- "indicators": ", ".join(record.classifier_indicators),
308
- "notes": record.verifier_notes,
309
- "timestamp": record.timestamp.strftime("%Y-%m-%d %H:%M:%S")
310
- })
311
 
312
  return results
313
 
@@ -597,16 +600,10 @@ def create_manual_input_interface() -> gr.Blocks:
597
  # Export options
598
  gr.Markdown("## 💾 Export Options")
599
  with gr.Column():
600
- # Keep the existing buttons to show a status message,
601
- # but also provide direct downloads via DownloadButton.
602
- export_csv_btn = StandardizedComponents.create_export_button("csv")
603
- download_csv_btn = gr.DownloadButton("⬇️ Download CSV", variant="secondary")
604
-
605
- export_json_btn = StandardizedComponents.create_export_button("json")
606
- download_json_btn = gr.DownloadButton("⬇️ Download JSON", variant="secondary")
607
-
608
- export_xlsx_btn = StandardizedComponents.create_export_button("xlsx")
609
- download_xlsx_btn = gr.DownloadButton("⬇️ Download XLSX", variant="secondary")
610
 
611
  # Complete session
612
  gr.Markdown("## 🏁 Session Control")
@@ -653,6 +650,9 @@ def create_manual_input_interface() -> gr.Blocks:
653
  gr.Row(visible=True), # manual_input_section
654
  gr.Row(visible=True), # results_history_section
655
  session_info, # session_info_display
 
 
 
656
  message # status_message
657
  )
658
  else:
@@ -661,6 +661,9 @@ def create_manual_input_interface() -> gr.Blocks:
661
  gr.Row(visible=False), # manual_input_section
662
  gr.Row(visible=False), # results_history_section
663
  "Enter your name and click 'Start Session' to begin", # session_info_display
 
 
 
664
  message # status_message
665
  )
666
 
@@ -707,6 +710,9 @@ def create_manual_input_interface() -> gr.Blocks:
707
  gr.Row(visible=False), # correction_section
708
  stats_text, # session_stats_display
709
  results, # results_display
 
 
 
710
  message # status_message
711
  )
712
  else:
@@ -716,6 +722,9 @@ def create_manual_input_interface() -> gr.Blocks:
716
  gr.Row(visible=False), # correction_section
717
  gr.Markdown(value=""), # session_stats_display (no change)
718
  gr.Dataframe(value=[]), # results_display (no change)
 
 
 
719
  message # status_message
720
  )
721
 
@@ -744,6 +753,9 @@ def create_manual_input_interface() -> gr.Blocks:
744
  "", # correction_notes (clear)
745
  stats_text, # session_stats_display
746
  results, # results_display
 
 
 
747
  message # status_message
748
  )
749
  else:
@@ -754,14 +766,12 @@ def create_manual_input_interface() -> gr.Blocks:
754
  notes, # correction_notes (keep)
755
  gr.Markdown(value=""), # session_stats_display (no change)
756
  gr.Dataframe(value=[]), # results_display (no change)
 
 
 
757
  message # status_message
758
  )
759
 
760
- def on_export_results(format_type):
761
- """Handle results export."""
762
- success, message, file_path = controller.export_session_results(format_type)
763
- return message
764
-
765
  def on_export_results_file(format_type):
766
  """Handle results export for DownloadButton (returns file path)."""
767
  success, message, file_path = controller.export_session_results(format_type)
@@ -812,6 +822,9 @@ def create_manual_input_interface() -> gr.Blocks:
812
  manual_input_section,
813
  results_history_section,
814
  session_info_display,
 
 
 
815
  status_message
816
  ]
817
  )
@@ -836,6 +849,9 @@ def create_manual_input_interface() -> gr.Blocks:
836
  correction_section,
837
  session_stats_display,
838
  results_display,
 
 
 
839
  status_message
840
  ]
841
  )
@@ -855,35 +871,23 @@ def create_manual_input_interface() -> gr.Blocks:
855
  correction_notes,
856
  session_stats_display,
857
  results_display,
 
 
 
858
  status_message
859
  ]
860
  )
861
 
862
- export_csv_btn.click(
863
- lambda: on_export_results("csv"),
864
- outputs=[status_message]
865
- )
866
-
867
  download_csv_btn.click(
868
  lambda: on_export_results_file("csv"),
869
  outputs=[download_csv_btn]
870
  )
871
 
872
- export_json_btn.click(
873
- lambda: on_export_results("json"),
874
- outputs=[status_message]
875
- )
876
-
877
  download_json_btn.click(
878
  lambda: on_export_results_file("json"),
879
  outputs=[download_json_btn]
880
  )
881
 
882
- export_xlsx_btn.click(
883
- lambda: on_export_results("xlsx"),
884
- outputs=[status_message]
885
- )
886
-
887
  download_xlsx_btn.click(
888
  lambda: on_export_results_file("xlsx"),
889
  outputs=[download_xlsx_btn]
 
281
  except Exception as e:
282
  return False, f"❌ Error saving verification: {str(e)}", {}
283
 
284
+ def get_session_results(self) -> List[List[str]]:
285
  """
286
  Get all results from the current session.
287
 
 
296
  if not session:
297
  return []
298
 
299
+ # Gradio Dataframe renders most reliably with a 2D list (rows) when
300
+ # headers are provided. Returning dicts can show up as "[object Object]"
301
+ # in the browser.
302
+ results: List[List[str]] = []
303
  for record in session.verifications:
304
+ results.append([
305
+ record.original_message,
306
+ record.classifier_decision.upper(),
307
+ record.ground_truth_label.upper(),
308
+ "✓" if record.is_correct else "✗",
309
+ f"{record.classifier_confidence * 100:.1f}%",
310
+ ", ".join(record.classifier_indicators),
311
+ record.verifier_notes,
312
+ record.timestamp.strftime("%Y-%m-%d %H:%M:%S"),
313
+ ])
314
 
315
  return results
316
 
 
600
  # Export options
601
  gr.Markdown("## 💾 Export Options")
602
  with gr.Column():
603
+ # Hidden until there's at least one verified message
604
+ download_csv_btn = gr.DownloadButton("⬇️ Download CSV", variant="secondary", visible=False)
605
+ download_json_btn = gr.DownloadButton("⬇️ Download JSON", variant="secondary", visible=False)
606
+ download_xlsx_btn = gr.DownloadButton("⬇️ Download XLSX", variant="secondary", visible=False)
 
 
 
 
 
 
607
 
608
  # Complete session
609
  gr.Markdown("## 🏁 Session Control")
 
650
  gr.Row(visible=True), # manual_input_section
651
  gr.Row(visible=True), # results_history_section
652
  session_info, # session_info_display
653
+ gr.DownloadButton(visible=False), # download_csv_btn
654
+ gr.DownloadButton(visible=False), # download_json_btn
655
+ gr.DownloadButton(visible=False), # download_xlsx_btn
656
  message # status_message
657
  )
658
  else:
 
661
  gr.Row(visible=False), # manual_input_section
662
  gr.Row(visible=False), # results_history_section
663
  "Enter your name and click 'Start Session' to begin", # session_info_display
664
+ gr.DownloadButton(visible=False), # download_csv_btn
665
+ gr.DownloadButton(visible=False), # download_json_btn
666
+ gr.DownloadButton(visible=False), # download_xlsx_btn
667
  message # status_message
668
  )
669
 
 
710
  gr.Row(visible=False), # correction_section
711
  stats_text, # session_stats_display
712
  results, # results_display
713
+ gr.DownloadButton(visible=True), # download_csv_btn
714
+ gr.DownloadButton(visible=True), # download_json_btn
715
+ gr.DownloadButton(visible=True), # download_xlsx_btn
716
  message # status_message
717
  )
718
  else:
 
722
  gr.Row(visible=False), # correction_section
723
  gr.Markdown(value=""), # session_stats_display (no change)
724
  gr.Dataframe(value=[]), # results_display (no change)
725
+ gr.DownloadButton(), # download_csv_btn (no change)
726
+ gr.DownloadButton(), # download_json_btn (no change)
727
+ gr.DownloadButton(), # download_xlsx_btn (no change)
728
  message # status_message
729
  )
730
 
 
753
  "", # correction_notes (clear)
754
  stats_text, # session_stats_display
755
  results, # results_display
756
+ gr.DownloadButton(visible=True), # download_csv_btn
757
+ gr.DownloadButton(visible=True), # download_json_btn
758
+ gr.DownloadButton(visible=True), # download_xlsx_btn
759
  message # status_message
760
  )
761
  else:
 
766
  notes, # correction_notes (keep)
767
  gr.Markdown(value=""), # session_stats_display (no change)
768
  gr.Dataframe(value=[]), # results_display (no change)
769
+ gr.DownloadButton(), # download_csv_btn (no change)
770
+ gr.DownloadButton(), # download_json_btn (no change)
771
+ gr.DownloadButton(), # download_xlsx_btn (no change)
772
  message # status_message
773
  )
774
 
 
 
 
 
 
775
  def on_export_results_file(format_type):
776
  """Handle results export for DownloadButton (returns file path)."""
777
  success, message, file_path = controller.export_session_results(format_type)
 
822
  manual_input_section,
823
  results_history_section,
824
  session_info_display,
825
+ download_csv_btn,
826
+ download_json_btn,
827
+ download_xlsx_btn,
828
  status_message
829
  ]
830
  )
 
849
  correction_section,
850
  session_stats_display,
851
  results_display,
852
+ download_csv_btn,
853
+ download_json_btn,
854
+ download_xlsx_btn,
855
  status_message
856
  ]
857
  )
 
871
  correction_notes,
872
  session_stats_display,
873
  results_display,
874
+ download_csv_btn,
875
+ download_json_btn,
876
+ download_xlsx_btn,
877
  status_message
878
  ]
879
  )
880
 
 
 
 
 
 
881
  download_csv_btn.click(
882
  lambda: on_export_results_file("csv"),
883
  outputs=[download_csv_btn]
884
  )
885
 
 
 
 
 
 
886
  download_json_btn.click(
887
  lambda: on_export_results_file("json"),
888
  outputs=[download_json_btn]
889
  )
890
 
 
 
 
 
 
891
  download_xlsx_btn.click(
892
  lambda: on_export_results_file("xlsx"),
893
  outputs=[download_xlsx_btn]