Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,15 +33,6 @@ torch_device = device
|
|
33 |
torch_dtype = torch.float16
|
34 |
|
35 |
|
36 |
-
# add file save and download and clear:
|
37 |
-
# Function to create a zip file from a list of files
|
38 |
-
def create_zip(files):
|
39 |
-
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
40 |
-
zip_filename = f"images_{timestamp}.zip"
|
41 |
-
with zipfile.ZipFile(zip_filename, 'w') as zipf:
|
42 |
-
for file in files:
|
43 |
-
zipf.write(file, os.path.basename(file))
|
44 |
-
return zip_filename
|
45 |
|
46 |
# Function to encode a file to base64
|
47 |
def encode_file_to_base64(file_path):
|
@@ -83,6 +74,17 @@ def clear_all_images():
|
|
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:
|
@@ -90,6 +92,8 @@ def save_all_images(images):
|
|
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
|
|
|
33 |
torch_dtype = torch.float16
|
34 |
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Function to encode a file to base64
|
38 |
def encode_file_to_base64(file_path):
|
|
|
74 |
for file in img_files:
|
75 |
os.remove(file)
|
76 |
|
77 |
+
|
78 |
+
# add file save and download and clear:
|
79 |
+
# Function to create a zip file from a list of files
|
80 |
+
def create_zip(files):
|
81 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
|
82 |
+
zip_filename = f"images_{timestamp}.zip"
|
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
|
89 |
def save_all_images(images):
|
90 |
if len(images) == 0:
|
|
|
92 |
zip_filename = create_zip(images) # Create a zip file from the list of image files
|
93 |
zip_base64 = encode_file_to_base64(zip_filename) # Encode the zip file to base64
|
94 |
download_link = f'<a href="data:application/zip;base64,{zip_base64}" download="{zip_filename}">Download All</a>'
|
95 |
+
gr.HTML(download_link)
|
96 |
+
print(download_link)
|
97 |
return zip_filename, download_link
|
98 |
|
99 |
# Function to handle "Save All" button click
|