Spaces:
Runtime error
Runtime error
import gradio as gr | |
import insightface | |
from insightface.app import FaceAnalysis | |
assert insightface.__version__ >= '0.7' | |
def prepare_app(): | |
app = FaceAnalysis(name='buffalo_l') | |
app.prepare(ctx_id=0, det_size=(640, 640)) | |
swapper = insightface.model_zoo.get_model('inswapper_128.onnx', download=True, download_zip=True) | |
return app, swapper | |
def swap_faces(sourceImage, destinationImage): | |
"""Swaps faces between the source and destination images.""" | |
app, swapper = prepare_app() | |
source_faces = app.get(sourceImage) | |
if not source_faces: | |
raise gr.Error("No face found in the source image.") | |
source_face = source_faces[0] | |
destination_faces = app.get(destinationImage) | |
if not destination_faces: | |
raise gr.Error("No face found in the destination image.") | |
destination_face = destination_faces[0] | |
result = swapper.get(destinationImage, destination_face, source_face, paste_back=True) | |
return result | |
gr.Interface( | |
swap_faces, | |
[ | |
gr.Image(label="Source Image"), | |
gr.Image(label="Destination Image"), | |
], | |
gr.Image(), | |
examples=[ | |
['./examples/IMG-a.jpg', './examples/IMG-a1.jpg'], | |
['./examples/IMG-b.jpg', './examples/IMG-b1.jpg'], | |
['./examples/IMG-c.jpg', './examples/IMG-c1.jpg'], | |
['./examples/IMG-d.jpg', './examples/IMG-d1.jpg'], | |
['./examples/IMG-a.jpg', './examples/IMG-a2.jpg'], | |
['./examples/IMG-b1.jpg', './examples/IMG-b11.jpg'], | |
], | |
theme="syddharth/gray-minimal", | |
title="<h1 style='color: black; text-decoration: underline;'>AI Face Swapping - Free Face Swap</h1>", | |
description="<span>β Experience the power of Ai Reface with Mergify.</span><br><span>β Swap faces with anyone in seconds - photos or AI images!</span><br><span>β A gradio demo for <a href='https://aiconvert.online/ai-face-merge/' style='color: blue; text-decoration: none;'>Mergify's Ai Face Swap </a></span><br><span>β Full features and Multiple Face Swapping For Free with no limitations at <a href='https://aiconvert.online' style='color: crimson; text-decoration: underline;'>Aiconvert.online</a></span>", | |
css=" footer{display:none !important;}" | |
).launch() | |