Spaces:
Running
on
T4
Running
on
T4
liuyizhang
commited on
Commit
•
5d0da89
1
Parent(s):
6e4c9f7
update app.py
Browse files
app.py
CHANGED
@@ -54,14 +54,6 @@ from io import BytesIO
|
|
54 |
from diffusers import StableDiffusionInpaintPipeline
|
55 |
from huggingface_hub import hf_hub_download
|
56 |
|
57 |
-
def get_device():
|
58 |
-
from numba import cuda
|
59 |
-
if cuda.is_available():
|
60 |
-
device = 'cuda:0' # cuda.get_current_device()
|
61 |
-
else:
|
62 |
-
device = 'cpu'
|
63 |
-
return device
|
64 |
-
|
65 |
def load_model_hf(model_config_path, repo_id, filename, device='cpu'):
|
66 |
args = SLConfig.fromfile(model_config_path)
|
67 |
model = build_model(args)
|
@@ -108,7 +100,11 @@ def plot_boxes_to_image(image_pil, tgt):
|
|
108 |
bbox = (x0, y0, w + x0, y0 + h)
|
109 |
# bbox = draw.textbbox((x0, y0), str(label))
|
110 |
draw.rectangle(bbox, fill=color)
|
111 |
-
|
|
|
|
|
|
|
|
|
112 |
|
113 |
mask_draw.rectangle([x0, y0, x1, y1], fill=255, width=6)
|
114 |
|
@@ -228,9 +224,8 @@ ckpt_repo_id = "ShilongLiu/GroundingDINO"
|
|
228 |
ckpt_filenmae = "groundingdino_swint_ogc.pth"
|
229 |
sam_checkpoint = './sam_vit_h_4b8939.pth'
|
230 |
output_dir = "outputs"
|
231 |
-
device =
|
232 |
|
233 |
-
device = get_device()
|
234 |
print(f'device={device}')
|
235 |
|
236 |
# make dir
|
@@ -540,13 +535,13 @@ if __name__ == "__main__":
|
|
540 |
run_button = gr.Button(label="Run")
|
541 |
with gr.Accordion("Advanced options", open=False):
|
542 |
box_threshold = gr.Slider(
|
543 |
-
label="Box Threshold", minimum=0.0, maximum=1.0, value=0.
|
544 |
)
|
545 |
text_threshold = gr.Slider(
|
546 |
-
label="Text Threshold", minimum=0.0, maximum=1.0, value=0.
|
547 |
)
|
548 |
iou_threshold = gr.Slider(
|
549 |
-
label="IOU Threshold", minimum=0.0, maximum=1.0, value=0.
|
550 |
)
|
551 |
inpaint_mode = gr.Radio(["merge", "first"], value="merge", label="inpaint_mode")
|
552 |
with gr.Row():
|
|
|
54 |
from diffusers import StableDiffusionInpaintPipeline
|
55 |
from huggingface_hub import hf_hub_download
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
def load_model_hf(model_config_path, repo_id, filename, device='cpu'):
|
58 |
args = SLConfig.fromfile(model_config_path)
|
59 |
model = build_model(args)
|
|
|
100 |
bbox = (x0, y0, w + x0, y0 + h)
|
101 |
# bbox = draw.textbbox((x0, y0), str(label))
|
102 |
draw.rectangle(bbox, fill=color)
|
103 |
+
font = os.path.join(cv2.__path__[0],'qt','fonts','DejaVuSans.ttf')
|
104 |
+
font_size = 36
|
105 |
+
new_font = ImageFont.truetype(font, font_size)
|
106 |
+
|
107 |
+
draw.text((x0+2, y0+2), str(label), font=new_font, fill="white")
|
108 |
|
109 |
mask_draw.rectangle([x0, y0, x1, y1], fill=255, width=6)
|
110 |
|
|
|
224 |
ckpt_filenmae = "groundingdino_swint_ogc.pth"
|
225 |
sam_checkpoint = './sam_vit_h_4b8939.pth'
|
226 |
output_dir = "outputs"
|
227 |
+
device = evice = 'cuda' if torch.cuda.is_available() else 'cpu'
|
228 |
|
|
|
229 |
print(f'device={device}')
|
230 |
|
231 |
# make dir
|
|
|
535 |
run_button = gr.Button(label="Run")
|
536 |
with gr.Accordion("Advanced options", open=False):
|
537 |
box_threshold = gr.Slider(
|
538 |
+
label="Box Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.001
|
539 |
)
|
540 |
text_threshold = gr.Slider(
|
541 |
+
label="Text Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001
|
542 |
)
|
543 |
iou_threshold = gr.Slider(
|
544 |
+
label="IOU Threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.001
|
545 |
)
|
546 |
inpaint_mode = gr.Radio(["merge", "first"], value="merge", label="inpaint_mode")
|
547 |
with gr.Row():
|