Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,38 +80,29 @@ def create_zip(files):
|
|
| 80 |
zipf.write(file, os.path.basename(file))
|
| 81 |
print('added:' + file)
|
| 82 |
return zip_filename
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
# Function to save all images as a zip file and provide a base64 download link
|
| 85 |
def save_all_images(images):
|
| 86 |
if len(images) == 0:
|
| 87 |
return None, None
|
| 88 |
-
zip_filename =
|
| 89 |
-
print(
|
| 90 |
-
|
| 91 |
-
gr.Button(link="/file=" + zip_filename)
|
| 92 |
-
|
| 93 |
-
# remove?
|
| 94 |
-
zip_base64 = encode_file_to_base64(zip_filename) # Encode the zip file to base64
|
| 95 |
-
download_link = f'<a href="data:application/zip;base64,{zip_base64}" download="{zip_filename}">Download All</a>'
|
| 96 |
-
gr.HTML(download_link)
|
| 97 |
-
|
| 98 |
-
# redirect_button = gr.Button("Clear", variant='secondary')
|
| 99 |
-
# redirect_button.click(None, None,None, _js="window.location.assign('https://google.com');")
|
| 100 |
-
|
| 101 |
return zip_filename, download_link
|
| 102 |
|
| 103 |
-
# Function to handle "Save All" button click
|
| 104 |
def save_all_button_click():
|
| 105 |
images = [file for file in os.listdir() if file.lower().endswith((".png", ".jpg", ".jpeg"))]
|
| 106 |
-
zip_filename, download_link = save_all_images(images)
|
| 107 |
-
if zip_filename:
|
| 108 |
-
print(zip_filename)
|
| 109 |
-
gr.Button(link=zip_filename)
|
| 110 |
-
gr.File(value=zip_filename)
|
| 111 |
if download_link:
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
gr.Button(link=download_link)
|
| 115 |
|
| 116 |
# Function to handle "Clear All" button click
|
| 117 |
def clear_all_button_click():
|
|
|
|
| 80 |
zipf.write(file, os.path.basename(file))
|
| 81 |
print('added:' + file)
|
| 82 |
return zip_filename
|
| 83 |
+
|
| 84 |
+
def get_zip_download_link(zip_file):
|
| 85 |
+
"""
|
| 86 |
+
Generate a link to download the zip file.
|
| 87 |
+
"""
|
| 88 |
+
zip_base64 = encode_file_to_base64(zip_file) # Encode the zip file to base64
|
| 89 |
+
href = f'<a href="data:application/zip;base64,{zip_base64}" download="{zip_file}">Download All</a>'
|
| 90 |
+
return href
|
| 91 |
|
|
|
|
| 92 |
def save_all_images(images):
|
| 93 |
if len(images) == 0:
|
| 94 |
return None, None
|
| 95 |
+
zip_filename = create_zip_of_files(images) # Create a zip file from the list of image files
|
| 96 |
+
print(f"Zip file created: {zip_filename}")
|
| 97 |
+
download_link = get_zip_download_link(zip_filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
return zip_filename, download_link
|
| 99 |
|
|
|
|
| 100 |
def save_all_button_click():
|
| 101 |
images = [file for file in os.listdir() if file.lower().endswith((".png", ".jpg", ".jpeg"))]
|
| 102 |
+
zip_filename, download_link = save_all_images(images)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
if download_link:
|
| 104 |
+
gr.HTML(download_link).update()
|
| 105 |
+
|
|
|
|
| 106 |
|
| 107 |
# Function to handle "Clear All" button click
|
| 108 |
def clear_all_button_click():
|