taroii commited on
Commit
3f5c0c0
1 Parent(s): 891a723

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -6
app.py CHANGED
@@ -4,10 +4,9 @@ import torch
4
  import supervision as sv
5
  import json
6
 
7
- def anylize(img):
8
- id2label = {0: 'dangerous-items', 1: 'Gun', 2: 'Knife', 3: 'Pliers', 4: 'Scissors', 5: 'Wrench'}
9
- image = img
10
 
 
11
  with torch.no_grad():
12
 
13
  inputs = image_processor(images=image, return_tensors='pt')
@@ -22,7 +21,23 @@ def anylize(img):
22
 
23
  # annotate
24
  detections = sv.Detections.from_transformers(transformers_results=results).with_nms(threshold=0.5)
25
- labels = [str([list(xyxy), confidence, id2label[class_id]]) for xyxy, _, confidence, class_id, _ in detections]
26
- json_list = json.dumps(str(labels[0]))
27
 
28
- gr.Interface.load("models/Guy2/AirportSec-100epoch").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import supervision as sv
5
  import json
6
 
7
+ id2label = {0: 'dangerous-items', 1: 'Gun', 2: 'Knife', 3: 'Pliers', 4: 'Scissors', 5: 'Wrench'}
 
 
8
 
9
+ def anylize(image):
10
  with torch.no_grad():
11
 
12
  inputs = image_processor(images=image, return_tensors='pt')
 
21
 
22
  # annotate
23
  detections = sv.Detections.from_transformers(transformers_results=results).with_nms(threshold=0.5)
 
 
24
 
25
+ out = {}
26
+
27
+ for idx, detection in enumerate(detections):
28
+ cls = id2label[detection.class_id]
29
+ confidence = detection.confidence
30
+ box = detection.xyxy
31
+
32
+ out[str(idx)] = {
33
+ "box":list(box),
34
+ "cls":cls,
35
+ "conf":confidence
36
+ }
37
+
38
+ #labels = [str([list(xyxy), confidence, id2label[class_id]]) for xyxy, _, confidence, class_id, _ in detections]
39
+ #json_list = json.dumps(str(labels[0]))
40
+
41
+ return out
42
+
43
+ gr.Interface(fn = anylize, inputs="image", outputs=gr.JSON()).launch()