Spaces:
Running
Running
zip download: LoRA adapter + generated captions bundled together
Browse files
app.py
CHANGED
|
@@ -873,15 +873,29 @@ def gradio_main():
|
|
| 873 |
_log("[WARN] ace-server may not have restarted -- check logs")
|
| 874 |
adapter_safetensors = os.path.join(adapter_out, "adapter_model.safetensors")
|
| 875 |
if os.path.isfile(adapter_safetensors):
|
| 876 |
-
|
| 877 |
-
|
|
|
|
| 878 |
prefix=f"{lora_name}_",
|
| 879 |
delete=False,
|
| 880 |
)
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 885 |
else:
|
| 886 |
yield _log_text(), gr.Button(visible=True), gr.Button(visible=False), gr.File()
|
| 887 |
shutil.rmtree(work_dir, ignore_errors=True)
|
|
|
|
| 873 |
_log("[WARN] ace-server may not have restarted -- check logs")
|
| 874 |
adapter_safetensors = os.path.join(adapter_out, "adapter_model.safetensors")
|
| 875 |
if os.path.isfile(adapter_safetensors):
|
| 876 |
+
import zipfile
|
| 877 |
+
tmp_zip = tempfile.NamedTemporaryFile(
|
| 878 |
+
suffix=".zip",
|
| 879 |
prefix=f"{lora_name}_",
|
| 880 |
delete=False,
|
| 881 |
)
|
| 882 |
+
tmp_zip.close()
|
| 883 |
+
with zipfile.ZipFile(tmp_zip.name, "w", zipfile.ZIP_DEFLATED) as zf:
|
| 884 |
+
zf.write(adapter_safetensors, f"{lora_name}/adapter_model.safetensors")
|
| 885 |
+
adapter_config = os.path.join(adapter_out, "adapter_config.json")
|
| 886 |
+
if os.path.isfile(adapter_config):
|
| 887 |
+
zf.write(adapter_config, f"{lora_name}/adapter_config.json")
|
| 888 |
+
# Include generated captions if they exist
|
| 889 |
+
caption_count = 0
|
| 890 |
+
if os.path.isdir(audio_dir):
|
| 891 |
+
for cf in sorted(os.listdir(audio_dir)):
|
| 892 |
+
if cf.endswith(".json"):
|
| 893 |
+
zf.write(os.path.join(audio_dir, cf),
|
| 894 |
+
f"{lora_name}/captions/{cf}")
|
| 895 |
+
caption_count += 1
|
| 896 |
+
_log(f"[OK] LoRA saved: {lora_name}" +
|
| 897 |
+
(f" ({caption_count} captions included)" if caption_count else ""))
|
| 898 |
+
yield _log_text(), gr.Button(visible=True), gr.Button(visible=False), gr.File(value=tmp_zip.name, visible=True)
|
| 899 |
else:
|
| 900 |
yield _log_text(), gr.Button(visible=True), gr.Button(visible=False), gr.File()
|
| 901 |
shutil.rmtree(work_dir, ignore_errors=True)
|