Spaces:
Paused
Paused
Deepro Bardhan
commited on
Commit
·
2aa54ab
1
Parent(s):
e489a8d
minor changes 2
Browse files
app.py
CHANGED
|
@@ -74,18 +74,26 @@ def swap_video(src_img, src_idx, video, dst_idx, progress=gr.Progress(track_tqdm
|
|
| 74 |
dst_video_path = video
|
| 75 |
|
| 76 |
from VideoSwapping import extract_frames, frames_to_video
|
|
|
|
|
|
|
| 77 |
frame_paths = extract_frames(dst_video_path, frames_dir)
|
| 78 |
log += f"Extracted {len(frame_paths)} frames to {frames_dir}\n"
|
| 79 |
progress(0.15, desc="Extracted frames")
|
| 80 |
|
|
|
|
|
|
|
| 81 |
for idx, frame_path in enumerate(frame_paths):
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
try:
|
| 84 |
try:
|
| 85 |
swapped = swapper.swap_faces(src_path, int(src_idx), frame_path, int(dst_idx))
|
| 86 |
except ValueError as ve:
|
| 87 |
if int(dst_idx) != 1 and "Target image contains" in str(ve):
|
| 88 |
-
# Fallback to dst_idx=1 if requested index not found in this frame
|
| 89 |
swapped = swapper.swap_faces(src_path, int(src_idx), frame_path, 1)
|
| 90 |
log += f"Frame {idx}: dst_idx {dst_idx} not found, used 1 instead.\n"
|
| 91 |
else:
|
|
|
|
| 74 |
dst_video_path = video
|
| 75 |
|
| 76 |
from VideoSwapping import extract_frames, frames_to_video
|
| 77 |
+
|
| 78 |
+
# Extract frames only if not already present
|
| 79 |
frame_paths = extract_frames(dst_video_path, frames_dir)
|
| 80 |
log += f"Extracted {len(frame_paths)} frames to {frames_dir}\n"
|
| 81 |
progress(0.15, desc="Extracted frames")
|
| 82 |
|
| 83 |
+
# Prepare swapped frames list and resume if possible
|
| 84 |
+
swapped_files = set(os.listdir(swapped_dir))
|
| 85 |
for idx, frame_path in enumerate(frame_paths):
|
| 86 |
+
swapped_name = f"swapped_{idx:05d}.jpg"
|
| 87 |
+
out_path = os.path.join(swapped_dir, swapped_name)
|
| 88 |
+
if swapped_name in swapped_files and os.path.exists(out_path):
|
| 89 |
+
log += f"Frame {idx}: already swapped, skipping.\n"
|
| 90 |
+
progress(0.15 + 0.6 * (idx + 1) / len(frame_paths), desc=f"Swapping frames ({idx+1}/{len(frame_paths)})")
|
| 91 |
+
continue
|
| 92 |
try:
|
| 93 |
try:
|
| 94 |
swapped = swapper.swap_faces(src_path, int(src_idx), frame_path, int(dst_idx))
|
| 95 |
except ValueError as ve:
|
| 96 |
if int(dst_idx) != 1 and "Target image contains" in str(ve):
|
|
|
|
| 97 |
swapped = swapper.swap_faces(src_path, int(src_idx), frame_path, 1)
|
| 98 |
log += f"Frame {idx}: dst_idx {dst_idx} not found, used 1 instead.\n"
|
| 99 |
else:
|