KajetanNiewczas commited on
Commit ·
03080db
1
Parent(s): 894ddd1
Multiple downloadable files
Browse files
src/interface/gradio_interface.py
CHANGED
|
@@ -419,8 +419,13 @@ with gr.Blocks(theme=theme, js=JS_FUNC) as demo:
|
|
| 419 |
label="Download Presentation",
|
| 420 |
interactive=False,
|
| 421 |
elem_id="download-box",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
)
|
| 423 |
-
pdf_output_viewer = PDF(label="Presentation Preview", elem_id="preview-box", visible=False)
|
| 424 |
browser_alert_box = gr.HTML(
|
| 425 |
"""
|
| 426 |
<div style="
|
|
@@ -525,12 +530,17 @@ with gr.Blocks(theme=theme, js=JS_FUNC) as demo:
|
|
| 525 |
config_state,
|
| 526 |
session_id_state,
|
| 527 |
],
|
| 528 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 529 |
)
|
| 530 |
|
| 531 |
compilation_status.change(
|
| 532 |
fn=download_files,
|
| 533 |
inputs=[
|
|
|
|
| 534 |
presentation_folder_state,
|
| 535 |
session_id_state,
|
| 536 |
],
|
|
|
|
| 419 |
label="Download Presentation",
|
| 420 |
interactive=False,
|
| 421 |
elem_id="download-box",
|
| 422 |
+
file_count="multiple",
|
| 423 |
+
)
|
| 424 |
+
pdf_output_viewer = PDF(
|
| 425 |
+
label="Presentation Preview",
|
| 426 |
+
elem_id="preview-box",
|
| 427 |
+
visible=False,
|
| 428 |
)
|
|
|
|
| 429 |
browser_alert_box = gr.HTML(
|
| 430 |
"""
|
| 431 |
<div style="
|
|
|
|
| 530 |
config_state,
|
| 531 |
session_id_state,
|
| 532 |
],
|
| 533 |
+
outputs=[
|
| 534 |
+
compilation_status,
|
| 535 |
+
trace_id_state,
|
| 536 |
+
presentation_folder_state
|
| 537 |
+
],
|
| 538 |
)
|
| 539 |
|
| 540 |
compilation_status.change(
|
| 541 |
fn=download_files,
|
| 542 |
inputs=[
|
| 543 |
+
compilation_status,
|
| 544 |
presentation_folder_state,
|
| 545 |
session_id_state,
|
| 546 |
],
|
src/interface/manage_files.py
CHANGED
|
@@ -72,14 +72,31 @@ def upload_files(files: list, session_id: str) -> tuple[str, list[str]]:
|
|
| 72 |
return "\n".join(messages), saved_paths
|
| 73 |
|
| 74 |
|
| 75 |
-
def download_files(folder_path, session_id) -> str:
|
| 76 |
"""Prepare downloadable zip archive from the specified folder path."""
|
| 77 |
|
| 78 |
if not folder_path:
|
| 79 |
return None
|
| 80 |
|
| 81 |
folder = Path(folder_path)
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
| 85 |
# Add gfx folder
|
|
@@ -97,7 +114,9 @@ def download_files(folder_path, session_id) -> str:
|
|
| 97 |
zipf.write(file_path, arcname=arcname)
|
| 98 |
LOGGER.info("📦 Created zip archive at %s", zip_path)
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
|
| 102 |
|
| 103 |
def delete_files(session_id: str) -> None:
|
|
|
|
| 72 |
return "\n".join(messages), saved_paths
|
| 73 |
|
| 74 |
|
| 75 |
+
def download_files(compilation_status, folder_path, session_id) -> str:
|
| 76 |
"""Prepare downloadable zip archive from the specified folder path."""
|
| 77 |
|
| 78 |
if not folder_path:
|
| 79 |
return None
|
| 80 |
|
| 81 |
folder = Path(folder_path)
|
| 82 |
+
base_dir = Path.cwd() / "tmp" / session_id
|
| 83 |
+
|
| 84 |
+
all_zips = [base_dir / "presentation.zip"]
|
| 85 |
+
all_zips += sorted(base_dir.glob("presentation_*.zip"))
|
| 86 |
+
all_zips = [str(p) for p in all_zips if p.exists() and p.is_file()]
|
| 87 |
+
if compilation_status == "":
|
| 88 |
+
return all_zips
|
| 89 |
+
|
| 90 |
+
if all_zips:
|
| 91 |
+
last_file = Path(all_zips[-1]).name
|
| 92 |
+
match = re.match(r"presentation_(\d+)\.zip", last_file)
|
| 93 |
+
if match:
|
| 94 |
+
next_num = int(match.group(1)) + 1
|
| 95 |
+
else:
|
| 96 |
+
next_num = 2
|
| 97 |
+
zip_path = base_dir / f"presentation_{next_num}.zip"
|
| 98 |
+
else:
|
| 99 |
+
zip_path = base_dir / "presentation.zip"
|
| 100 |
|
| 101 |
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
| 102 |
# Add gfx folder
|
|
|
|
| 114 |
zipf.write(file_path, arcname=arcname)
|
| 115 |
LOGGER.info("📦 Created zip archive at %s", zip_path)
|
| 116 |
|
| 117 |
+
all_zips.append(str(zip_path))
|
| 118 |
+
|
| 119 |
+
return all_zips
|
| 120 |
|
| 121 |
|
| 122 |
def delete_files(session_id: str) -> None:
|