Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -502,7 +502,7 @@ def concatenate_images_vertical(image1, image2):
|
|
| 502 |
mask_source_draw = "draw a mask on input image"
|
| 503 |
mask_source_segment = "type what to detect below"
|
| 504 |
|
| 505 |
-
def run_anything_task(secret_token,
|
| 506 |
iou_threshold, cleaner_size_limit=1080):
|
| 507 |
if secret_token != SECRET_TOKEN:
|
| 508 |
raise gr.Error(
|
|
@@ -513,28 +513,20 @@ def run_anything_task(secret_token, input_image, text_prompt, box_threshold, tex
|
|
| 513 |
text_prompt = text_prompt.strip()
|
| 514 |
if not ((task_type == 'inpainting' or task_type == 'remove') and mask_source_radio == mask_source_draw):
|
| 515 |
if text_prompt == '':
|
| 516 |
-
return
|
| 517 |
|
| 518 |
-
if
|
| 519 |
-
return
|
| 520 |
|
| 521 |
file_temp = int(time.time())
|
| 522 |
|
| 523 |
output_images = []
|
| 524 |
|
| 525 |
# load image
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
# no need to print back the input image
|
| 531 |
-
# output_images.append(input_image['image'])
|
| 532 |
-
else:
|
| 533 |
-
image_pil, image = load_image(input_image.convert("RGB"))
|
| 534 |
-
input_img = input_image
|
| 535 |
-
# no need to print back the input image
|
| 536 |
-
# output_images.append(input_image)
|
| 537 |
-
|
| 538 |
size = image_pil.size
|
| 539 |
|
| 540 |
# run grounding dino model
|
|
@@ -565,7 +557,7 @@ def run_anything_task(secret_token, input_image, text_prompt, box_threshold, tex
|
|
| 565 |
# output_images.append(image_with_box)
|
| 566 |
|
| 567 |
# now we generate the segmentation
|
| 568 |
-
image = np.array(
|
| 569 |
sam_predictor.set_image(image)
|
| 570 |
|
| 571 |
H, W = size[1], size[0]
|
|
@@ -658,7 +650,7 @@ if __name__ == "__main__":
|
|
| 658 |
|
| 659 |
secret_token = gr.Textbox()
|
| 660 |
text_prompt = gr.Textbox()
|
| 661 |
-
|
| 662 |
text_prompt = gr.Textbox(label="Detection Prompt[To detect multiple objects, seperating each name with '.', like this: cat . dog . chair ]", placeholder="Cannot be empty")
|
| 663 |
run_button = gr.Button(label="Run", visible=True)
|
| 664 |
with gr.Accordion("Advanced options", open=False) as advanced_options:
|
|
@@ -676,7 +668,7 @@ if __name__ == "__main__":
|
|
| 676 |
fn=run_anything_task,
|
| 677 |
inputs=[
|
| 678 |
secret_token,
|
| 679 |
-
|
| 680 |
text_prompt,
|
| 681 |
box_threshold,
|
| 682 |
text_threshold,
|
|
|
|
| 502 |
mask_source_draw = "draw a mask on input image"
|
| 503 |
mask_source_segment = "type what to detect below"
|
| 504 |
|
| 505 |
+
def run_anything_task(secret_token, input_image_b64, text_prompt, box_threshold, text_threshold,
|
| 506 |
iou_threshold, cleaner_size_limit=1080):
|
| 507 |
if secret_token != SECRET_TOKEN:
|
| 508 |
raise gr.Error(
|
|
|
|
| 513 |
text_prompt = text_prompt.strip()
|
| 514 |
if not ((task_type == 'inpainting' or task_type == 'remove') and mask_source_radio == mask_source_draw):
|
| 515 |
if text_prompt == '':
|
| 516 |
+
return ""
|
| 517 |
|
| 518 |
+
if input_image_b64 is None:
|
| 519 |
+
return ""
|
| 520 |
|
| 521 |
file_temp = int(time.time())
|
| 522 |
|
| 523 |
output_images = []
|
| 524 |
|
| 525 |
# load image
|
| 526 |
+
input_image = readb64(input_image_b64)
|
| 527 |
+
|
| 528 |
+
image_pil, image = load_image(input_image.convert("RGB"))
|
| 529 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
size = image_pil.size
|
| 531 |
|
| 532 |
# run grounding dino model
|
|
|
|
| 557 |
# output_images.append(image_with_box)
|
| 558 |
|
| 559 |
# now we generate the segmentation
|
| 560 |
+
image = np.array(input_image)
|
| 561 |
sam_predictor.set_image(image)
|
| 562 |
|
| 563 |
H, W = size[1], size[0]
|
|
|
|
| 650 |
|
| 651 |
secret_token = gr.Textbox()
|
| 652 |
text_prompt = gr.Textbox()
|
| 653 |
+
input_image_b64 = gr.Textbox()
|
| 654 |
text_prompt = gr.Textbox(label="Detection Prompt[To detect multiple objects, seperating each name with '.', like this: cat . dog . chair ]", placeholder="Cannot be empty")
|
| 655 |
run_button = gr.Button(label="Run", visible=True)
|
| 656 |
with gr.Accordion("Advanced options", open=False) as advanced_options:
|
|
|
|
| 668 |
fn=run_anything_task,
|
| 669 |
inputs=[
|
| 670 |
secret_token,
|
| 671 |
+
input_image_b64,
|
| 672 |
text_prompt,
|
| 673 |
box_threshold,
|
| 674 |
text_threshold,
|