|
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] |
|
|
|
|
|
cv2.imwrite(source_path, cv2.cvtColor(source_image, cv2.COLOR_RGB2BGR)) |
|
|
|
|
|
with open(target_path, "wb") as f: |
|
f.write(target_file.read()) |
|
|
|
|
|
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() |