Spaces:
Runtime error
Runtime error
MayankTamakuwala
commited on
Commit
•
e7f74df
1
Parent(s):
6f74c1e
Init
Browse files- FaceSwap.py +39 -0
- inswapper_128.onnx +3 -0
- requirements.txt +93 -0
FaceSwap.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import io
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
import base64
|
6 |
+
import cv2
|
7 |
+
from PIL import Image
|
8 |
+
import json
|
9 |
+
import numpy as np
|
10 |
+
import rsa
|
11 |
+
import insightface
|
12 |
+
from insightface.app import FaceAnalysis
|
13 |
+
|
14 |
+
def FaceSwap(source_img, dest_img):
|
15 |
+
|
16 |
+
swapper = insightface.model_zoo.get_model('./inswapper_128.onnx', download=False, download_zip=False)
|
17 |
+
|
18 |
+
app = FaceAnalysis(name="buffalo_l")
|
19 |
+
app.prepare(ctx_id=0, det_size=(640, 640))
|
20 |
+
|
21 |
+
s_faces = app.get(source_img)
|
22 |
+
if len(s_faces) == 0:
|
23 |
+
raise gr.Error("No Face Detected in Source Image")
|
24 |
+
|
25 |
+
d_faces = app.get(dest_img)
|
26 |
+
if len(d_faces) == 0:
|
27 |
+
raise gr.Error("No Face Detected in Destination Image")
|
28 |
+
|
29 |
+
source_face = s_faces[0]
|
30 |
+
dest_face = d_faces[0]
|
31 |
+
|
32 |
+
res = dest_img.copy()
|
33 |
+
res = swapper.get(res, dest_face, source_face, paste_back=True)
|
34 |
+
return res
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
with gr.Blocks(title="Face Swap | Meet With Your new Personality") as demo:
|
38 |
+
gr.Interface(fn=FaceSwap, inputs=["image","image"], outputs=["image"], allow_flagging="never")
|
39 |
+
demo.launch(show_api=False, favicon_path="./favicon.ico")
|
inswapper_128.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e4a3f08c753cb72d04e10aa0f7dbe3deebbf39567d4ead6dce08e98aa49e16af
|
3 |
+
size 554253681
|
requirements.txt
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
albumentations==1.3.1
|
3 |
+
altair==5.2.0
|
4 |
+
annotated-types==0.6.0
|
5 |
+
anyio==4.2.0
|
6 |
+
attrs==23.2.0
|
7 |
+
certifi==2023.11.17
|
8 |
+
charset-normalizer==3.3.2
|
9 |
+
click==8.1.7
|
10 |
+
colorama==0.4.6
|
11 |
+
coloredlogs==15.0.1
|
12 |
+
contourpy==1.2.0
|
13 |
+
cycler==0.12.1
|
14 |
+
Cython==3.0.8
|
15 |
+
easydict==1.11
|
16 |
+
fastapi==0.109.0
|
17 |
+
ffmpy==0.3.1
|
18 |
+
filelock==3.13.1
|
19 |
+
flatbuffers==23.5.26
|
20 |
+
fonttools==4.47.2
|
21 |
+
fsspec==2023.12.2
|
22 |
+
gradio==4.16.0
|
23 |
+
gradio_client==0.8.1
|
24 |
+
h11==0.14.0
|
25 |
+
httpcore==1.0.2
|
26 |
+
httpx==0.26.0
|
27 |
+
huggingface-hub==0.20.3
|
28 |
+
humanfriendly==10.0
|
29 |
+
idna==3.6
|
30 |
+
imageio==2.33.1
|
31 |
+
importlib-resources==6.1.1
|
32 |
+
insightface==0.7.3
|
33 |
+
Jinja2==3.1.3
|
34 |
+
joblib==1.3.2
|
35 |
+
jsonschema==4.21.1
|
36 |
+
jsonschema-specifications==2023.12.1
|
37 |
+
kiwisolver==1.4.5
|
38 |
+
lazy_loader==0.3
|
39 |
+
markdown-it-py==3.0.0
|
40 |
+
MarkupSafe==2.1.4
|
41 |
+
matplotlib==3.8.2
|
42 |
+
mdurl==0.1.2
|
43 |
+
mpmath==1.3.0
|
44 |
+
networkx==3.2.1
|
45 |
+
numpy==1.26.3
|
46 |
+
onnx==1.15.0
|
47 |
+
onnxruntime==1.17.0
|
48 |
+
opencv-python==4.9.0.80
|
49 |
+
opencv-python-headless==4.9.0.80
|
50 |
+
orjson==3.9.12
|
51 |
+
packaging==23.2
|
52 |
+
pandas==2.2.0
|
53 |
+
pillow==10.2.0
|
54 |
+
prettytable==3.9.0
|
55 |
+
protobuf==4.25.2
|
56 |
+
pyasn1==0.5.1
|
57 |
+
pydantic==2.6.0
|
58 |
+
pydantic_core==2.16.1
|
59 |
+
pydub==0.25.1
|
60 |
+
Pygments==2.17.2
|
61 |
+
pyparsing==3.1.1
|
62 |
+
python-dateutil==2.8.2
|
63 |
+
python-multipart==0.0.6
|
64 |
+
pytz==2023.4
|
65 |
+
PyYAML==6.0.1
|
66 |
+
qudida==0.0.4
|
67 |
+
referencing==0.33.0
|
68 |
+
requests==2.31.0
|
69 |
+
rich==13.7.0
|
70 |
+
rpds-py==0.17.1
|
71 |
+
rsa==4.9
|
72 |
+
ruff==0.1.15
|
73 |
+
scikit-image==0.22.0
|
74 |
+
scikit-learn==1.4.0
|
75 |
+
scipy==1.12.0
|
76 |
+
semantic-version==2.10.0
|
77 |
+
shellingham==1.5.4
|
78 |
+
six==1.16.0
|
79 |
+
sniffio==1.3.0
|
80 |
+
starlette==0.35.1
|
81 |
+
sympy==1.12
|
82 |
+
threadpoolctl==3.2.0
|
83 |
+
tifffile==2024.1.30
|
84 |
+
tomlkit==0.12.0
|
85 |
+
toolz==0.12.1
|
86 |
+
tqdm==4.66.1
|
87 |
+
typer==0.9.0
|
88 |
+
typing_extensions==4.9.0
|
89 |
+
tzdata==2023.4
|
90 |
+
urllib3==2.2.0
|
91 |
+
uvicorn==0.27.0.post1
|
92 |
+
wcwidth==0.2.13
|
93 |
+
websockets==11.0.3
|