Spaces:
Sleeping
Sleeping
liuyizhang
commited on
Commit
•
e94be43
1
Parent(s):
abcd303
update app.py
Browse files
app.py
CHANGED
@@ -62,6 +62,11 @@ from utils import computer_info
|
|
62 |
from ram_utils import iou, sort_and_deduplicate, relation_classes, MLP, show_anns, ram_show_mask
|
63 |
from ram_train_eval import RamModel,RamPredictor
|
64 |
from mmengine.config import Config as mmengine_Config
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
config_file = 'GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py'
|
67 |
ckpt_repo_id = "ShilongLiu/GroundingDINO"
|
@@ -126,14 +131,19 @@ def plot_boxes_to_image(image_pil, tgt):
|
|
126 |
bbox = (x0, y0, w + x0, y0 + h)
|
127 |
# bbox = draw.textbbox((x0, y0), str(label))
|
128 |
draw.rectangle(bbox, fill=color)
|
129 |
-
font = os.path.join(cv2.__path__[0],'qt','fonts','DejaVuSans.ttf')
|
130 |
-
font_size = 36
|
131 |
-
new_font = ImageFont.truetype(font, font_size)
|
132 |
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
mask_draw.rectangle([x0, y0, x1, y1], fill=255, width=6)
|
136 |
|
|
|
137 |
return image_pil, mask
|
138 |
|
139 |
def load_image(image_path):
|
@@ -282,11 +292,6 @@ def load_lama_cleaner_model():
|
|
282 |
# initialize lama_cleaner
|
283 |
global lama_cleaner_model
|
284 |
logger.info(f"initialize lama_cleaner...")
|
285 |
-
from lama_cleaner.helper import (
|
286 |
-
load_img,
|
287 |
-
numpy_to_bytes,
|
288 |
-
resize_max_size,
|
289 |
-
)
|
290 |
|
291 |
lama_cleaner_model = ModelManager(
|
292 |
name='lama',
|
@@ -522,16 +527,25 @@ def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_t
|
|
522 |
file_temp = int(time.time())
|
523 |
logger.info(f'run_anything_task_[{file_temp}]_{task_type}/{inpaint_mode}/[{mask_source_radio}]/{remove_mode}/{remove_mask_extend}_[{text_prompt}]/[{inpaint_prompt}]___1_')
|
524 |
|
|
|
|
|
525 |
# load image
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
530 |
|
531 |
size = image_pil.size
|
532 |
-
|
533 |
-
output_images = []
|
534 |
-
output_images.append(input_image['image'])
|
535 |
# run grounding dino model
|
536 |
if (task_type == 'inpainting' or task_type == 'remove') and mask_source_radio == mask_source_draw:
|
537 |
pass
|
@@ -557,12 +571,13 @@ def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_t
|
|
557 |
"size": [size[1], size[0]], # H,W
|
558 |
"labels": pred_phrases,
|
559 |
}
|
|
|
560 |
image_with_box = plot_boxes_to_image(copy.deepcopy(image_pil), pred_dict)[0]
|
561 |
output_images.append(image_with_box)
|
562 |
|
563 |
logger.info(f'run_anything_task_[{file_temp}]_{task_type}_2_')
|
564 |
if task_type == 'segment' or ((task_type == 'inpainting' or task_type == 'remove') and mask_source_radio == mask_source_segment):
|
565 |
-
image = np.array(
|
566 |
sam_predictor.set_image(image)
|
567 |
|
568 |
H, W = size[1], size[0]
|
|
|
62 |
from ram_utils import iou, sort_and_deduplicate, relation_classes, MLP, show_anns, ram_show_mask
|
63 |
from ram_train_eval import RamModel,RamPredictor
|
64 |
from mmengine.config import Config as mmengine_Config
|
65 |
+
from lama_cleaner.helper import (
|
66 |
+
load_img,
|
67 |
+
numpy_to_bytes,
|
68 |
+
resize_max_size,
|
69 |
+
)
|
70 |
|
71 |
config_file = 'GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py'
|
72 |
ckpt_repo_id = "ShilongLiu/GroundingDINO"
|
|
|
131 |
bbox = (x0, y0, w + x0, y0 + h)
|
132 |
# bbox = draw.textbbox((x0, y0), str(label))
|
133 |
draw.rectangle(bbox, fill=color)
|
|
|
|
|
|
|
134 |
|
135 |
+
try:
|
136 |
+
font = os.path.join(cv2.__path__[0],'qt','fonts','DejaVuSans.ttf')
|
137 |
+
font_size = 36
|
138 |
+
new_font = ImageFont.truetype(font, font_size)
|
139 |
+
|
140 |
+
draw.text((x0+2, y0+2), str(label), font=new_font, fill="white")
|
141 |
+
except Exception as e:
|
142 |
+
pass
|
143 |
|
144 |
mask_draw.rectangle([x0, y0, x1, y1], fill=255, width=6)
|
145 |
|
146 |
+
|
147 |
return image_pil, mask
|
148 |
|
149 |
def load_image(image_path):
|
|
|
292 |
# initialize lama_cleaner
|
293 |
global lama_cleaner_model
|
294 |
logger.info(f"initialize lama_cleaner...")
|
|
|
|
|
|
|
|
|
|
|
295 |
|
296 |
lama_cleaner_model = ModelManager(
|
297 |
name='lama',
|
|
|
527 |
file_temp = int(time.time())
|
528 |
logger.info(f'run_anything_task_[{file_temp}]_{task_type}/{inpaint_mode}/[{mask_source_radio}]/{remove_mode}/{remove_mask_extend}_[{text_prompt}]/[{inpaint_prompt}]___1_')
|
529 |
|
530 |
+
output_images = []
|
531 |
+
|
532 |
# load image
|
533 |
+
if mask_source_radio == mask_source_draw:
|
534 |
+
input_mask_pil = input_image['mask']
|
535 |
+
input_mask = np.array(input_mask_pil.convert("L"))
|
536 |
+
|
537 |
+
print(type(input_image))
|
538 |
+
if isinstance(input_image, list):
|
539 |
+
image_pil, image = load_image(input_image['image'].convert("RGB"))
|
540 |
+
input_img = input_image['image']
|
541 |
+
output_images.append(input_image['image'])
|
542 |
+
else:
|
543 |
+
image_pil, image = load_image(input_image.convert("RGB"))
|
544 |
+
input_img = input_image
|
545 |
+
output_images.append(input_image)
|
546 |
|
547 |
size = image_pil.size
|
548 |
+
|
|
|
|
|
549 |
# run grounding dino model
|
550 |
if (task_type == 'inpainting' or task_type == 'remove') and mask_source_radio == mask_source_draw:
|
551 |
pass
|
|
|
571 |
"size": [size[1], size[0]], # H,W
|
572 |
"labels": pred_phrases,
|
573 |
}
|
574 |
+
|
575 |
image_with_box = plot_boxes_to_image(copy.deepcopy(image_pil), pred_dict)[0]
|
576 |
output_images.append(image_with_box)
|
577 |
|
578 |
logger.info(f'run_anything_task_[{file_temp}]_{task_type}_2_')
|
579 |
if task_type == 'segment' or ((task_type == 'inpainting' or task_type == 'remove') and mask_source_radio == mask_source_segment):
|
580 |
+
image = np.array(input_img)
|
581 |
sam_predictor.set_image(image)
|
582 |
|
583 |
H, W = size[1], size[0]
|