Spaces:
Sleeping
Sleeping
Refactor export button implementation to use gr.DownloadButton and update click handlers for file downloads
Browse files
src/interface/file_upload_interface.py
CHANGED
|
@@ -779,9 +779,21 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 779 |
# Export options
|
| 780 |
gr.Markdown("### 💾 Export Results")
|
| 781 |
with gr.Column():
|
| 782 |
-
export_csv_btn =
|
| 783 |
-
|
| 784 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 785 |
|
| 786 |
# Status messages
|
| 787 |
status_message = gr.Markdown("", visible=True)
|
|
@@ -826,6 +838,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 826 |
"", # file_preview_display
|
| 827 |
None, # current_file_result_state
|
| 828 |
None, # current_session_state
|
|
|
|
|
|
|
|
|
|
| 829 |
"File cleared" # status_message
|
| 830 |
)
|
| 831 |
|
|
@@ -862,6 +877,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 862 |
confidence_text, # classifier_confidence_display
|
| 863 |
indicators_text, # classifier_indicators_display
|
| 864 |
progress_text, # batch_progress_display
|
|
|
|
|
|
|
|
|
|
| 865 |
message # status_message
|
| 866 |
)
|
| 867 |
else:
|
|
@@ -874,6 +892,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 874 |
"", # classifier_confidence_display
|
| 875 |
"", # classifier_indicators_display
|
| 876 |
"No messages to process", # batch_progress_display
|
|
|
|
|
|
|
|
|
|
| 877 |
"❌ No messages in file" # status_message
|
| 878 |
)
|
| 879 |
else:
|
|
@@ -886,6 +907,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 886 |
"", # classifier_confidence_display
|
| 887 |
"", # classifier_indicators_display
|
| 888 |
"", # batch_progress_display
|
|
|
|
|
|
|
|
|
|
| 889 |
message # status_message
|
| 890 |
)
|
| 891 |
|
|
@@ -922,6 +946,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 922 |
progress_text, # batch_progress_display
|
| 923 |
stats_text, # batch_stats_display
|
| 924 |
gr.Row(visible=False), # correction_section
|
|
|
|
|
|
|
|
|
|
| 925 |
message # status_message
|
| 926 |
)
|
| 927 |
else:
|
|
@@ -942,6 +969,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 942 |
"✅ Batch processing complete", # batch_progress_display
|
| 943 |
stats_text, # batch_stats_display
|
| 944 |
gr.Row(visible=False), # correction_section
|
|
|
|
|
|
|
|
|
|
| 945 |
message # status_message
|
| 946 |
)
|
| 947 |
else:
|
|
@@ -954,6 +984,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 954 |
gr.Markdown(value=""), # batch_progress_display (no change)
|
| 955 |
gr.Markdown(value=""), # batch_stats_display (no change)
|
| 956 |
gr.Row(visible=False), # correction_section
|
|
|
|
|
|
|
|
|
|
| 957 |
message # status_message
|
| 958 |
)
|
| 959 |
|
|
@@ -1000,6 +1033,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 1000 |
stats_text, # batch_stats_display
|
| 1001 |
gr.Row(visible=False), # correction_section
|
| 1002 |
"", # correction_notes (clear)
|
|
|
|
|
|
|
|
|
|
| 1003 |
message # status_message
|
| 1004 |
)
|
| 1005 |
else:
|
|
@@ -1021,6 +1057,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 1021 |
stats_text, # batch_stats_display
|
| 1022 |
gr.Row(visible=False), # correction_section
|
| 1023 |
"", # correction_notes (clear)
|
|
|
|
|
|
|
|
|
|
| 1024 |
message # status_message
|
| 1025 |
)
|
| 1026 |
else:
|
|
@@ -1034,13 +1073,18 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 1034 |
gr.Markdown(value=""), # batch_stats_display (no change)
|
| 1035 |
gr.Row(visible=True), # correction_section (keep visible)
|
| 1036 |
notes, # correction_notes (keep)
|
|
|
|
|
|
|
|
|
|
| 1037 |
message # status_message
|
| 1038 |
)
|
| 1039 |
|
| 1040 |
-
def
|
| 1041 |
-
"""Handle results export."""
|
| 1042 |
success, message, file_path = controller.export_batch_results(format_type)
|
| 1043 |
-
|
|
|
|
|
|
|
| 1044 |
|
| 1045 |
def on_download_csv_template():
|
| 1046 |
"""Handle CSV template download."""
|
|
@@ -1086,6 +1130,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 1086 |
file_preview_display,
|
| 1087 |
current_file_result_state,
|
| 1088 |
current_session_state,
|
|
|
|
|
|
|
|
|
|
| 1089 |
status_message
|
| 1090 |
]
|
| 1091 |
)
|
|
@@ -1102,6 +1149,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 1102 |
classifier_confidence_display,
|
| 1103 |
classifier_indicators_display,
|
| 1104 |
batch_progress_display,
|
|
|
|
|
|
|
|
|
|
| 1105 |
status_message
|
| 1106 |
]
|
| 1107 |
)
|
|
@@ -1117,6 +1167,9 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 1117 |
batch_progress_display,
|
| 1118 |
batch_stats_display,
|
| 1119 |
correction_section,
|
|
|
|
|
|
|
|
|
|
| 1120 |
status_message
|
| 1121 |
]
|
| 1122 |
)
|
|
@@ -1139,24 +1192,16 @@ def create_file_upload_interface() -> gr.Blocks:
|
|
| 1139 |
batch_stats_display,
|
| 1140 |
correction_section,
|
| 1141 |
correction_notes,
|
|
|
|
|
|
|
|
|
|
| 1142 |
status_message
|
| 1143 |
]
|
| 1144 |
)
|
| 1145 |
|
| 1146 |
-
export_csv_btn.click(
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
)
|
| 1150 |
-
|
| 1151 |
-
export_json_btn.click(
|
| 1152 |
-
lambda: on_export_results("json"),
|
| 1153 |
-
outputs=[status_message]
|
| 1154 |
-
)
|
| 1155 |
-
|
| 1156 |
-
export_xlsx_btn.click(
|
| 1157 |
-
lambda: on_export_results("xlsx"),
|
| 1158 |
-
outputs=[status_message]
|
| 1159 |
-
)
|
| 1160 |
|
| 1161 |
download_csv_template_btn.click(
|
| 1162 |
on_download_csv_template,
|
|
|
|
| 779 |
# Export options
|
| 780 |
gr.Markdown("### 💾 Export Results")
|
| 781 |
with gr.Column():
|
| 782 |
+
export_csv_btn = gr.DownloadButton(
|
| 783 |
+
label="Download CSV",
|
| 784 |
+
variant="secondary",
|
| 785 |
+
visible=False,
|
| 786 |
+
)
|
| 787 |
+
export_json_btn = gr.DownloadButton(
|
| 788 |
+
label="Download JSON",
|
| 789 |
+
variant="secondary",
|
| 790 |
+
visible=False,
|
| 791 |
+
)
|
| 792 |
+
export_xlsx_btn = gr.DownloadButton(
|
| 793 |
+
label="Download XLSX",
|
| 794 |
+
variant="secondary",
|
| 795 |
+
visible=False,
|
| 796 |
+
)
|
| 797 |
|
| 798 |
# Status messages
|
| 799 |
status_message = gr.Markdown("", visible=True)
|
|
|
|
| 838 |
"", # file_preview_display
|
| 839 |
None, # current_file_result_state
|
| 840 |
None, # current_session_state
|
| 841 |
+
gr.DownloadButton(visible=False), # export_csv_btn
|
| 842 |
+
gr.DownloadButton(visible=False), # export_json_btn
|
| 843 |
+
gr.DownloadButton(visible=False), # export_xlsx_btn
|
| 844 |
"File cleared" # status_message
|
| 845 |
)
|
| 846 |
|
|
|
|
| 877 |
confidence_text, # classifier_confidence_display
|
| 878 |
indicators_text, # classifier_indicators_display
|
| 879 |
progress_text, # batch_progress_display
|
| 880 |
+
gr.DownloadButton(visible=False), # export_csv_btn
|
| 881 |
+
gr.DownloadButton(visible=False), # export_json_btn
|
| 882 |
+
gr.DownloadButton(visible=False), # export_xlsx_btn
|
| 883 |
message # status_message
|
| 884 |
)
|
| 885 |
else:
|
|
|
|
| 892 |
"", # classifier_confidence_display
|
| 893 |
"", # classifier_indicators_display
|
| 894 |
"No messages to process", # batch_progress_display
|
| 895 |
+
gr.DownloadButton(visible=False), # export_csv_btn
|
| 896 |
+
gr.DownloadButton(visible=False), # export_json_btn
|
| 897 |
+
gr.DownloadButton(visible=False), # export_xlsx_btn
|
| 898 |
"❌ No messages in file" # status_message
|
| 899 |
)
|
| 900 |
else:
|
|
|
|
| 907 |
"", # classifier_confidence_display
|
| 908 |
"", # classifier_indicators_display
|
| 909 |
"", # batch_progress_display
|
| 910 |
+
gr.DownloadButton(visible=False), # export_csv_btn
|
| 911 |
+
gr.DownloadButton(visible=False), # export_json_btn
|
| 912 |
+
gr.DownloadButton(visible=False), # export_xlsx_btn
|
| 913 |
message # status_message
|
| 914 |
)
|
| 915 |
|
|
|
|
| 946 |
progress_text, # batch_progress_display
|
| 947 |
stats_text, # batch_stats_display
|
| 948 |
gr.Row(visible=False), # correction_section
|
| 949 |
+
gr.DownloadButton(visible=True), # export_csv_btn
|
| 950 |
+
gr.DownloadButton(visible=True), # export_json_btn
|
| 951 |
+
gr.DownloadButton(visible=True), # export_xlsx_btn
|
| 952 |
message # status_message
|
| 953 |
)
|
| 954 |
else:
|
|
|
|
| 969 |
"✅ Batch processing complete", # batch_progress_display
|
| 970 |
stats_text, # batch_stats_display
|
| 971 |
gr.Row(visible=False), # correction_section
|
| 972 |
+
gr.DownloadButton(visible=True), # export_csv_btn
|
| 973 |
+
gr.DownloadButton(visible=True), # export_json_btn
|
| 974 |
+
gr.DownloadButton(visible=True), # export_xlsx_btn
|
| 975 |
message # status_message
|
| 976 |
)
|
| 977 |
else:
|
|
|
|
| 984 |
gr.Markdown(value=""), # batch_progress_display (no change)
|
| 985 |
gr.Markdown(value=""), # batch_stats_display (no change)
|
| 986 |
gr.Row(visible=False), # correction_section
|
| 987 |
+
gr.DownloadButton(visible=False), # export_csv_btn
|
| 988 |
+
gr.DownloadButton(visible=False), # export_json_btn
|
| 989 |
+
gr.DownloadButton(visible=False), # export_xlsx_btn
|
| 990 |
message # status_message
|
| 991 |
)
|
| 992 |
|
|
|
|
| 1033 |
stats_text, # batch_stats_display
|
| 1034 |
gr.Row(visible=False), # correction_section
|
| 1035 |
"", # correction_notes (clear)
|
| 1036 |
+
gr.DownloadButton(visible=True), # export_csv_btn
|
| 1037 |
+
gr.DownloadButton(visible=True), # export_json_btn
|
| 1038 |
+
gr.DownloadButton(visible=True), # export_xlsx_btn
|
| 1039 |
message # status_message
|
| 1040 |
)
|
| 1041 |
else:
|
|
|
|
| 1057 |
stats_text, # batch_stats_display
|
| 1058 |
gr.Row(visible=False), # correction_section
|
| 1059 |
"", # correction_notes (clear)
|
| 1060 |
+
gr.DownloadButton(visible=True), # export_csv_btn
|
| 1061 |
+
gr.DownloadButton(visible=True), # export_json_btn
|
| 1062 |
+
gr.DownloadButton(visible=True), # export_xlsx_btn
|
| 1063 |
message # status_message
|
| 1064 |
)
|
| 1065 |
else:
|
|
|
|
| 1073 |
gr.Markdown(value=""), # batch_stats_display (no change)
|
| 1074 |
gr.Row(visible=True), # correction_section (keep visible)
|
| 1075 |
notes, # correction_notes (keep)
|
| 1076 |
+
gr.DownloadButton(visible=False), # export_csv_btn
|
| 1077 |
+
gr.DownloadButton(visible=False), # export_json_btn
|
| 1078 |
+
gr.DownloadButton(visible=False), # export_xlsx_btn
|
| 1079 |
message # status_message
|
| 1080 |
)
|
| 1081 |
|
| 1082 |
+
def on_export_results_file(format_type):
|
| 1083 |
+
"""Handle results export and return the generated file for download."""
|
| 1084 |
success, message, file_path = controller.export_batch_results(format_type)
|
| 1085 |
+
if success and file_path:
|
| 1086 |
+
return file_path
|
| 1087 |
+
return None
|
| 1088 |
|
| 1089 |
def on_download_csv_template():
|
| 1090 |
"""Handle CSV template download."""
|
|
|
|
| 1130 |
file_preview_display,
|
| 1131 |
current_file_result_state,
|
| 1132 |
current_session_state,
|
| 1133 |
+
export_csv_btn,
|
| 1134 |
+
export_json_btn,
|
| 1135 |
+
export_xlsx_btn,
|
| 1136 |
status_message
|
| 1137 |
]
|
| 1138 |
)
|
|
|
|
| 1149 |
classifier_confidence_display,
|
| 1150 |
classifier_indicators_display,
|
| 1151 |
batch_progress_display,
|
| 1152 |
+
export_csv_btn,
|
| 1153 |
+
export_json_btn,
|
| 1154 |
+
export_xlsx_btn,
|
| 1155 |
status_message
|
| 1156 |
]
|
| 1157 |
)
|
|
|
|
| 1167 |
batch_progress_display,
|
| 1168 |
batch_stats_display,
|
| 1169 |
correction_section,
|
| 1170 |
+
export_csv_btn,
|
| 1171 |
+
export_json_btn,
|
| 1172 |
+
export_xlsx_btn,
|
| 1173 |
status_message
|
| 1174 |
]
|
| 1175 |
)
|
|
|
|
| 1192 |
batch_stats_display,
|
| 1193 |
correction_section,
|
| 1194 |
correction_notes,
|
| 1195 |
+
export_csv_btn,
|
| 1196 |
+
export_json_btn,
|
| 1197 |
+
export_xlsx_btn,
|
| 1198 |
status_message
|
| 1199 |
]
|
| 1200 |
)
|
| 1201 |
|
| 1202 |
+
export_csv_btn.click(lambda: on_export_results_file("csv"), outputs=[export_csv_btn])
|
| 1203 |
+
export_json_btn.click(lambda: on_export_results_file("json"), outputs=[export_json_btn])
|
| 1204 |
+
export_xlsx_btn.click(lambda: on_export_results_file("xlsx"), outputs=[export_xlsx_btn])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1205 |
|
| 1206 |
download_csv_template_btn.click(
|
| 1207 |
on_download_csv_template,
|