Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -139,6 +139,7 @@ with gr.Blocks() as demo:
|
|
| 139 |
output_files = gr.Files(label="分割后的文件")
|
| 140 |
with gr.Row():
|
| 141 |
submit_btn = gr.Button("开始分割")
|
|
|
|
| 142 |
|
| 143 |
# 动态显示/隐藏输入框
|
| 144 |
def toggle_inputs(mode):
|
|
@@ -147,6 +148,24 @@ with gr.Blocks() as demo:
|
|
| 147 |
else:
|
| 148 |
return gr.Textbox(visible=False), gr.Number(visible=True)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
mode.change(toggle_inputs, inputs=mode, outputs=[split_pages, max_size_mb])
|
| 151 |
|
| 152 |
# 绑定处理函数
|
|
@@ -155,7 +174,15 @@ with gr.Blocks() as demo:
|
|
| 155 |
inputs=[input_pdf, mode, split_pages, max_size_mb],
|
| 156 |
outputs=output_files
|
| 157 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
theme=gr.themes.Soft()
|
| 159 |
|
| 160 |
# 启动应用
|
| 161 |
-
demo.launch()
|
|
|
|
| 139 |
output_files = gr.Files(label="分割后的文件")
|
| 140 |
with gr.Row():
|
| 141 |
submit_btn = gr.Button("开始分割")
|
| 142 |
+
download_all_btn = gr.Button("批量下载")
|
| 143 |
|
| 144 |
# 动态显示/隐藏输入框
|
| 145 |
def toggle_inputs(mode):
|
|
|
|
| 148 |
else:
|
| 149 |
return gr.Textbox(visible=False), gr.Number(visible=True)
|
| 150 |
|
| 151 |
+
# 批量下载功能
|
| 152 |
+
def download_all_files(file_list):
|
| 153 |
+
if not file_list:
|
| 154 |
+
return None
|
| 155 |
+
# 创建一个临时zip文件
|
| 156 |
+
import tempfile
|
| 157 |
+
import zipfile
|
| 158 |
+
import shutil
|
| 159 |
+
|
| 160 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.zip') as temp_zip:
|
| 161 |
+
with zipfile.ZipFile(temp_zip.name, 'w') as zf:
|
| 162 |
+
for file_path in file_list:
|
| 163 |
+
# 获取文件名
|
| 164 |
+
file_name = os.path.basename(file_path)
|
| 165 |
+
# 将文件添加到zip中
|
| 166 |
+
zf.write(file_path, file_name)
|
| 167 |
+
return temp_zip.name
|
| 168 |
+
|
| 169 |
mode.change(toggle_inputs, inputs=mode, outputs=[split_pages, max_size_mb])
|
| 170 |
|
| 171 |
# 绑定处理函数
|
|
|
|
| 174 |
inputs=[input_pdf, mode, split_pages, max_size_mb],
|
| 175 |
outputs=output_files
|
| 176 |
)
|
| 177 |
+
|
| 178 |
+
# 绑定批量下载函数
|
| 179 |
+
download_all_btn.click(
|
| 180 |
+
download_all_files,
|
| 181 |
+
inputs=[output_files],
|
| 182 |
+
outputs=gr.File(label="下载所有文件")
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
theme=gr.themes.Soft()
|
| 186 |
|
| 187 |
# 启动应用
|
| 188 |
+
demo.launch()
|