Spaces:
Running
Running
Commit
·
a8ebb2f
1
Parent(s):
9ff1959
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess as sp
|
| 3 |
import os
|
| 4 |
import uuid
|
|
|
|
|
|
|
| 5 |
|
| 6 |
os.makedirs("./output", exist_ok=True)
|
| 7 |
|
|
@@ -11,7 +14,7 @@ def run(*args):
|
|
| 11 |
return "Source file does not exist"
|
| 12 |
if not os.path.exists(target):
|
| 13 |
return "Target file does not exist"
|
| 14 |
-
|
| 15 |
filename = os.path.basename(target)
|
| 16 |
os.makedirs(f"./output/{unique_id}",exist_ok=True)
|
| 17 |
output = f"./output/{unique_id}/{filename}"
|
|
@@ -68,6 +71,24 @@ def clear_output(unique_id):
|
|
| 68 |
except Exception as e:
|
| 69 |
return f"An error occurred: {str(e)}"
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
def get_theme() -> gr.Theme:
|
| 72 |
return gr.themes.Soft(
|
| 73 |
primary_hue = gr.themes.colors.red,
|
|
@@ -91,6 +112,7 @@ with gr.Blocks(theme=get_theme(), title="DeepFakeAI 1.0.0") as ui:
|
|
| 91 |
value = ['face_swapper'] # Default value
|
| 92 |
)
|
| 93 |
|
|
|
|
| 94 |
with gr.Box():
|
| 95 |
with gr.Column(scale=3):
|
| 96 |
face_analyser_direction_dropdown = gr.Dropdown(
|
|
|
|
| 1 |
+
#
|
| 2 |
import gradio as gr
|
| 3 |
import subprocess as sp
|
| 4 |
import os
|
| 5 |
import uuid
|
| 6 |
+
import time
|
| 7 |
+
import shutil
|
| 8 |
|
| 9 |
os.makedirs("./output", exist_ok=True)
|
| 10 |
|
|
|
|
| 14 |
return "Source file does not exist"
|
| 15 |
if not os.path.exists(target):
|
| 16 |
return "Target file does not exist"
|
| 17 |
+
remove_old_directories("./output", num_minutes=2)
|
| 18 |
filename = os.path.basename(target)
|
| 19 |
os.makedirs(f"./output/{unique_id}",exist_ok=True)
|
| 20 |
output = f"./output/{unique_id}/{filename}"
|
|
|
|
| 71 |
except Exception as e:
|
| 72 |
return f"An error occurred: {str(e)}"
|
| 73 |
|
| 74 |
+
def remove_old_directories(directory, num_minutes=10):
|
| 75 |
+
now = time.time()
|
| 76 |
+
|
| 77 |
+
for r, d, f in os.walk(directory):
|
| 78 |
+
for dir_name in d:
|
| 79 |
+
dir_path = os.path.join(r, dir_name)
|
| 80 |
+
timestamp = os.path.getmtime(dir_path)
|
| 81 |
+
age_minutes = (now - timestamp) / 60 # Convert to minutes
|
| 82 |
+
|
| 83 |
+
if age_minutes >= num_minutes:
|
| 84 |
+
try:
|
| 85 |
+
print("Removing", dir_path)
|
| 86 |
+
shutil.rmtree(dir_path)
|
| 87 |
+
print("Directory removed:", dir_path)
|
| 88 |
+
except Exception as e:
|
| 89 |
+
print(e)
|
| 90 |
+
pass
|
| 91 |
+
|
| 92 |
def get_theme() -> gr.Theme:
|
| 93 |
return gr.themes.Soft(
|
| 94 |
primary_hue = gr.themes.colors.red,
|
|
|
|
| 112 |
value = ['face_swapper'] # Default value
|
| 113 |
)
|
| 114 |
|
| 115 |
+
|
| 116 |
with gr.Box():
|
| 117 |
with gr.Column(scale=3):
|
| 118 |
face_analyser_direction_dropdown = gr.Dropdown(
|