Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -25,6 +25,33 @@ app = FaceAnalysis(name='buffalo_l')
|
|
25 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
26 |
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def greet(description,color,features,occasion,type_):
|
30 |
|
|
|
25 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
26 |
|
27 |
|
28 |
+
def face_swap(dest_img):
|
29 |
+
|
30 |
+
# Convert to RGB
|
31 |
+
src_img = src_img.convert(mode='RGB')
|
32 |
+
dest_img = dest_img.convert(mode='RGB')
|
33 |
+
|
34 |
+
# Convert to array
|
35 |
+
src_img_arr = np.asarray(src_img)
|
36 |
+
dest_img_arr = np.asarray(dest_img)
|
37 |
+
|
38 |
+
# Face detection
|
39 |
+
src_faces = app.get(src_img_arr)
|
40 |
+
dest_faces = app.get(dest_img_arr)
|
41 |
+
|
42 |
+
# Initialize swapper
|
43 |
+
swapper = insightface.model_zoo.get_model('inswapper_128.onnx', download=False, download_zip=False)
|
44 |
+
|
45 |
+
# Swap face
|
46 |
+
res = dest_img_arr.copy()
|
47 |
+
for face in dest_faces:
|
48 |
+
res = swapper.get(res, face, src_faces[0], paste_back=True)
|
49 |
+
|
50 |
+
# Convert to PIL image
|
51 |
+
final_image = Image.fromarray(np.uint8(res)).convert('RGB')
|
52 |
+
|
53 |
+
return final_image
|
54 |
+
|
55 |
|
56 |
def greet(description,color,features,occasion,type_):
|
57 |
|