biosn2 commited on
Commit
adcf14e
·
verified ·
1 Parent(s): 653367c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -408,19 +408,27 @@ def zip_outputs_folder():
408
  outputs_dir = "Outputs"
409
  zip_path = os.path.join("tmp", "outputs.zip")
410
  os.makedirs("tmp", exist_ok=True)
411
-
412
- if os.path.exists(outputs_dir) and os.path.isdir(outputs_dir):
413
- with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
414
- for root, _, files in os.walk(outputs_dir):
415
- for file in files:
416
- file_path = os.path.join(root, file)
417
- arcname = os.path.relpath(file_path, outputs_dir)
418
- zipf.write(file_path, os.path.join("Outputs", arcname))
419
- return zip_path, "Outputs folder successfully zipped as outputs.zip"
420
- else:
421
- return None, "Outputs folder does not exist or is empty"
 
 
 
 
 
 
 
 
422
  except Exception as e:
423
- return None, f"Failed to zip Outputs folder: {str(e)}"
424
 
425
  def compress_wav_to_mp3():
426
  """Convert .wav files in Outputs folder and subfolders to 80kbps .mp3 files, replacing the originals"""
@@ -793,11 +801,6 @@ def main():
793
  outputs=[zip_status]
794
  )
795
 
796
- demo.load(
797
- fn=get_download_zip_state,
798
- inputs=[],
799
- outputs=[download_zip_button, zip_status]
800
- )
801
 
802
  seed_id_input.change(
803
  fn=get_pt_file_for_download,
 
408
  outputs_dir = "Outputs"
409
  zip_path = os.path.join("tmp", "outputs.zip")
410
  os.makedirs("tmp", exist_ok=True)
411
+
412
+ if not os.path.exists(outputs_dir) or not os.path.isdir(outputs_dir):
413
+ return "Outputs folder does not exist or is empty", gr.DownloadButton(visible=False)
414
+
415
+ with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
416
+ for root, _, files in os.walk(outputs_dir):
417
+ for file in files:
418
+ file_path = os.path.join(root, file)
419
+ arcname = os.path.relpath(file_path, outputs_dir)
420
+ zipf.write(file_path, os.path.join("Outputs", arcname))
421
+
422
+ return (
423
+ "outputs.zip created successfully",
424
+ gr.DownloadButton(
425
+ value=zip_path,
426
+ label="Download Outputs.zip",
427
+ visible=True
428
+ )
429
+ )
430
  except Exception as e:
431
+ return f"Zip failed: {str(e)}", gr.DownloadButton(visible=False)
432
 
433
  def compress_wav_to_mp3():
434
  """Convert .wav files in Outputs folder and subfolders to 80kbps .mp3 files, replacing the originals"""
 
801
  outputs=[zip_status]
802
  )
803
 
 
 
 
 
 
804
 
805
  seed_id_input.change(
806
  fn=get_pt_file_for_download,