Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
6dee816
1
Parent(s):
8b7bf00
Handle blending correctly
Browse files
app.py
CHANGED
@@ -54,10 +54,6 @@ CONFIG_FILE = 'GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py'
|
|
54 |
GROUNDINGDINO_CHECKPOINT = "groundingdino_swint_ogc.pth"
|
55 |
SAM_CHECKPOINT = 'sam_hq_vit_l.pth'
|
56 |
OUTPUT_DIR = "outputs"
|
57 |
-
# FAL_KEY = os.getenv("FAL_KEY")
|
58 |
-
# UPLOAD_DIR = "./tmp/images"
|
59 |
-
|
60 |
-
# os.makedirs(UPLOAD_DIR, exist_ok=True)
|
61 |
|
62 |
# Global variables for model caching
|
63 |
_models = {
|
@@ -364,8 +360,21 @@ def expand_mask(mask, expand, tapered_corners):
|
|
364 |
return Image.fromarray(mask_np, mode="L")
|
365 |
|
366 |
def image_blend_by_mask(image_a, image_b, mask, blend_percentage):
|
367 |
-
|
368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
|
370 |
# Mask image
|
371 |
masked_img = Image.composite(image_a, image_b, mask)
|
@@ -585,8 +594,6 @@ def generate_image(input_image_path, prompt):
|
|
585 |
|
586 |
resized_input_img = resize_to_square(input_image_path, 512)
|
587 |
|
588 |
-
# resized_input_img_path = resized_input_img.save('input_img.png')
|
589 |
-
|
590 |
resized_input_img_path = '/tmp/gradio/resized_input_img.png'
|
591 |
|
592 |
resized_input_img.convert("RGBA").save(resized_input_img_path, "PNG")
|
@@ -597,8 +604,6 @@ def generate_image(input_image_path, prompt):
|
|
597 |
|
598 |
final_image = blend_details(resized_input_img, ai_gen_image, mask_input_image)
|
599 |
|
600 |
-
# final_image = ai_gen_image
|
601 |
-
|
602 |
return final_image
|
603 |
|
604 |
def create_ui():
|
|
|
54 |
GROUNDINGDINO_CHECKPOINT = "groundingdino_swint_ogc.pth"
|
55 |
SAM_CHECKPOINT = 'sam_hq_vit_l.pth'
|
56 |
OUTPUT_DIR = "outputs"
|
|
|
|
|
|
|
|
|
57 |
|
58 |
# Global variables for model caching
|
59 |
_models = {
|
|
|
360 |
return Image.fromarray(mask_np, mode="L")
|
361 |
|
362 |
def image_blend_by_mask(image_a, image_b, mask, blend_percentage):
|
363 |
+
# Ensure images have the same size and mode
|
364 |
+
image_a = image_a.convert('RGB')
|
365 |
+
image_b = image_b.convert('RGB')
|
366 |
+
mask = mask.convert('L')
|
367 |
+
|
368 |
+
# Resize images if they don't match
|
369 |
+
if image_a.size != image_b.size:
|
370 |
+
image_b = image_b.resize(image_a.size, Image.LANCZOS)
|
371 |
+
|
372 |
+
# Ensure mask has the same size
|
373 |
+
if mask.size != image_a.size:
|
374 |
+
mask = mask.resize(image_a.size, Image.LANCZOS)
|
375 |
+
|
376 |
+
# Invert mask
|
377 |
+
mask = ImageOps.invert(mask)
|
378 |
|
379 |
# Mask image
|
380 |
masked_img = Image.composite(image_a, image_b, mask)
|
|
|
594 |
|
595 |
resized_input_img = resize_to_square(input_image_path, 512)
|
596 |
|
|
|
|
|
597 |
resized_input_img_path = '/tmp/gradio/resized_input_img.png'
|
598 |
|
599 |
resized_input_img.convert("RGBA").save(resized_input_img_path, "PNG")
|
|
|
604 |
|
605 |
final_image = blend_details(resized_input_img, ai_gen_image, mask_input_image)
|
606 |
|
|
|
|
|
607 |
return final_image
|
608 |
|
609 |
def create_ui():
|