Spaces:
Running
Running
sandrocalzada
commited on
Commit
•
59057f1
1
Parent(s):
fdc2c6f
Update app.py
Browse files
app.py
CHANGED
@@ -19,32 +19,27 @@ swapper = insightface.model_zoo.get_model('inswapper_128.onnx')
|
|
19 |
|
20 |
|
21 |
def swapi(imagen):
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
else:
|
26 |
-
img = np.array(imagen)
|
27 |
|
28 |
-
|
29 |
-
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
bbox = [int(b) for b in bbox]
|
42 |
|
43 |
-
|
44 |
-
for face in faces:
|
45 |
-
res = swapper.get(res, face, source_face, paste_back=True)
|
46 |
|
47 |
-
return res
|
48 |
|
49 |
|
50 |
with gr.Blocks() as blocks:
|
|
|
19 |
|
20 |
|
21 |
def swapi(imagen):
|
22 |
+
# Use the uploaded image to extract features
|
23 |
+
img_user = cv2.imread(imagen)
|
24 |
+
faces_user = app.get(img_user)
|
|
|
|
|
25 |
|
26 |
+
# Use another image "background1" for modifications
|
27 |
+
img_background = cv2.imread('background1.jpg')
|
28 |
+
faces_background = app.get(img_background)
|
29 |
|
30 |
+
# Assuming the user image has a face and we are using its features
|
31 |
+
source_face = faces_user[0]
|
32 |
|
33 |
+
# Apply modifications to the "background1" image
|
34 |
+
res = img_background.copy()
|
35 |
+
for face in faces_background:
|
36 |
+
res = swapper.get(res, face, source_face, paste_back=True)
|
37 |
|
38 |
+
# Convert from BGR to RGB
|
39 |
+
res_rgb = cv2.cvtColor(res, cv2.COLOR_BGR2RGB)
|
|
|
40 |
|
41 |
+
return res_rgb
|
|
|
|
|
42 |
|
|
|
43 |
|
44 |
|
45 |
with gr.Blocks() as blocks:
|