Masaaki Kawata
commited on
Commit
Β·
841bf25
1
Parent(s):
75bd3a8
Update parallax.py
Browse files- parallax.py +17 -17
parallax.py
CHANGED
|
@@ -368,22 +368,7 @@ def convert_webp(image: Image.Image) -> str:
|
|
| 368 |
def generate_animation_images(image, prompts=['make the eyes half-closed evenly; keep identity and all other details unchanged', 'make the eyes closed; keep identity and all other details unchanged'], target_size=1024, frame=None):
|
| 369 |
rgba = np.asarray(image)
|
| 370 |
face_results = FACE_YOLO.predict(source=Image.fromarray(np.asarray(Image.alpha_composite(Image.new('RGBA', image.size, (0, 0, 0)), image))[:, :, :3]), conf=0.5, iou=0.45, verbose=False, device='0' if torch.cuda.is_available() else 'cpu')
|
| 371 |
-
edited_outputs = []
|
| 372 |
edited_images = []
|
| 373 |
-
filtered_prompts = []
|
| 374 |
-
|
| 375 |
-
if frame is None:
|
| 376 |
-
for prompt in prompts:
|
| 377 |
-
filtered_prompts.append(prompt)
|
| 378 |
-
edited_outputs.append(rgba.copy())
|
| 379 |
-
|
| 380 |
-
else:
|
| 381 |
-
for index, prompt in enumerate(prompts):
|
| 382 |
-
if frame == index:
|
| 383 |
-
filtered_prompts.append(prompt)
|
| 384 |
-
edited_outputs.append(rgba.copy())
|
| 385 |
-
|
| 386 |
-
break
|
| 387 |
|
| 388 |
if len(face_results) > 0 and face_results[0].boxes is not None and len(face_results[0].boxes) > 0:
|
| 389 |
min_x = np.iinfo(np.int32).max
|
|
@@ -391,6 +376,21 @@ def generate_animation_images(image, prompts=['make the eyes half-closed evenly;
|
|
| 391 |
max_x = 0
|
| 392 |
max_y = 0
|
| 393 |
boxes = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
|
| 395 |
for xyxy in np.round(face_results[0].boxes.xyxy.detach().cpu().numpy()).astype(np.int32):
|
| 396 |
min_x = min(min_x, xyxy[0])
|
|
@@ -421,8 +421,8 @@ def generate_animation_images(image, prompts=['make the eyes half-closed evenly;
|
|
| 421 |
for x1, y1, x2, y2 in boxes:
|
| 422 |
edited_outputs[index][y1:y2, x1:x2, :3] = edited_rgb[y1 - min_y:y2 - min_y, x1 - min_x:x2 - min_x, :]
|
| 423 |
|
| 424 |
-
|
| 425 |
-
|
| 426 |
|
| 427 |
return edited_images
|
| 428 |
|
|
|
|
| 368 |
def generate_animation_images(image, prompts=['make the eyes half-closed evenly; keep identity and all other details unchanged', 'make the eyes closed; keep identity and all other details unchanged'], target_size=1024, frame=None):
|
| 369 |
rgba = np.asarray(image)
|
| 370 |
face_results = FACE_YOLO.predict(source=Image.fromarray(np.asarray(Image.alpha_composite(Image.new('RGBA', image.size, (0, 0, 0)), image))[:, :, :3]), conf=0.5, iou=0.45, verbose=False, device='0' if torch.cuda.is_available() else 'cpu')
|
|
|
|
| 371 |
edited_images = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
|
| 373 |
if len(face_results) > 0 and face_results[0].boxes is not None and len(face_results[0].boxes) > 0:
|
| 374 |
min_x = np.iinfo(np.int32).max
|
|
|
|
| 376 |
max_x = 0
|
| 377 |
max_y = 0
|
| 378 |
boxes = []
|
| 379 |
+
filtered_prompts = []
|
| 380 |
+
edited_outputs = []
|
| 381 |
+
|
| 382 |
+
if frame is None:
|
| 383 |
+
for prompt in prompts:
|
| 384 |
+
filtered_prompts.append(prompt)
|
| 385 |
+
edited_outputs.append(rgba.copy())
|
| 386 |
+
|
| 387 |
+
else:
|
| 388 |
+
for index, prompt in enumerate(prompts):
|
| 389 |
+
if frame == index:
|
| 390 |
+
filtered_prompts.append(prompt)
|
| 391 |
+
edited_outputs.append(rgba.copy())
|
| 392 |
+
|
| 393 |
+
break
|
| 394 |
|
| 395 |
for xyxy in np.round(face_results[0].boxes.xyxy.detach().cpu().numpy()).astype(np.int32):
|
| 396 |
min_x = min(min_x, xyxy[0])
|
|
|
|
| 421 |
for x1, y1, x2, y2 in boxes:
|
| 422 |
edited_outputs[index][y1:y2, x1:x2, :3] = edited_rgb[y1 - min_y:y2 - min_y, x1 - min_x:x2 - min_x, :]
|
| 423 |
|
| 424 |
+
for edited_rgba in edited_outputs:
|
| 425 |
+
edited_images.append(convert_webp(Image.fromarray(edited_rgba, 'RGBA')))
|
| 426 |
|
| 427 |
return edited_images
|
| 428 |
|