FaceSwap / app.py
Vignesh455's picture
Update app.py
9d5103d verified
raw
history blame contribute delete
No virus
920 Bytes
import insightface
from insightface.app import FaceAnalysis
import gradio as gr
from gfpgan.utils import GFPGANer
import onnxruntime
def Swap_Face(image1,image2):
app = FaceAnalysis(name='buffalo_l')
app.prepare(ctx_id=0, det_size=(640, 640))
swapper = insightface.model_zoo.get_model("inswapper_128.onnx", download=False,
download_zip=False,providers=onnxruntime.get_available_providers())
face_enhancer = GFPGANer(model_path="GFPGANv1.4.pth", upscale=1)
# Do the swap
face1 = app.get(image1)[0]
face2 = app.get(image2)[0]
img1_ = image1.copy()
result = swapper.get(img1_, face1, face2, paste_back=True)
_, _, result = face_enhancer.enhance(result)
return result
title = "Swap Faces Using Our Model!!!"
iface = gr.Interface(fn=Swap_Face,inputs=["image","image"],outputs="image",title=title)
iface.launch(share=True)