Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -49,16 +49,6 @@ def encode_file_to_base64(file_path):
|
|
49 |
encoded = base64.b64encode(file.read()).decode()
|
50 |
return encoded
|
51 |
|
52 |
-
# Function to save all images as a zip file and provide a base64 download link
|
53 |
-
def save_all_images(images):
|
54 |
-
if len(images) == 0:
|
55 |
-
return None, None
|
56 |
-
|
57 |
-
zip_filename = create_zip(images) # Create a zip file from the list of image files
|
58 |
-
zip_base64 = encode_file_to_base64(zip_filename) # Encode the zip file to base64
|
59 |
-
download_link = f'<a href="data:application/zip;base64,{zip_base64}" download="{zip_filename}">Download All</a>'
|
60 |
-
|
61 |
-
return zip_filename, download_link
|
62 |
|
63 |
|
64 |
def create_zip_of_files(files):
|
@@ -93,18 +83,24 @@ def clear_all_images():
|
|
93 |
for file in img_files:
|
94 |
os.remove(file)
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
# Function to handle "Save All" button click
|
97 |
def save_all_button_click():
|
98 |
images = [file for file in os.listdir() if file.lower().endswith((".png", ".jpg", ".jpeg"))]
|
99 |
-
zip_filename, download_link = save_all_images(images)
|
100 |
-
|
|
|
101 |
if download_link:
|
102 |
gr.HTML(download_link)
|
103 |
|
104 |
-
zip_file = create_zip_of_files(all_files)
|
105 |
-
gr.HTML(get_zip_download_link(zip_file))
|
106 |
-
|
107 |
-
|
108 |
|
109 |
# Function to handle "Clear All" button click
|
110 |
def clear_all_button_click():
|
|
|
49 |
encoded = base64.b64encode(file.read()).decode()
|
50 |
return encoded
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
|
54 |
def create_zip_of_files(files):
|
|
|
83 |
for file in img_files:
|
84 |
os.remove(file)
|
85 |
|
86 |
+
# Function to save all images as a zip file and provide a base64 download link
|
87 |
+
def save_all_images(images):
|
88 |
+
if len(images) == 0:
|
89 |
+
return None, None
|
90 |
+
zip_filename = create_zip(images) # Create a zip file from the list of image files
|
91 |
+
zip_base64 = encode_file_to_base64(zip_filename) # Encode the zip file to base64
|
92 |
+
download_link = f'<a href="data:application/zip;base64,{zip_base64}" download="{zip_filename}">Download All</a>'
|
93 |
+
return zip_filename, download_link
|
94 |
+
|
95 |
# Function to handle "Save All" button click
|
96 |
def save_all_button_click():
|
97 |
images = [file for file in os.listdir() if file.lower().endswith((".png", ".jpg", ".jpeg"))]
|
98 |
+
zip_filename, download_link = save_all_images(images)
|
99 |
+
if zip_filename:
|
100 |
+
gr.HTML(zip_filename)
|
101 |
if download_link:
|
102 |
gr.HTML(download_link)
|
103 |
|
|
|
|
|
|
|
|
|
104 |
|
105 |
# Function to handle "Clear All" button click
|
106 |
def clear_all_button_click():
|