profaker commited on
Commit
b5acdca
·
verified ·
1 Parent(s): 1f13053

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -9,6 +9,7 @@ import gradio as gr
9
  import subprocess
10
  from PIL import Image
11
 
 
12
 
13
  def video_to_frames(video_path, output_folder):
14
  vidcap = cv2.VideoCapture(video_path)
@@ -30,6 +31,7 @@ def video_to_frames(video_path, output_folder):
30
 
31
  def frames_to_video(frame_folder, video_path, image_path, frame_count,fps):
32
  print("ImagePath",image_path)
 
33
  frames = [f for f in os.listdir(frame_folder) if f.endswith('.jpg')]
34
  frames.sort(key=lambda x: int(x.split('_')[1].split('.')[0])) # Sort frames in ascending order
35
 
@@ -47,6 +49,7 @@ def frames_to_video(frame_folder, video_path, image_path, frame_count,fps):
47
  face_enhancer = gfpgan.GFPGANer(model_path="GFPGANv1.4.pth", upscale=1, device='cuda')
48
 
49
  for i in tqdm(range(frame_count), desc="Converting frames to video"):
 
50
  img1 = cv2.imread(os.path.join(frame_folder, frames[i]))
51
  #img2_pil = Image.open(image_path)
52
  #img2_cv2 = cv2.cvtColor(np.array(img2_pil), cv2.COLOR_RGB2BGR)
@@ -68,7 +71,6 @@ def frames_to_video(frame_folder, video_path, image_path, frame_count,fps):
68
  else:
69
  out.write(img1)
70
  progress = int((i + 1) / frame_count * 100)
71
- print(progress,end="")
72
  out.release()
73
 
74
  print(f"Video saved at {video_path}.")
@@ -76,8 +78,8 @@ def frames_to_video(frame_folder, video_path, image_path, frame_count,fps):
76
  def face_swap(video_path, image_path):
77
  output_folder = "Out_Frames"
78
  frame_count = video_to_frames(video_path, output_folder)
79
- if frame_count[0] > 500:
80
- frame_count[0] = 500
81
  output_video_path = "output_video.mp4"
82
  frames_to_video(output_folder, output_video_path, image_path, frame_count[0],frame_count[1])
83
  return output_video_path
 
9
  import subprocess
10
  from PIL import Image
11
 
12
+ progress = 0
13
 
14
  def video_to_frames(video_path, output_folder):
15
  vidcap = cv2.VideoCapture(video_path)
 
31
 
32
  def frames_to_video(frame_folder, video_path, image_path, frame_count,fps):
33
  print("ImagePath",image_path)
34
+ global progress
35
  frames = [f for f in os.listdir(frame_folder) if f.endswith('.jpg')]
36
  frames.sort(key=lambda x: int(x.split('_')[1].split('.')[0])) # Sort frames in ascending order
37
 
 
49
  face_enhancer = gfpgan.GFPGANer(model_path="GFPGANv1.4.pth", upscale=1, device='cuda')
50
 
51
  for i in tqdm(range(frame_count), desc="Converting frames to video"):
52
+ print("Progress:",progress)
53
  img1 = cv2.imread(os.path.join(frame_folder, frames[i]))
54
  #img2_pil = Image.open(image_path)
55
  #img2_cv2 = cv2.cvtColor(np.array(img2_pil), cv2.COLOR_RGB2BGR)
 
71
  else:
72
  out.write(img1)
73
  progress = int((i + 1) / frame_count * 100)
 
74
  out.release()
75
 
76
  print(f"Video saved at {video_path}.")
 
78
  def face_swap(video_path, image_path):
79
  output_folder = "Out_Frames"
80
  frame_count = video_to_frames(video_path, output_folder)
81
+ if frame_count[0] > 400:
82
+ frame_count[0] = 400
83
  output_video_path = "output_video.mp4"
84
  frames_to_video(output_folder, output_video_path, image_path, frame_count[0],frame_count[1])
85
  return output_video_path