jbilcke-hf commited on
Commit
b0d0b61
·
verified ·
1 Parent(s): 53c8802

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -9
app.py CHANGED
@@ -3,16 +3,17 @@ import warnings
3
  warnings.filterwarnings('ignore')
4
 
5
  import subprocess, io, os, sys, time
6
- os.system("pip install gradio==3.38.0")
7
  import gradio as gr
8
 
9
  from loguru import logger
10
 
 
11
  os.environ["CUDA_VISIBLE_DEVICES"] = "0"
12
 
13
- if os.environ.get('IS_MY_DEBUG') is None:
14
- result = subprocess.run(['pip', 'install', '-e', 'GroundingDINO'], check=True)
15
- print(f'pip install GroundingDINO = {result}')
16
 
17
  # result = subprocess.run(['pip', 'list'], check=True)
18
  # print(f'pip list = {result}')
@@ -63,6 +64,8 @@ from lama_cleaner.helper import (
63
  resize_max_size,
64
  )
65
 
 
 
66
  config_file = 'GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py'
67
  ckpt_repo_id = "ShilongLiu/GroundingDINO"
68
  ckpt_filenmae = "groundingdino_swint_ogc.pth"
@@ -604,12 +607,21 @@ if __name__ == "__main__":
604
  load_lama_cleaner_model()
605
  load_ram_model()
606
 
607
- os.system("pip list")
608
 
609
  block = gr.Blocks().queue()
610
  with block:
 
 
 
 
 
 
 
611
  with gr.Row():
612
  with gr.Column():
 
 
613
  input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload")
614
 
615
  text_prompt = gr.Textbox(label="Detection Prompt[To detect multiple objects, seperating each name with '.', like this: cat . dog . chair ]", placeholder="Cannot be empty")
@@ -629,7 +641,23 @@ if __name__ == "__main__":
629
  image_gallery = gr.Gallery(label="result images", show_label=True, elem_id="gallery", visible=True
630
  ).style(preview=True, columns=[5], object_fit="scale-down", height="auto")
631
 
632
- run_button.click(fn=run_anything_task, inputs=[
633
- input_image, text_prompt, box_threshold, text_threshold, iou_threshold], outputs=[gr.Textbox(), image_gallery, image_gallery], show_progress=True, queue=True)
634
-
635
- block.queue(max_size=1).launch(server_name='0.0.0.0', debug=args.debug, share=args.share)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  warnings.filterwarnings('ignore')
4
 
5
  import subprocess, io, os, sys, time
6
+ # os.system("pip install gradio==3.38.0")
7
  import gradio as gr
8
 
9
  from loguru import logger
10
 
11
+
12
  os.environ["CUDA_VISIBLE_DEVICES"] = "0"
13
 
14
+ #if os.environ.get('IS_MY_DEBUG') is None:
15
+ # result = subprocess.run(['pip', 'install', '-e', 'GroundingDINO'], check=True)
16
+ # print(f'pip install GroundingDINO = {result}')
17
 
18
  # result = subprocess.run(['pip', 'list'], check=True)
19
  # print(f'pip list = {result}')
 
64
  resize_max_size,
65
  )
66
 
67
+ SECRET_TOKEN = os.getenv('SECRET_TOKEN', 'default_secret')
68
+
69
  config_file = 'GroundingDINO/groundingdino/config/GroundingDINO_SwinT_OGC.py'
70
  ckpt_repo_id = "ShilongLiu/GroundingDINO"
71
  ckpt_filenmae = "groundingdino_swint_ogc.pth"
 
607
  load_lama_cleaner_model()
608
  load_ram_model()
609
 
610
+ # os.system("pip list")
611
 
612
  block = gr.Blocks().queue()
613
  with block:
614
+ gr.HTML("""
615
+ <div style="z-index: 100; position: fixed; top: 0px; right: 0px; left: 0px; bottom: 0px; width: 100%; height: 100%; background: white; display: flex; align-items: center; justify-content: center; color: black;">
616
+ <div style="text-align: center; color: black;">
617
+ <p style="color: black;">This space is a REST API to programmatically segment an image.</p>
618
+ <p style="color: black;">Interested in using it? Please use the <a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything" target="_blank">original space</a>, thank you!</p>
619
+ </div>
620
+ </div>""")
621
  with gr.Row():
622
  with gr.Column():
623
+ text_prompt = gr.Textbox()
624
+
625
  input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload")
626
 
627
  text_prompt = gr.Textbox(label="Detection Prompt[To detect multiple objects, seperating each name with '.', like this: cat . dog . chair ]", placeholder="Cannot be empty")
 
641
  image_gallery = gr.Gallery(label="result images", show_label=True, elem_id="gallery", visible=True
642
  ).style(preview=True, columns=[5], object_fit="scale-down", height="auto")
643
 
644
+ run_button.click(
645
+ fn=run_anything_task,
646
+ inputs=[
647
+ secret_token,
648
+ input_image,
649
+ text_prompt,
650
+ box_threshold,
651
+ text_threshold,
652
+ iou_threshold
653
+ ],
654
+ outputs=[
655
+ gr.Textbox(),
656
+ image_gallery,
657
+ image_gallery
658
+ ],
659
+ show_progress=False,
660
+ queue=True
661
+ )
662
+
663
+ block.queue(max_size=20).launch(server_name='0.0.0.0', debug=args.debug, share=args.share)