File size: 950 Bytes
06cd1c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import cv2
import os
import gradio as gr
from run import run_faceswap
def process_face_swap(source_image, target_file):
source_path = "face.png"
target_path = "target" + os.path.splitext(target_file.name)[-1]
# Save uploaded numpy image using OpenCV
cv2.imwrite(source_path, cv2.cvtColor(source_image, cv2.COLOR_RGB2BGR))
# Save uploaded target file
with open(target_path, "wb") as f:
f.write(target_file.read())
# Call face swap
output_path = run_faceswap(source_path, target_path)
return output_path
iface = gr.Interface(
fn=process_face_swap,
inputs=[
gr.Image(label="Source Face (face.png)", type="numpy"),
gr.File(label="Target Image or Video (.jpg/.mp4)")
],
outputs=gr.File(label="Swapped Output"),
title="Lightweight Face Swap (User Logic)",
description="Upload face.png and target image/video. Output will be result.jpg or result.mp4"
)
iface.launch() |