Spaces:
Runtime error
Runtime error
Clean app.py
Browse files
app.py
CHANGED
|
@@ -10,10 +10,10 @@ from loguru import logger
|
|
| 10 |
import subprocess
|
| 11 |
import copy
|
| 12 |
import time
|
| 13 |
-
|
| 14 |
import warnings
|
| 15 |
|
| 16 |
import torch
|
|
|
|
| 17 |
warnings.filterwarnings("ignore")
|
| 18 |
|
| 19 |
# grounding DINO
|
|
@@ -23,15 +23,11 @@ from groundingdino.util.utils import clean_state_dict
|
|
| 23 |
from groundingdino.util.inference import annotate, load_image, predict
|
| 24 |
import groundingdino.datasets.transforms as T
|
| 25 |
|
| 26 |
-
from torchvision.ops import box_convert
|
| 27 |
-
|
| 28 |
# segment anything
|
| 29 |
from segment_anything import build_sam, SamPredictor
|
| 30 |
|
| 31 |
from huggingface_hub import hf_hub_download
|
| 32 |
|
| 33 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
|
| 34 |
-
|
| 35 |
if not os.path.exists('./sam_vit_h_4b8939.pth'):
|
| 36 |
logger.info(f"get sam_vit_h_4b8939.pth...")
|
| 37 |
result = subprocess.run(['wget', 'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth'], check=True)
|
|
@@ -230,12 +226,11 @@ def grounding_sam(input_image, text_prompt, task_type, box_threshold, text_thres
|
|
| 230 |
|
| 231 |
return output_images, gr.Gallery.update(label='result images')
|
| 232 |
|
| 233 |
-
|
| 234 |
groundingDino_model = load_model_hf(config_file, ckpt_repo_id, ckpt_filename, groundingdino_device)
|
| 235 |
sam_predictor = SamPredictor(build_sam(checkpoint=sam_checkpoint))
|
| 236 |
|
| 237 |
if __name__ == "__main__":
|
| 238 |
-
|
| 239 |
parser = argparse.ArgumentParser("Grounding SAM demo", add_help=True)
|
| 240 |
parser.add_argument("--debug", action="store_true", help="using debug mode")
|
| 241 |
parser.add_argument("--share", action="store_true", help="share the app")
|
|
@@ -278,4 +273,4 @@ if __name__ == "__main__":
|
|
| 278 |
run_button.click(fn=grounding_sam, inputs=[
|
| 279 |
input_image, text_prompt, task_type, box_threshold, text_threshold, iou_threshold], outputs=[gallery, gallery])
|
| 280 |
|
| 281 |
-
block.launch(share=
|
|
|
|
| 10 |
import subprocess
|
| 11 |
import copy
|
| 12 |
import time
|
|
|
|
| 13 |
import warnings
|
| 14 |
|
| 15 |
import torch
|
| 16 |
+
from torchvision.ops import box_convert
|
| 17 |
warnings.filterwarnings("ignore")
|
| 18 |
|
| 19 |
# grounding DINO
|
|
|
|
| 23 |
from groundingdino.util.inference import annotate, load_image, predict
|
| 24 |
import groundingdino.datasets.transforms as T
|
| 25 |
|
|
|
|
|
|
|
| 26 |
# segment anything
|
| 27 |
from segment_anything import build_sam, SamPredictor
|
| 28 |
|
| 29 |
from huggingface_hub import hf_hub_download
|
| 30 |
|
|
|
|
|
|
|
| 31 |
if not os.path.exists('./sam_vit_h_4b8939.pth'):
|
| 32 |
logger.info(f"get sam_vit_h_4b8939.pth...")
|
| 33 |
result = subprocess.run(['wget', 'https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth'], check=True)
|
|
|
|
| 226 |
|
| 227 |
return output_images, gr.Gallery.update(label='result images')
|
| 228 |
|
|
|
|
| 229 |
groundingDino_model = load_model_hf(config_file, ckpt_repo_id, ckpt_filename, groundingdino_device)
|
| 230 |
sam_predictor = SamPredictor(build_sam(checkpoint=sam_checkpoint))
|
| 231 |
|
| 232 |
if __name__ == "__main__":
|
| 233 |
+
|
| 234 |
parser = argparse.ArgumentParser("Grounding SAM demo", add_help=True)
|
| 235 |
parser.add_argument("--debug", action="store_true", help="using debug mode")
|
| 236 |
parser.add_argument("--share", action="store_true", help="share the app")
|
|
|
|
| 273 |
run_button.click(fn=grounding_sam, inputs=[
|
| 274 |
input_image, text_prompt, task_type, box_threshold, text_threshold, iou_threshold], outputs=[gallery, gallery])
|
| 275 |
|
| 276 |
+
block.launch(debug=args.debug, share=args.share, show_api=False, show_error=True)
|