Spaces:
Paused
Paused
Update backup.app.py
Browse files- backup.app.py +12 -15
backup.app.py
CHANGED
|
@@ -32,16 +32,12 @@ device = torch.device(
|
|
| 32 |
torch_device = device
|
| 33 |
torch_dtype = torch.float16
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
# Function to encode a file to base64
|
| 38 |
def encode_file_to_base64(file_path):
|
| 39 |
with open(file_path, "rb") as file:
|
| 40 |
encoded = base64.b64encode(file.read()).decode()
|
| 41 |
return encoded
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
def create_zip_of_files(files):
|
| 46 |
"""
|
| 47 |
Create a zip file from a list of files.
|
|
@@ -63,8 +59,6 @@ def get_zip_download_link(zip_file):
|
|
| 63 |
href = f'<a href="data:application/zip;base64,{b64}" download="{zip_file}">Download All</a>'
|
| 64 |
return href
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
# Function to clear all image files
|
| 69 |
def clear_all_images():
|
| 70 |
base_dir = os.getcwd() # Get the current base directory
|
|
@@ -74,8 +68,7 @@ def clear_all_images():
|
|
| 74 |
for file in img_files:
|
| 75 |
os.remove(file)
|
| 76 |
print('removed:' + file)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
# add file save and download and clear:
|
| 80 |
# Function to create a zip file from a list of files
|
| 81 |
def create_zip(files):
|
|
@@ -95,12 +88,13 @@ def save_all_images(images):
|
|
| 95 |
zip_filename = create_zip(images) # Create a zip file from the list of image files
|
| 96 |
print(' Zip file created:' + zip_filename)
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
# remove?
|
| 101 |
zip_base64 = encode_file_to_base64(zip_filename) # Encode the zip file to base64
|
| 102 |
download_link = f'<a href="data:application/zip;base64,{zip_base64}" download="{zip_filename}">Download All</a>'
|
| 103 |
-
|
|
|
|
| 104 |
# redirect_button = gr.Button("Clear", variant='secondary')
|
| 105 |
# redirect_button.click(None, None,None, _js="window.location.assign('https://google.com');")
|
| 106 |
|
|
@@ -113,10 +107,10 @@ def save_all_button_click():
|
|
| 113 |
if zip_filename:
|
| 114 |
print(zip_filename)
|
| 115 |
gr.Button(link=zip_filename)
|
| 116 |
-
|
| 117 |
if download_link:
|
| 118 |
print(download_link)
|
| 119 |
-
|
| 120 |
gr.Button(link=download_link)
|
| 121 |
|
| 122 |
# Function to handle "Clear All" button click
|
|
@@ -309,9 +303,12 @@ with gr.Blocks(css=css) as demo:
|
|
| 309 |
|
| 310 |
# Attach click event handlers to the buttons
|
| 311 |
save_all_button.click(save_all_button_click)
|
| 312 |
-
clear_all_button.click(clear_all_button_click)
|
| 313 |
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
demo.queue()
|
| 317 |
-
demo.launch()
|
|
|
|
| 32 |
torch_device = device
|
| 33 |
torch_dtype = torch.float16
|
| 34 |
|
|
|
|
|
|
|
| 35 |
# Function to encode a file to base64
|
| 36 |
def encode_file_to_base64(file_path):
|
| 37 |
with open(file_path, "rb") as file:
|
| 38 |
encoded = base64.b64encode(file.read()).decode()
|
| 39 |
return encoded
|
| 40 |
|
|
|
|
|
|
|
| 41 |
def create_zip_of_files(files):
|
| 42 |
"""
|
| 43 |
Create a zip file from a list of files.
|
|
|
|
| 59 |
href = f'<a href="data:application/zip;base64,{b64}" download="{zip_file}">Download All</a>'
|
| 60 |
return href
|
| 61 |
|
|
|
|
|
|
|
| 62 |
# Function to clear all image files
|
| 63 |
def clear_all_images():
|
| 64 |
base_dir = os.getcwd() # Get the current base directory
|
|
|
|
| 68 |
for file in img_files:
|
| 69 |
os.remove(file)
|
| 70 |
print('removed:' + file)
|
| 71 |
+
|
|
|
|
| 72 |
# add file save and download and clear:
|
| 73 |
# Function to create a zip file from a list of files
|
| 74 |
def create_zip(files):
|
|
|
|
| 88 |
zip_filename = create_zip(images) # Create a zip file from the list of image files
|
| 89 |
print(' Zip file created:' + zip_filename)
|
| 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 |
|
|
|
|
| 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 |
print(download_link)
|
| 113 |
+
gr.HTML(download_link)
|
| 114 |
gr.Button(link=download_link)
|
| 115 |
|
| 116 |
# Function to handle "Clear All" button click
|
|
|
|
| 303 |
|
| 304 |
# Attach click event handlers to the buttons
|
| 305 |
save_all_button.click(save_all_button_click)
|
|
|
|
| 306 |
|
| 307 |
+
with gr.Column():
|
| 308 |
+
file_obj = gr.File(label="Input File")
|
| 309 |
+
input= file_obj
|
| 310 |
+
|
| 311 |
+
clear_all_button.click(clear_all_button_click)
|
| 312 |
|
| 313 |
demo.queue()
|
| 314 |
+
demo.launch()
|