Spaces:
Sleeping
Sleeping
Update webgui.py
Browse files
webgui.py
CHANGED
@@ -28,6 +28,7 @@ import argparse
|
|
28 |
import gradio as gr
|
29 |
|
30 |
import huggingface_hub
|
|
|
31 |
|
32 |
huggingface_hub.snapshot_download(
|
33 |
repo_id='BadToBest/EchoMimic',
|
@@ -155,8 +156,8 @@ def select_face(det_bboxes, probs):
|
|
155 |
sorted_bboxes = sorted(filtered_bboxes, key=lambda x:(x[3]-x[1]) * (x[2] - x[0]), reverse=True)
|
156 |
return sorted_bboxes[0]
|
157 |
|
158 |
-
def process_video(uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device):
|
159 |
|
|
|
160 |
if seed is not None and seed > -1:
|
161 |
generator = torch.manual_seed(seed)
|
162 |
else:
|
@@ -176,7 +177,7 @@ def process_video(uploaded_img, uploaded_audio, width, height, length, seed, fac
|
|
176 |
r_pad = int((re - rb) * facemask_dilation_ratio)
|
177 |
c_pad = int((ce - cb) * facemask_dilation_ratio)
|
178 |
face_mask[rb - r_pad : re + r_pad, cb - c_pad : ce + c_pad] = 255
|
179 |
-
|
180 |
#### face crop
|
181 |
r_pad_crop = int((re - rb) * facecrop_dilation_ratio)
|
182 |
c_pad_crop = int((ce - cb) * facecrop_dilation_ratio)
|
@@ -188,7 +189,7 @@ def process_video(uploaded_img, uploaded_audio, width, height, length, seed, fac
|
|
188 |
|
189 |
ref_image_pil = Image.fromarray(face_img[:, :, [2, 1, 0]])
|
190 |
face_mask_tensor = torch.Tensor(face_mask).to(dtype=weight_dtype, device="cuda").unsqueeze(0).unsqueeze(0).unsqueeze(0) / 255.0
|
191 |
-
|
192 |
video = pipe(
|
193 |
ref_image_pil,
|
194 |
uploaded_audio,
|
@@ -212,9 +213,19 @@ def process_video(uploaded_img, uploaded_audio, width, height, length, seed, fac
|
|
212 |
|
213 |
video_clip = VideoFileClip(str(output_video_path))
|
214 |
audio_clip = AudioFileClip(uploaded_audio)
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
|
219 |
return final_output_path
|
220 |
|
|
|
28 |
import gradio as gr
|
29 |
|
30 |
import huggingface_hub
|
31 |
+
from moviepy.editor import VideoFileClip, AudioFileClip, ImageClip
|
32 |
|
33 |
huggingface_hub.snapshot_download(
|
34 |
repo_id='BadToBest/EchoMimic',
|
|
|
156 |
sorted_bboxes = sorted(filtered_bboxes, key=lambda x:(x[3]-x[1]) * (x[2] - x[0]), reverse=True)
|
157 |
return sorted_bboxes[0]
|
158 |
|
|
|
159 |
|
160 |
+
def process_video(uploaded_img, uploaded_audio, width, height, length, seed, facemask_dilation_ratio, facecrop_dilation_ratio, context_frames, context_overlap, cfg, steps, sample_rate, fps, device):
|
161 |
if seed is not None and seed > -1:
|
162 |
generator = torch.manual_seed(seed)
|
163 |
else:
|
|
|
177 |
r_pad = int((re - rb) * facemask_dilation_ratio)
|
178 |
c_pad = int((ce - cb) * facemask_dilation_ratio)
|
179 |
face_mask[rb - r_pad : re + r_pad, cb - c_pad : ce + c_pad] = 255
|
180 |
+
|
181 |
#### face crop
|
182 |
r_pad_crop = int((re - rb) * facecrop_dilation_ratio)
|
183 |
c_pad_crop = int((ce - cb) * facecrop_dilation_ratio)
|
|
|
189 |
|
190 |
ref_image_pil = Image.fromarray(face_img[:, :, [2, 1, 0]])
|
191 |
face_mask_tensor = torch.Tensor(face_mask).to(dtype=weight_dtype, device="cuda").unsqueeze(0).unsqueeze(0).unsqueeze(0) / 255.0
|
192 |
+
|
193 |
video = pipe(
|
194 |
ref_image_pil,
|
195 |
uploaded_audio,
|
|
|
213 |
|
214 |
video_clip = VideoFileClip(str(output_video_path))
|
215 |
audio_clip = AudioFileClip(uploaded_audio)
|
216 |
+
|
217 |
+
# 워터마크 이미지 로드 및 크기 조정
|
218 |
+
watermark = (ImageClip("watermark.png") # 워터마크 이미지 경로
|
219 |
+
.set_duration(video_clip.duration)
|
220 |
+
.resize(height=50) # 워터마크 크기 조정
|
221 |
+
.margin(right=8, bottom=8, opacity=0) # 마진 및 투명도 설정
|
222 |
+
.set_pos(("right", "bottom"))) # 위치 설정
|
223 |
+
|
224 |
+
final_clip = video_clip.set_audio(audio_clip).set_position(("center", "center")).fx(vfx.composite, watermark)
|
225 |
+
|
226 |
+
# APP.PY와 동일한 경로에 위치시키기
|
227 |
+
final_output_path = Path(__file__).parent / "output_video_with_audio.mp4"
|
228 |
+
final_clip.write_videofile(str(final_output_path), codec="libx264", audio_codec="aac")
|
229 |
|
230 |
return final_output_path
|
231 |
|