Spaces:
Runtime error
Runtime error
File size: 1,136 Bytes
e7f74df |
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 33 34 35 36 37 38 39 |
import gradio as gr
import io
import requests
import os
import base64
import cv2
from PIL import Image
import json
import numpy as np
import rsa
import insightface
from insightface.app import FaceAnalysis
def FaceSwap(source_img, dest_img):
swapper = insightface.model_zoo.get_model('./inswapper_128.onnx', download=False, download_zip=False)
app = FaceAnalysis(name="buffalo_l")
app.prepare(ctx_id=0, det_size=(640, 640))
s_faces = app.get(source_img)
if len(s_faces) == 0:
raise gr.Error("No Face Detected in Source Image")
d_faces = app.get(dest_img)
if len(d_faces) == 0:
raise gr.Error("No Face Detected in Destination Image")
source_face = s_faces[0]
dest_face = d_faces[0]
res = dest_img.copy()
res = swapper.get(res, dest_face, source_face, paste_back=True)
return res
if __name__ == "__main__":
with gr.Blocks(title="Face Swap | Meet With Your new Personality") as demo:
gr.Interface(fn=FaceSwap, inputs=["image","image"], outputs=["image"], allow_flagging="never")
demo.launch(show_api=False, favicon_path="./favicon.ico") |