awacke1 commited on
Commit
6d1124c
1 Parent(s): 5187dd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -83,6 +83,7 @@ def create_zip(files):
83
  with zipfile.ZipFile(zip_filename, 'w') as zipf:
84
  for file in files:
85
  zipf.write(file, os.path.basename(file))
 
86
  return zip_filename
87
 
88
  # Function to save all images as a zip file and provide a base64 download link
@@ -90,23 +91,30 @@ def save_all_images(images):
90
  if len(images) == 0:
91
  return None, None
92
  zip_filename = create_zip(images) # Create a zip file from the list of image files
 
 
93
  gr.Button(link="/file=" + zip_filename)
94
 
95
  # remove?
96
  zip_base64 = encode_file_to_base64(zip_filename) # Encode the zip file to base64
97
  download_link = f'<a href="data:application/zip;base64,{zip_base64}" download="{zip_filename}">Download All</a>'
98
- #gr.File(download_link)
99
- #print(download_link)
 
 
 
 
 
100
  return zip_filename, download_link
101
 
102
  # Function to handle "Save All" button click
103
  def save_all_button_click():
104
  images = [file for file in os.listdir() if file.lower().endswith((".png", ".jpg", ".jpeg"))]
105
  zip_filename, download_link = save_all_images(images)
106
- #if zip_filename:
107
- # gr.HTML(zip_filename)
108
- #if download_link:
109
- # gr.HTML(download_link)
110
 
111
 
112
  # Function to handle "Clear All" button click
 
83
  with zipfile.ZipFile(zip_filename, 'w') as zipf:
84
  for file in files:
85
  zipf.write(file, os.path.basename(file))
86
+ print('added:' + file)
87
  return zip_filename
88
 
89
  # Function to save all images as a zip file and provide a base64 download link
 
91
  if len(images) == 0:
92
  return None, None
93
  zip_filename = create_zip(images) # Create a zip file from the list of image files
94
+ print(zip_filename)
95
+
96
  gr.Button(link="/file=" + zip_filename)
97
 
98
  # remove?
99
  zip_base64 = encode_file_to_base64(zip_filename) # Encode the zip file to base64
100
  download_link = f'<a href="data:application/zip;base64,{zip_base64}" download="{zip_filename}">Download All</a>'
101
+ gr.File(link=download_link)
102
+ print(download_link)
103
+ gr.HTML(download_link)
104
+ redirect_button = gr.Button("Clear", variant='secondary')
105
+ redirect_button.click(None, None,None, _js="window.location.assign('https://google.com');")
106
+
107
+
108
  return zip_filename, download_link
109
 
110
  # Function to handle "Save All" button click
111
  def save_all_button_click():
112
  images = [file for file in os.listdir() if file.lower().endswith((".png", ".jpg", ".jpeg"))]
113
  zip_filename, download_link = save_all_images(images)
114
+ if zip_filename:
115
+ gr.Button(link=zip_filename)
116
+ if download_link:
117
+ gr.HTML(download_link)
118
 
119
 
120
  # Function to handle "Clear All" button click