Guy2 commited on
Commit
e11d9a1
1 Parent(s): 174826a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -26,8 +26,10 @@ def anylize(url):
26
 
27
  # annotate
28
  detections = sv.Detections.from_transformers(transformers_results=results).with_nms(threshold=0.5)
29
- labels = [str([list(xyxy), confidence, id2label[class_id]]) for xyxy, _, confidence, class_id, _ in detections]
30
- json_list = json.dumps(labels)
31
- return json_list
 
32
 
33
- gr.Interface(fn = anylize, inputs="text", outputs=gr.JSON()).launch()
 
 
26
 
27
  # annotate
28
  detections = sv.Detections.from_transformers(transformers_results=results).with_nms(threshold=0.5)
29
+ labels = [f"{id2label[class_id]} {confidence:.2f}" for _, _, confidence, class_id, _ in detections]
30
+ box_annotator = sv.BoxAnnotator()
31
+ frame = box_annotator.annotate(scene=image.copy(), detections=detections, labels=labels)
32
+ return frame
33
 
34
+ output = gr.components.Image(type="numpy", label="Output Image")
35
+ gr.Interface(fn = anylize, inputs="text", outputs=output).launch()