Spaces:
Running
Running
Deepro Bardhan
commited on
Commit
·
2405f92
1
Parent(s):
2aa54ab
added time remaining
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import cv2
|
|
| 4 |
import numpy as np
|
| 5 |
import shutil
|
| 6 |
import subprocess
|
|
|
|
| 7 |
from SinglePhoto import FaceSwapper
|
| 8 |
|
| 9 |
wellcomingMessage = """
|
|
@@ -82,12 +83,18 @@ def swap_video(src_img, src_idx, video, dst_idx, progress=gr.Progress(track_tqdm
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
continue
|
| 92 |
try:
|
| 93 |
try:
|
|
@@ -103,7 +110,11 @@ def swap_video(src_img, src_idx, video, dst_idx, progress=gr.Progress(track_tqdm
|
|
| 103 |
except Exception as e:
|
| 104 |
cv2.imwrite(out_path, cv2.imread(frame_path))
|
| 105 |
log += f"Failed to swap frame {idx}: {e}\n"
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
cap = cv2.VideoCapture(dst_video_path)
|
| 108 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 109 |
cap.release()
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import shutil
|
| 6 |
import subprocess
|
| 7 |
+
import time
|
| 8 |
from SinglePhoto import FaceSwapper
|
| 9 |
|
| 10 |
wellcomingMessage = """
|
|
|
|
| 83 |
|
| 84 |
# Prepare swapped frames list and resume if possible
|
| 85 |
swapped_files = set(os.listdir(swapped_dir))
|
| 86 |
+
start_time = time.time()
|
| 87 |
+
total_frames = len(frame_paths)
|
| 88 |
for idx, frame_path in enumerate(frame_paths):
|
| 89 |
swapped_name = f"swapped_{idx:05d}.jpg"
|
| 90 |
out_path = os.path.join(swapped_dir, swapped_name)
|
| 91 |
if swapped_name in swapped_files and os.path.exists(out_path):
|
| 92 |
log += f"Frame {idx}: already swapped, skipping.\n"
|
| 93 |
+
elapsed = time.time() - start_time
|
| 94 |
+
avg_time = elapsed / (idx + 1) if idx + 1 > 0 else 0
|
| 95 |
+
remaining = avg_time * (total_frames - (idx + 1))
|
| 96 |
+
mins, secs = divmod(int(remaining), 60)
|
| 97 |
+
progress(0.15 + 0.6 * (idx + 1) / total_frames, desc=f"Swapping frames ({idx+1}/{total_frames}) | Est. left: {mins:02d}:{secs:02d}")
|
| 98 |
continue
|
| 99 |
try:
|
| 100 |
try:
|
|
|
|
| 110 |
except Exception as e:
|
| 111 |
cv2.imwrite(out_path, cv2.imread(frame_path))
|
| 112 |
log += f"Failed to swap frame {idx}: {e}\n"
|
| 113 |
+
elapsed = time.time() - start_time
|
| 114 |
+
avg_time = elapsed / (idx + 1) if idx + 1 > 0 else 0
|
| 115 |
+
remaining = avg_time * (total_frames - (idx + 1))
|
| 116 |
+
mins, secs = divmod(int(remaining), 60)
|
| 117 |
+
progress(0.15 + 0.6 * (idx + 1) / total_frames, desc=f"Swapping frames ({idx+1}/{total_frames}) | Est. left: {mins:02d}:{secs:02d}")
|
| 118 |
cap = cv2.VideoCapture(dst_video_path)
|
| 119 |
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 120 |
cap.release()
|