root commited on
Commit
ff3fa65
·
1 Parent(s): 28ff6fb
Files changed (4) hide show
  1. __pycache__/handler.cpython-310.pyc +0 -0
  2. handler.py +12 -0
  3. result.mp4 +0 -0
  4. sampler.py +13 -1
__pycache__/handler.cpython-310.pyc CHANGED
Binary files a/__pycache__/handler.cpython-310.pyc and b/__pycache__/handler.cpython-310.pyc differ
 
handler.py CHANGED
@@ -258,6 +258,15 @@ class EndpointHandler():
258
  for f in files:
259
  print(f"{subindent}{f}")
260
 
 
 
 
 
 
 
 
 
 
261
  def __call__(self, data: Any) -> Dict[str, str]:
262
  inputs = data.get("inputs", {})
263
  ref_image_url = inputs.get("ref_image_url", "")
@@ -363,9 +372,11 @@ class EndpointHandler():
363
  torch.cuda.empty_cache()
364
 
365
  # Perform face swapping
 
366
  swapped_face_video_path = os.path.join(save_dir, "swapped_face_output.mp4")
367
 
368
  # Subprocess call to facefusion for face swapping
 
369
  facefusion_script_path = os.path.join(base_dir, 'facefusion', 'core.py')
370
  swap_command = f'python3 {facefusion_script_path} --source {cropped_face_path} --target {animation_path} --output {swapped_face_video_path}'
371
  swap_result = subprocess.run(swap_command, shell=True, capture_output=True, text=True)
@@ -382,6 +393,7 @@ class EndpointHandler():
382
 
383
 
384
  #remove background
 
385
  removed_background_output_path = os.path.join(save_dir, "removed_background_result.mp4")
386
  remove_background_command = f'python3 ./rembg_video.py {swapped_face_video_path} {removed_background_output_path}'
387
  print("Command is " + remove_background_command)
 
258
  for f in files:
259
  print(f"{subindent}{f}")
260
 
261
+ def print_directory_contents(self, path='.'):
262
+ for root, dirs, files in os.walk(path):
263
+ level = root.replace(path, '').count(os.sep)
264
+ indent = ' ' * 4 * level
265
+ print(f'{indent}{os.path.basename(root)}/')
266
+ sub_indent = ' ' * 4 * (level + 1)
267
+ for f in files:
268
+ print(f'{sub_indent}{f}')
269
+
270
  def __call__(self, data: Any) -> Dict[str, str]:
271
  inputs = data.get("inputs", {})
272
  ref_image_url = inputs.get("ref_image_url", "")
 
372
  torch.cuda.empty_cache()
373
 
374
  # Perform face swapping
375
+ self.print_directory_contents()
376
  swapped_face_video_path = os.path.join(save_dir, "swapped_face_output.mp4")
377
 
378
  # Subprocess call to facefusion for face swapping
379
+ self.print_directory_contents()
380
  facefusion_script_path = os.path.join(base_dir, 'facefusion', 'core.py')
381
  swap_command = f'python3 {facefusion_script_path} --source {cropped_face_path} --target {animation_path} --output {swapped_face_video_path}'
382
  swap_result = subprocess.run(swap_command, shell=True, capture_output=True, text=True)
 
393
 
394
 
395
  #remove background
396
+ self.print_directory_contents()
397
  removed_background_output_path = os.path.join(save_dir, "removed_background_result.mp4")
398
  remove_background_command = f'python3 ./rembg_video.py {swapped_face_video_path} {removed_background_output_path}'
399
  print("Command is " + remove_background_command)
result.mp4 DELETED
File without changes
sampler.py CHANGED
@@ -3,8 +3,20 @@ import json
3
  from handler import EndpointHandler
4
  from PIL import Image
5
  import io
 
 
6
 
7
  # Initialize the handler
 
 
 
 
 
 
 
 
 
 
8
  handler = EndpointHandler()
9
 
10
  # Define sample inputs
@@ -12,7 +24,7 @@ inputs = {
12
  "inputs": {
13
  "ref_image_url": "https://media.discordapp.net/attachments/1237667104866697267/1246982998520496261/image.jpg?ex=665e5eea&is=665d0d6a&hm=46a719438e039655788336902d62419a2921a00720b21ac17e74755cb6de8cee&=&format=webp&width=976&height=1192",
14
  "video_url": "https://cdn.discordapp.com/attachments/1237667104866697267/1246950669689290752/pose.mp4?ex=665e40ce&is=665cef4e&hm=37a5f042a2d03f71c4ae5e9f56616a35d205b97df0ff205182cab28aa7784bbb&",
15
- "length": 96,
16
  "num_inference_steps": 25,
17
  "cfg": 3.5,
18
  "seed": 123
 
3
  from handler import EndpointHandler
4
  from PIL import Image
5
  import io
6
+ import os
7
+ import subprocess
8
 
9
  # Initialize the handler
10
+ # base_dir = os.path.dirname(os.path.abspath(__file__))
11
+ # video_root = os.path.join(base_dir, "dw_poses_videos")
12
+ # extract_pose_path = os.path.join(base_dir, 'extract_dwpose_from_vid.py')
13
+ # command = f'python3 {extract_pose_path} --video_root {video_root}'
14
+
15
+ # # Run the command with shell=True
16
+ # result = subprocess.run(command, shell=True, capture_output=True, text=True)
17
+ # if result.returncode != 0:
18
+ # raise RuntimeError(f"Error running extract_dwpose_from_vid.py: {result.stderr}")
19
+
20
  handler = EndpointHandler()
21
 
22
  # Define sample inputs
 
24
  "inputs": {
25
  "ref_image_url": "https://media.discordapp.net/attachments/1237667104866697267/1246982998520496261/image.jpg?ex=665e5eea&is=665d0d6a&hm=46a719438e039655788336902d62419a2921a00720b21ac17e74755cb6de8cee&=&format=webp&width=976&height=1192",
26
  "video_url": "https://cdn.discordapp.com/attachments/1237667104866697267/1246950669689290752/pose.mp4?ex=665e40ce&is=665cef4e&hm=37a5f042a2d03f71c4ae5e9f56616a35d205b97df0ff205182cab28aa7784bbb&",
27
+ "length": 12,
28
  "num_inference_steps": 25,
29
  "cfg": 3.5,
30
  "seed": 123