jbilcke-hf commited on
Commit
aabf6ef
Β·
verified Β·
1 Parent(s): 051aa5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -19
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, input_image, text_prompt, box_threshold, text_threshold,
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 [], gr.Gallery.update(label='Detection prompt is not found!πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚')
517
 
518
- if input_image is None:
519
- return [], gr.Gallery.update(label='Please upload a image!πŸ˜‚πŸ˜‚πŸ˜‚πŸ˜‚')
520
 
521
  file_temp = int(time.time())
522
 
523
  output_images = []
524
 
525
  # load image
526
-
527
- if isinstance(input_image, dict):
528
- image_pil, image = load_image(input_image['image'].convert("RGB"))
529
- input_img = input_image['image']
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(input_img)
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
- input_image = gr.Textbox()
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
- input_image,
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,