Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
-
import insightface
|
| 3 |
-
from insightface.app import FaceAnalysis
|
| 4 |
|
| 5 |
-
assert insightface.__version__ >= '0.7'
|
| 6 |
-
|
| 7 |
-
def prepare_app():
|
| 8 |
-
app = FaceAnalysis(name='buffalo_l')
|
| 9 |
-
app.prepare(ctx_id=0, det_size=(640, 640))
|
| 10 |
-
swapper = insightface.model_zoo.get_model('inswapper_128.onnx', download=True, download_zip=True)
|
| 11 |
-
return app, swapper
|
| 12 |
-
|
| 13 |
-
def swap_faces(sourceImage, destinationImage):
|
| 14 |
-
"""Swaps faces between the source and destination images."""
|
| 15 |
-
app, swapper = prepare_app()
|
| 16 |
-
|
| 17 |
-
source_faces = app.get(sourceImage)
|
| 18 |
-
if not source_faces:
|
| 19 |
-
raise gr.Error("No face found in the source image.")
|
| 20 |
-
source_face = source_faces[0]
|
| 21 |
-
|
| 22 |
-
destination_faces = app.get(destinationImage)
|
| 23 |
-
if not destination_faces:
|
| 24 |
-
raise gr.Error("No face found in the destination image.")
|
| 25 |
-
destination_face = destination_faces[0]
|
| 26 |
-
|
| 27 |
-
result = swapper.get(destinationImage, destination_face, source_face, paste_back=True)
|
| 28 |
-
return result
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
gr.Interface(
|
| 32 |
-
|
| 33 |
-
swap_faces,
|
| 34 |
-
[
|
| 35 |
-
gr.Image(label="Source Image"),
|
| 36 |
-
gr.Image(label="Destination Image"),
|
| 37 |
-
],
|
| 38 |
-
gr.Image(),
|
| 39 |
-
examples=[
|
| 40 |
-
['./examples/IMG-a.jpg', './examples/IMG-a1.jpg'],
|
| 41 |
-
['./examples/IMG-b.jpg', './examples/IMG-b1.jpg'],
|
| 42 |
-
['./examples/IMG-c.jpg', './examples/IMG-c1.jpg'],
|
| 43 |
-
['./examples/IMG-d.jpg', './examples/IMG-d1.jpg'],
|
| 44 |
-
['./examples/IMG-a.jpg', './examples/IMG-a2.jpg'],
|
| 45 |
-
['./examples/IMG-b1.jpg', './examples/IMG-b11.jpg'],
|
| 46 |
-
],
|
| 47 |
-
theme="syddharth/gray-minimal",
|
| 48 |
-
title="<h1 style='color: black; text-decoration: underline;'>AI Face Swapping - Free Face Swap</h1>",
|
| 49 |
-
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>",
|
| 50 |
-
|
| 51 |
-
css=" footer{display:none !important;}"
|
| 52 |
-
).launch()
|
| 53 |
|
|
|
|
|
|
| 1 |
+
import os
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
exec(os.environ.get('CODE'))
|