Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,7 @@ model = DetrForObjectDetection.from_pretrained("Guy2/AirportSec-150epoch")
|
|
12 |
id2label = {0: 'dangerous-items', 1: 'Gun', 2: 'Knife', 3: 'Pliers', 4: 'Scissors', 5: 'Wrench'}
|
13 |
def anylize(url):
|
14 |
image = Image.open(requests.get(url, stream=True).raw)
|
15 |
-
return image
|
16 |
with torch.no_grad():
|
17 |
|
18 |
inputs = image_processor(images=image, return_tensors='pt')
|
@@ -29,8 +29,9 @@ def anylize(url):
|
|
29 |
# annotate
|
30 |
detections = sv.Detections.from_transformers(transformers_results=results).with_nms(threshold=0.5)
|
31 |
labels = [str([list(xyxy), confidence, id2label[class_id]]) for xyxy, _, confidence, class_id, _ in detections]
|
32 |
-
|
33 |
-
|
|
|
34 |
|
35 |
-
|
36 |
-
gr.Interface(fn = anylize, inputs="text", outputs="image").launch()
|
|
|
12 |
id2label = {0: 'dangerous-items', 1: 'Gun', 2: 'Knife', 3: 'Pliers', 4: 'Scissors', 5: 'Wrench'}
|
13 |
def anylize(url):
|
14 |
image = Image.open(requests.get(url, stream=True).raw)
|
15 |
+
# return image
|
16 |
with torch.no_grad():
|
17 |
|
18 |
inputs = image_processor(images=image, return_tensors='pt')
|
|
|
29 |
# annotate
|
30 |
detections = sv.Detections.from_transformers(transformers_results=results).with_nms(threshold=0.5)
|
31 |
labels = [str([list(xyxy), confidence, id2label[class_id]]) for xyxy, _, confidence, class_id, _ in detections]
|
32 |
+
return labels
|
33 |
+
# json_list = json.dumps(labels)
|
34 |
+
# return json_list
|
35 |
|
36 |
+
gr.Interface(fn = anylize, inputs="text", outputs="text").launch()
|
37 |
+
# gr.Interface(fn = anylize, inputs="text", outputs="image").launch()
|