capjamesg commited on
Commit
606d9f7
·
1 Parent(s): 815319d
Files changed (2) hide show
  1. app.py +33 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import gradio as gr
3
+ import numpy as np
4
+ import spaces
5
+ import supervision as sv
6
+ from autodistill.detection import CaptionOntology
7
+ from autodistill.utils import plot
8
+ from autodistill_grounded_sam_2 import GroundedSAM2
9
+
10
+
11
+ @spaces.GPU
12
+ def greet(image):
13
+ base_model = GroundedSAM2(
14
+ ontology=CaptionOntology({"container id": "container number", "logo": "logo"}),
15
+ model="Grounding DINO",
16
+ grounding_dino_box_threshold=0.25,
17
+ )
18
+
19
+ results = base_model.predict("container1.jpg").with_nms()
20
+ results = results[results.confidence > 0.3]
21
+ # print(results)
22
+
23
+ image = cv2.imread("container1.jpg")
24
+
25
+ mask_annotator = sv.BoxAnnotator()
26
+
27
+ annotated_image = mask_annotator.annotate(image.copy(), detections=results)
28
+
29
+ return annotated_image
30
+
31
+
32
+ demo = gr.Interface(fn=greet, inputs="image", outputs="image")
33
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ autodistill
3
+ numpy>=1.20.0
4
+ opencv-python>=4.6.0
5
+ supervision
6
+ roboflow
7
+ autodistill_florence_2
8
+ rf_groundingdino