Spaces:
Running
Running
Deepro Bardhan
commited on
Commit
·
e489a8d
1
Parent(s):
4fa4bee
minor changes
Browse files
app.py
CHANGED
|
@@ -81,7 +81,15 @@ def swap_video(src_img, src_idx, video, dst_idx, progress=gr.Progress(track_tqdm
|
|
| 81 |
for idx, frame_path in enumerate(frame_paths):
|
| 82 |
out_path = os.path.join(swapped_dir, f"swapped_{idx:05d}.jpg")
|
| 83 |
try:
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
cv2.imwrite(out_path, swapped)
|
| 86 |
log += f"Swapped frame {idx} and saved to {out_path}\n"
|
| 87 |
except Exception as e:
|
|
|
|
| 81 |
for idx, frame_path in enumerate(frame_paths):
|
| 82 |
out_path = os.path.join(swapped_dir, f"swapped_{idx:05d}.jpg")
|
| 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:
|
| 92 |
+
raise ve
|
| 93 |
cv2.imwrite(out_path, swapped)
|
| 94 |
log += f"Swapped frame {idx} and saved to {out_path}\n"
|
| 95 |
except Exception as e:
|