TzuShianYang commited on
Commit
3bf8c66
·
1 Parent(s): 335b410

Update zip name with datetime

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import zipfile
3
  import os
 
4
 
5
 
6
  def add_image(camera, gallery):
@@ -13,12 +14,11 @@ def add_image(camera, gallery):
13
 
14
 
15
  def zip_gallery(gallery):
 
16
  count = 0
17
  if not gallery:
18
  return gr.DownloadButton("Download", visible=False)
19
- if os.path.isfile("image_data.zip"):
20
- os.remove("image_data.zip")
21
- zf = zipfile.ZipFile("image_data.zip", mode="w")
22
  try:
23
  for path, _ in gallery:
24
  zf.write(path, f'image_{count}.png',
@@ -29,7 +29,7 @@ def zip_gallery(gallery):
29
  finally:
30
  zf.close()
31
 
32
- return gr.DownloadButton("Download", value="image_data.zip", visible=True)
33
 
34
 
35
  with gr.Blocks(fill_height=True) as demo:
 
1
  import gradio as gr
2
  import zipfile
3
  import os
4
+ import datetime
5
 
6
 
7
  def add_image(camera, gallery):
 
14
 
15
 
16
  def zip_gallery(gallery):
17
+ new_zip_name = f'{datetime.today()}.zip'
18
  count = 0
19
  if not gallery:
20
  return gr.DownloadButton("Download", visible=False)
21
+ zf = zipfile.ZipFile(new_zip_name, mode="w")
 
 
22
  try:
23
  for path, _ in gallery:
24
  zf.write(path, f'image_{count}.png',
 
29
  finally:
30
  zf.close()
31
 
32
+ return gr.DownloadButton("Download", value=new_zip_name, visible=True)
33
 
34
 
35
  with gr.Blocks(fill_height=True) as demo: