Spaces:
Running
Running
File size: 1,778 Bytes
a1873d6 a1e86b6 a1873d6 b547fbf fa4ee23 a0bd560 b547fbf fa4ee23 cd7cf5e a8eee9b cd7cf5e a8eee9b 1dbceee cd7cf5e b547fbf a0bd560 08d4b40 b547fbf a0bd560 b547fbf a0bd560 b547fbf a0bd560 b547fbf 96523cc b547fbf a0bd560 b547fbf 08d4b40 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import spaces # on top as CUDA needs to be initialized after `spaces`
import os
try:
import detectron2
except ImportError:
import os
os.system('pip install git+https://github.com/facebookresearch/detectron2.git')
try:
from segment_anything import build_sam, SamPredictor
except ImportError:
import os
os.system('pip install git+https://github.com/facebookresearch/segment-anything.git')
from segment_anything import build_sam, SamPredictor
try:
import grounded_dino
except ImportError:
import os
os.system('pip install transformers')
os.system('pip install git+https://github.com/IDEA-Research/GroundingDINO.git')
import gradio as gr
import json
import numpy as np
from sam_utils import grounded_segmentation, create_yellow_background_with_insects
from yolo_utils import yolo_processimage
from detectron_utils import detectron_process_image
from gsl_utils import gsl_process_image
@spaces.GPU
def process_image(image, include_json):
detectron_result = detectron_process_image(image)
yolo_result = yolo_processimage(image)
insectsam_result = create_yellow_background_with_insects(image)
gsl_result = gsl_process_image(image)
return insectsam_result, yolo_result, detectron_result, gsl_result
examples = [
["imgs/demo.jpg"],
["imgs/demo1.jpg"],
["imgs/demo2.jpg"],
["imgs/demo3.jpg"],
["imgs/demo4.jpg"],
["imgs/demo5.jpg"],
]
gr.Interface(
fn=process_image,
inputs=[gr.Image(type="pil")],
outputs=[
gr.Image(label='InsectSAM', type="numpy"),
gr.Image(label='Yolov8', type="numpy"),
gr.Image(label='Detectron', type="numpy"),
gr.Image(label='GSL', type="numpy")
],
title="Insect Model Zoo ππ¬",
examples=examples
).launch() |