Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,10 @@ warnings.filterwarnings('ignore')
|
|
4 |
|
5 |
import subprocess, io, os, sys, time
|
6 |
|
7 |
-
# os.system("pip install -q gradio==3.48.0")
|
8 |
os.system("pip install -q gradio")
|
9 |
os.system("pip install -q diffusers")
|
10 |
os.system("pip install -q segment_anything")
|
11 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
12 |
|
13 |
result = subprocess.run(['pip', 'install', '-e', 'GroundingDINO'], check=True)
|
14 |
print(f'pip install GroundingDINO = {result}')
|
@@ -84,7 +83,7 @@ class CFG:
|
|
84 |
"vit_l": "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth",
|
85 |
"vit_b": "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth"
|
86 |
}
|
87 |
-
device = 'cuda'
|
88 |
ckpt_repo_id = "ShilongLiu/GroundingDINO"
|
89 |
ckpt_filename = "groundingdino_swinb_cogcoor.pth"
|
90 |
ckpt_config_filename = "GroundingDINO_SwinB.cfg.py"
|
@@ -251,147 +250,6 @@ def main_fun(image_pil, x_units, y_units, text_prompt):
|
|
251 |
|
252 |
import gradio as gr
|
253 |
|
254 |
-
# with gr.Blocks() as demo:
|
255 |
-
# gr.Markdown("Segmentation and shift")
|
256 |
-
# with gr.Tab("Txt2Img"):
|
257 |
-
# with gr.Row():
|
258 |
-
# with gr.Column(scale=1):
|
259 |
-
# # image_pil, x_units, y_units, text_prompt
|
260 |
-
|
261 |
-
# text_prompt = gr.Textbox(lines=1, label="Prompt")
|
262 |
-
# image_pil = gr.Image(type="filepath", label='Image')
|
263 |
-
# # negative_prompt = gr.Textbox(lines=1, label="Negative Prompt")
|
264 |
-
# # width = gr.Dropdown(choices=number_choices, value=704, label="Width")
|
265 |
-
# # height = gr.Dropdown(choices=number_choicess, value=408, label="Height")
|
266 |
-
# x_units = gr.Slider(minimum=50, maximum=300, step=1, value=10, label="x_units")
|
267 |
-
# y_units = gr.Slider(minimum=30, maximum=300, step=0.1, value=5, label="y_units")
|
268 |
-
# # seed = gr.Textbox(label="Seed (Leave empty for random seed)")
|
269 |
-
# with gr.Column(scale=2):
|
270 |
-
# output = gr.Image(type="pil", label="Output Image")
|
271 |
-
# # generate = gr.Button("Generate")
|
272 |
-
# # output_seed = gr.Textbox(label="Current Seed")
|
273 |
-
|
274 |
-
# # Create the txt2img function
|
275 |
-
|
276 |
-
# # generate.click(fn=main_fun, inputs=[image_pil, x_units, y_units, text_prompt], outputs=[output_image])
|
277 |
-
|
278 |
-
# x_units = gr.Slider(minimum=50, maximum=300, step=1, value=10, label="x_units")
|
279 |
-
# y_units = gr.Slider(minimum=30, maximum=300, step=0.1, value=5, label="y_units")
|
280 |
-
# text_prompt = gr.Textbox(lines=1, label="Prompt")
|
281 |
-
# image_pil = gr.components.Image(type="filepath", label="Input Image")
|
282 |
-
# output = gr.components.Image(type="numpy", label="Output Image")
|
283 |
-
|
284 |
-
# # Launch the Gradio UI
|
285 |
-
# gr.Interface(fn=main_fun, inputs=[image_pil, x_units, y_units, text_prompt], outputs=[output]).launch(share=True, debug=True)
|
286 |
-
|
287 |
-
|
288 |
-
# block = gr.Blocks().queue()
|
289 |
-
# with block:
|
290 |
-
# with gr.Row():
|
291 |
-
# with gr.Column():
|
292 |
-
# # task_types = ["detection"]
|
293 |
-
# # if sam_enable:
|
294 |
-
# # task_types.append("segment")
|
295 |
-
# # if inpainting_enable:
|
296 |
-
# # task_types.append("inpainting")
|
297 |
-
# # task_types.append("outpainting")
|
298 |
-
# # if lama_cleaner_enable:
|
299 |
-
# # task_types.append("remove")
|
300 |
-
# # if ram_enable:
|
301 |
-
# # task_types.append("relate anything")
|
302 |
-
# # if kosmos_enable:
|
303 |
-
# # task_types.append("Kosmos-2")
|
304 |
-
|
305 |
-
# input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload",
|
306 |
-
# height=512, brush_color='#00FFFF', mask_opacity=0.6)
|
307 |
-
# # task_type = gr.Radio(task_types, value="detection",
|
308 |
-
# # label='Task type', visible=True)
|
309 |
-
# # mask_source_radio = gr.Radio([mask_source_draw, mask_source_segment],
|
310 |
-
# # value=mask_source_segment, label="Mask from",
|
311 |
-
# # visible=False)
|
312 |
-
# x_units = gr.Slider(minimum=50, maximum=300, step=1, value=10, label="x_units")
|
313 |
-
# y_units = gr.Slider(minimum=30, maximum=300, step=0.1, value=5, label="y_units")
|
314 |
-
# text_prompt = gr.Textbox(lines=1, label="Prompt")
|
315 |
-
# # image_pil = gr.components.Image(type="filepath", label="Input Image")
|
316 |
-
# # output = gr.components.Image(type="numpy", label="Output Image")
|
317 |
-
|
318 |
-
# run_button = gr.Button(label="Run", visible=True)
|
319 |
-
# # with gr.Accordion("Advanced options", open=False) as advanced_options:
|
320 |
-
# # box_threshold = gr.Slider(
|
321 |
-
# # label="Box Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.001
|
322 |
-
# # )
|
323 |
-
# # text_threshold = gr.Slider(
|
324 |
-
# # label="Text Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001
|
325 |
-
# # )
|
326 |
-
# # iou_threshold = gr.Slider(
|
327 |
-
# # label="IOU Threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.001
|
328 |
-
# # )
|
329 |
-
# # inpaint_mode = gr.Radio(["merge", "first"], value="merge", label="inpaint_mode")
|
330 |
-
# # with gr.Row():
|
331 |
-
# # with gr.Column(scale=1):
|
332 |
-
# # remove_mode = gr.Radio(["segment", "rectangle"], value="segment", label='remove mode')
|
333 |
-
# # with gr.Column(scale=1):
|
334 |
-
# # remove_mask_extend = gr.Textbox(label="remove_mask_extend", value='10')
|
335 |
-
|
336 |
-
# with gr.Column():
|
337 |
-
# image_gallery = gr.Gallery(label="result images", show_label=True, elem_id="gallery", height=512, visible=True
|
338 |
-
# ).style(preview=True, columns=[5], object_fit="scale-down", height="auto")
|
339 |
-
# # time_cost = gr.Textbox(label="Time cost by step (ms):", visible=False, interactive=False)
|
340 |
-
|
341 |
-
# # kosmos_output = gr.Image(type="pil", label="result images", visible=False)
|
342 |
-
# # kosmos_text_output = gr.HighlightedText(
|
343 |
-
# # label="Generated Description",
|
344 |
-
# # combine_adjacent=False,
|
345 |
-
# # show_legend=True,
|
346 |
-
# # visible=False,
|
347 |
-
# # ).style(color_map=color_map)
|
348 |
-
# # # record which text span (label) is selected
|
349 |
-
# # selected = gr.Number(-1, show_label=False, placeholder="Selected", visible=False)
|
350 |
-
|
351 |
-
# # # record the current `entities`
|
352 |
-
# # entity_output = gr.Textbox(visible=False)
|
353 |
-
|
354 |
-
# # # get the current selected span label
|
355 |
-
# # def get_text_span_label(evt: gr.SelectData):
|
356 |
-
# # if evt.value[-1] is None:
|
357 |
-
# # return -1
|
358 |
-
# # return int(evt.value[-1])
|
359 |
-
# # # and set this information to `selected`
|
360 |
-
# # kosmos_text_output.select(get_text_span_label, None, selected)
|
361 |
-
|
362 |
-
# # update output image when we change the span (enity) selection
|
363 |
-
# # def update_output_image(img_input, image_output, entities, idx):
|
364 |
-
# # entities = ast.literal_eval(entities)
|
365 |
-
# # updated_image = draw_entity_boxes_on_image(img_input, entities, entity_index=idx)
|
366 |
-
# # return updated_image
|
367 |
-
# # selected.change(update_output_image, [kosmos_output, kosmos_output, entity_output, selected], [kosmos_output])
|
368 |
-
|
369 |
-
# run_button.click(fn=main_fun, inputs=[image_pil, x_units, y_units, text_prompt], outputs=[image_gallery], show_progress=True, queue=True)
|
370 |
-
|
371 |
-
# # mask_source_radio.change(fn=change_radio_display, inputs=[task_type, mask_source_radio],
|
372 |
-
# # outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation])
|
373 |
-
# # task_type.change(fn=change_radio_display, inputs=[task_type, mask_source_radio],
|
374 |
-
# # outputs=[text_prompt, inpaint_prompt, mask_source_radio, num_relation,
|
375 |
-
# # image_gallery, kosmos_input, kosmos_output, kosmos_text_output
|
376 |
-
# # ])
|
377 |
-
|
378 |
-
# # DESCRIPTION = f'### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
|
379 |
-
# # if lama_cleaner_enable:
|
380 |
-
# # DESCRIPTION += f'Remove(cleaner) from [lama-cleaner](https://github.com/Sanster/lama-cleaner). <br>'
|
381 |
-
# # if kosmos_enable:
|
382 |
-
# # DESCRIPTION += f'Kosmos-2 from [Kosmos-2](https://github.com/microsoft/unilm/tree/master/kosmos-2). <br>'
|
383 |
-
# # if ram_enable:
|
384 |
-
# # DESCRIPTION += f'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
|
385 |
-
# # DESCRIPTION += f'Thanks for their excellent work.'
|
386 |
-
# # DESCRIPTION += f'<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. \
|
387 |
-
# # <a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
388 |
-
# # gr.Markdown(DESCRIPTION)
|
389 |
-
|
390 |
-
# # print(f'device = {device}')
|
391 |
-
# # print(f'torch.cuda.is_available = {torch.cuda.is_available()}')
|
392 |
-
# # computer_info()
|
393 |
-
# block.launch(server_name='0.0.0.0')
|
394 |
-
|
395 |
|
396 |
image_blocks = gr.Blocks()
|
397 |
with image_blocks as demo:
|
|
|
4 |
|
5 |
import subprocess, io, os, sys, time
|
6 |
|
|
|
7 |
os.system("pip install -q gradio")
|
8 |
os.system("pip install -q diffusers")
|
9 |
os.system("pip install -q segment_anything")
|
10 |
+
# os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
11 |
|
12 |
result = subprocess.run(['pip', 'install', '-e', 'GroundingDINO'], check=True)
|
13 |
print(f'pip install GroundingDINO = {result}')
|
|
|
83 |
"vit_l": "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth",
|
84 |
"vit_b": "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth"
|
85 |
}
|
86 |
+
device = 'cuda' if cuda.is_available() else 'cpu'
|
87 |
ckpt_repo_id = "ShilongLiu/GroundingDINO"
|
88 |
ckpt_filename = "groundingdino_swinb_cogcoor.pth"
|
89 |
ckpt_config_filename = "GroundingDINO_SwinB.cfg.py"
|
|
|
250 |
|
251 |
import gradio as gr
|
252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
image_blocks = gr.Blocks()
|
255 |
with image_blocks as demo:
|