Spaces:
Running
Running
Avoid delete the user files
Browse files
app.py
CHANGED
@@ -210,19 +210,22 @@ def reduce_and_convert(input_folder):
|
|
210 |
|
211 |
|
212 |
|
213 |
-
def clear_gradio_temp():
|
214 |
-
temp_dir = tempfile.gettempdir()
|
215 |
for folder in os.listdir(temp_dir):
|
216 |
folder_path = os.path.join(temp_dir, folder)
|
217 |
-
if "gradio" in folder_path.lower():
|
|
|
|
|
|
|
218 |
try:
|
219 |
-
shutil.rmtree(folder_path)
|
220 |
print(f"Deleted: {folder_path}")
|
221 |
except Exception as e:
|
222 |
print(f"Failed to delete {folder_path}: {e}")
|
223 |
|
224 |
def ui(input_files):
|
225 |
-
clear_gradio_temp()
|
226 |
output_zip = "./output.zip"
|
227 |
if os.path.exists(output_zip):
|
228 |
os.remove(output_zip)
|
|
|
210 |
|
211 |
|
212 |
|
213 |
+
def clear_gradio_temp(exclude_files):
|
214 |
+
temp_dir = tempfile.gettempdir()
|
215 |
for folder in os.listdir(temp_dir):
|
216 |
folder_path = os.path.join(temp_dir, folder)
|
217 |
+
if "gradio" in folder_path.lower():
|
218 |
+
should_skip = any(file_path.startswith(folder_path) for file_path in exclude_files)
|
219 |
+
if should_skip:
|
220 |
+
continue
|
221 |
try:
|
222 |
+
shutil.rmtree(folder_path)
|
223 |
print(f"Deleted: {folder_path}")
|
224 |
except Exception as e:
|
225 |
print(f"Failed to delete {folder_path}: {e}")
|
226 |
|
227 |
def ui(input_files):
|
228 |
+
clear_gradio_temp(input_files)
|
229 |
output_zip = "./output.zip"
|
230 |
if os.path.exists(output_zip):
|
231 |
os.remove(output_zip)
|