LogicGoInfotechSpaces commited on
Commit
5fc122d
·
verified ·
1 Parent(s): e24b088

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -162,7 +162,7 @@ def enhance_image_with_codeformer(rgb_img, temp_dir=None):
162
  python_cmd = sys.executable if sys.executable else "python3"
163
  cmd = (
164
  f"{python_cmd} {CODEFORMER_PATH} "
165
- f"-w 0.7 "
166
  f"--input_path {input_path} "
167
  f"--output_path {temp_dir} "
168
  f"--bg_upsampler realesrgan "
@@ -366,14 +366,16 @@ def face_swap_and_enhance(src_img, tgt_img, temp_dir=None):
366
  return None, None, "❌ Face not detected in one of the images"
367
 
368
  swapped_path = os.path.join(temp_dir, f"swapped_{uuid.uuid4().hex[:8]}.jpg")
369
- swapped_bgr = swapper.get(tgt_bgr, tgt_faces[0], src_faces[0])
 
 
370
  if swapped_bgr is None:
371
  return None, None, "❌ Face swap failed"
372
 
373
  cv2.imwrite(swapped_path, swapped_bgr)
374
 
375
  python_cmd = sys.executable if sys.executable else "python3"
376
- cmd = f"{python_cmd} {CODEFORMER_PATH} -w 0.7 --input_path {swapped_path} --output_path {temp_dir} --bg_upsampler realesrgan --face_upsample"
377
  result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
378
  if result.returncode != 0:
379
  return None, None, f"❌ CodeFormer failed:\n{result.stderr}"
@@ -474,7 +476,7 @@ def build_multi_faceswap_gradio():
474
 
475
  def process(src_img, tgt_img):
476
  try:
477
- swapped = multi_face_swap(src_img, tgt_img)
478
  enhanced = enhance_image_with_codeformer(swapped)
479
  return enhanced, ""
480
  except Exception as e:
 
162
  python_cmd = sys.executable if sys.executable else "python3"
163
  cmd = (
164
  f"{python_cmd} {CODEFORMER_PATH} "
165
+ f"-w 0.4 "
166
  f"--input_path {input_path} "
167
  f"--output_path {temp_dir} "
168
  f"--bg_upsampler realesrgan "
 
366
  return None, None, "❌ Face not detected in one of the images"
367
 
368
  swapped_path = os.path.join(temp_dir, f"swapped_{uuid.uuid4().hex[:8]}.jpg")
369
+ swapped_rgb = multi_face_swap_industry(src_img, tgt_img)
370
+ swapped_bgr = cv2.cvtColor(swapped_rgb, cv2.COLOR_RGB2BGR)
371
+
372
  if swapped_bgr is None:
373
  return None, None, "❌ Face swap failed"
374
 
375
  cv2.imwrite(swapped_path, swapped_bgr)
376
 
377
  python_cmd = sys.executable if sys.executable else "python3"
378
+ cmd = f"{python_cmd} {CODEFORMER_PATH} -w 0.4 --input_path {swapped_path} --output_path {temp_dir} --bg_upsampler realesrgan --face_upsample"
379
  result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
380
  if result.returncode != 0:
381
  return None, None, f"❌ CodeFormer failed:\n{result.stderr}"
 
476
 
477
  def process(src_img, tgt_img):
478
  try:
479
+ swapped = multi_face_swap_industry(src_img, tgt_img)
480
  enhanced = enhance_image_with_codeformer(swapped)
481
  return enhanced, ""
482
  except Exception as e: