Spaces:
Running
on
Zero
Running
on
Zero
Avoid `IndexError` when no face is detected
#5
by
cbensimon
HF staff
- opened
app.py
CHANGED
@@ -55,9 +55,11 @@ def generate_image(images, prompt, negative_prompt, preserve_face_structure, fac
|
|
55 |
|
56 |
faceid_all_embeds = []
|
57 |
first_iteration = True
|
58 |
-
for image in images:
|
59 |
face = cv2.imread(image)
|
60 |
faces = app.get(face)
|
|
|
|
|
61 |
faceid_embed = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
|
62 |
faceid_all_embeds.append(faceid_embed)
|
63 |
if(first_iteration and preserve_face_structure):
|
|
|
55 |
|
56 |
faceid_all_embeds = []
|
57 |
first_iteration = True
|
58 |
+
for i, image in enumerate(images):
|
59 |
face = cv2.imread(image)
|
60 |
faces = app.get(face)
|
61 |
+
if len(faces) == 0:
|
62 |
+
raise gr.Error(f"No face detected in image number {i+1}")
|
63 |
faceid_embed = torch.from_numpy(faces[0].normed_embedding).unsqueeze(0)
|
64 |
faceid_all_embeds.append(faceid_embed)
|
65 |
if(first_iteration and preserve_face_structure):
|