Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
|
|
3 |
import yaml
|
4 |
import tempfile
|
5 |
import huggingface_hub
|
@@ -43,13 +44,43 @@ def print_directory_contents(path):
|
|
43 |
for f in files:
|
44 |
print(f"{subindent}{f}")
|
45 |
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
def infer(ref_video_in, ref_image_in):
|
|
|
|
|
|
|
53 |
# Create a temporary directory
|
54 |
with tempfile.TemporaryDirectory() as temp_dir:
|
55 |
print("Temporary directory created:", temp_dir)
|
@@ -115,15 +146,20 @@ def infer(ref_video_in, ref_image_in):
|
|
115 |
stderr_thread.join()
|
116 |
|
117 |
print("Inference script finished with return code:", process.returncode)
|
118 |
-
|
|
|
119 |
print_directory_contents('./outputs')
|
|
|
|
|
|
|
|
|
120 |
|
121 |
-
return
|
122 |
|
123 |
demo = gr.Interface(
|
124 |
fn = infer,
|
125 |
inputs = [gr.Video(), gr.Image(type="filepath")],
|
126 |
-
outputs = [gr.
|
127 |
)
|
128 |
|
129 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import shutil
|
4 |
import yaml
|
5 |
import tempfile
|
6 |
import huggingface_hub
|
|
|
44 |
for f in files:
|
45 |
print(f"{subindent}{f}")
|
46 |
|
47 |
+
def check_outputs_folder(folder_path):
|
48 |
+
# Check if the folder exists
|
49 |
+
if os.path.exists(folder_path) and os.path.isdir(folder_path):
|
50 |
+
# Delete all contents inside the folder
|
51 |
+
for filename in os.listdir(folder_path):
|
52 |
+
file_path = os.path.join(folder_path, filename)
|
53 |
+
try:
|
54 |
+
if os.path.isfile(file_path) or os.path.islink(file_path):
|
55 |
+
os.unlink(file_path) # Remove file or link
|
56 |
+
elif os.path.isdir(file_path):
|
57 |
+
shutil.rmtree(file_path) # Remove directory
|
58 |
+
except Exception as e:
|
59 |
+
print(f'Failed to delete {file_path}. Reason: {e}')
|
60 |
+
else:
|
61 |
+
print(f'The folder {folder_path} does not exist.')
|
62 |
|
63 |
+
def check_for_mp4_in_outputs():
|
64 |
+
# Define the path to the outputs folder
|
65 |
+
outputs_folder = './outputs'
|
66 |
+
|
67 |
+
# Check if the outputs folder exists
|
68 |
+
if not os.path.exists(outputs_folder):
|
69 |
+
return None
|
70 |
+
|
71 |
+
# Check if there is a .mp4 file in the outputs folder
|
72 |
+
mp4_files = [f for f in os.listdir(outputs_folder) if f.endswith('.mp4')]
|
73 |
+
|
74 |
+
# Return the path to the mp4 file if it exists
|
75 |
+
if mp4_files:
|
76 |
+
return os.path.join(outputs_folder, mp4_files[0])
|
77 |
+
else:
|
78 |
+
return None
|
79 |
|
80 |
+
def infer(ref_video_in, ref_image_in, progress=gr.Progress()):
|
81 |
+
# check if 'outputs' dir exists and empty it if necessary
|
82 |
+
check_outputs_folder('./outputs')
|
83 |
+
|
84 |
# Create a temporary directory
|
85 |
with tempfile.TemporaryDirectory() as temp_dir:
|
86 |
print("Temporary directory created:", temp_dir)
|
|
|
146 |
stderr_thread.join()
|
147 |
|
148 |
print("Inference script finished with return code:", process.returncode)
|
149 |
+
|
150 |
+
# Print the outputs directory contents
|
151 |
print_directory_contents('./outputs')
|
152 |
+
|
153 |
+
# Call the function and print the result
|
154 |
+
mp4_file_path = check_for_mp4_in_outputs()
|
155 |
+
print(mp4_file_path)
|
156 |
|
157 |
+
return mp4_file_path
|
158 |
|
159 |
demo = gr.Interface(
|
160 |
fn = infer,
|
161 |
inputs = [gr.Video(), gr.Image(type="filepath")],
|
162 |
+
outputs = [gr.Video()]
|
163 |
)
|
164 |
|
165 |
demo.launch()
|