Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,22 +10,26 @@ def generate(video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bo
|
|
10 |
if video is None or audio is None or checkpoint is None:
|
11 |
return "Пожалуйста, загрузите видео/изображение и аудио файл, а также выберите чекпойнт."
|
12 |
|
13 |
-
#
|
14 |
-
|
|
|
15 |
|
|
|
16 |
with tempfile.TemporaryDirectory() as temp_dir:
|
17 |
-
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
|
22 |
# Подготовка аргументов для инференса
|
23 |
args = [
|
24 |
"--checkpoint_path", f"checkpoints/{checkpoint}.pth",
|
25 |
"--segmentation_path", "checkpoints/face_segmentation.pth",
|
26 |
"--enhance_face", "gfpgan",
|
27 |
-
"--face",
|
28 |
-
"--audio",
|
29 |
"--outfile", output_path,
|
30 |
"--resize_factor", str(resize_factor),
|
31 |
"--pads", str(pad_top), str(pad_bottom), str(pad_left), str(pad_right)
|
@@ -35,19 +39,18 @@ def generate(video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bo
|
|
35 |
args.append("--nosmooth")
|
36 |
|
37 |
try:
|
38 |
-
#
|
39 |
-
print(f"Running inference with command: python inference.py {' '.join(args)}")
|
40 |
-
|
41 |
cmd = ["python", "inference.py"] + args
|
42 |
-
subprocess.run(cmd, check=True)
|
43 |
except subprocess.CalledProcessError as e:
|
44 |
return f"Произошла ошибка при обработке: {e}"
|
45 |
|
|
|
46 |
if not os.path.exists(output_path):
|
47 |
return "Не удалось создать выходное видео."
|
48 |
|
49 |
-
|
50 |
-
|
51 |
|
52 |
with gr.Blocks() as ui:
|
53 |
gr.Markdown("## Wav2Lip - Синхронизация губ в видео")
|
@@ -72,7 +75,7 @@ with gr.Blocks() as ui:
|
|
72 |
generate,
|
73 |
inputs=[video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bottom, pad_left, pad_right],
|
74 |
outputs=result,
|
75 |
-
concurrency_limit=1
|
76 |
)
|
77 |
|
78 |
ui.launch(debug=True)
|
|
|
10 |
if video is None or audio is None or checkpoint is None:
|
11 |
return "Пожалуйста, загрузите видео/изображение и аудио файл, а также выберите чекпойнт."
|
12 |
|
13 |
+
# Поскольку Gradio возвращает пути к файлам, используем их напрямую
|
14 |
+
video_path = video # Уже строка с путем к видео
|
15 |
+
audio_path = audio # Уже строка с путем к аудио
|
16 |
|
17 |
+
# Создание временной директории для сохранения выходного видео
|
18 |
with tempfile.TemporaryDirectory() as temp_dir:
|
19 |
+
# Создание поддиректории 'temp' внутри temp_dir для inference.py
|
20 |
+
temp_subdir = os.path.join(temp_dir, 'temp')
|
21 |
+
os.makedirs(temp_subdir, exist_ok=True)
|
22 |
|
23 |
+
# Определение выходного файла
|
24 |
+
output_path = os.path.join(temp_dir, "output.mp4")
|
25 |
|
26 |
# Подготовка аргументов для инференса
|
27 |
args = [
|
28 |
"--checkpoint_path", f"checkpoints/{checkpoint}.pth",
|
29 |
"--segmentation_path", "checkpoints/face_segmentation.pth",
|
30 |
"--enhance_face", "gfpgan",
|
31 |
+
"--face", video_path,
|
32 |
+
"--audio", audio_path,
|
33 |
"--outfile", output_path,
|
34 |
"--resize_factor", str(resize_factor),
|
35 |
"--pads", str(pad_top), str(pad_bottom), str(pad_left), str(pad_right)
|
|
|
39 |
args.append("--nosmooth")
|
40 |
|
41 |
try:
|
42 |
+
# Вызов команды с установкой рабочей директории в temp_dir
|
|
|
|
|
43 |
cmd = ["python", "inference.py"] + args
|
44 |
+
subprocess.run(cmd, check=True, cwd=temp_dir)
|
45 |
except subprocess.CalledProcessError as e:
|
46 |
return f"Произошла ошибка при обработке: {e}"
|
47 |
|
48 |
+
# Проверка наличия выходного файла
|
49 |
if not os.path.exists(output_path):
|
50 |
return "Не удалось создать выходное видео."
|
51 |
|
52 |
+
# Возвращаем путь к выходному файлу
|
53 |
+
return output_path # Gradio автоматически обработает путь и выведет видео
|
54 |
|
55 |
with gr.Blocks() as ui:
|
56 |
gr.Markdown("## Wav2Lip - Синхронизация губ в видео")
|
|
|
75 |
generate,
|
76 |
inputs=[video, audio, checkpoint, no_smooth, resize_factor, pad_top, pad_bottom, pad_left, pad_right],
|
77 |
outputs=result,
|
78 |
+
concurrency_limit=1 # Устанавливаем лимит на количество одновременно выполняемых операций
|
79 |
)
|
80 |
|
81 |
ui.launch(debug=True)
|