Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,7 +79,7 @@ def analyze_image(image, analysis_types):
|
|
| 79 |
draw = ImageDraw.Draw(img_with_boxes)
|
| 80 |
|
| 81 |
if "Labels" in analysis_types:
|
| 82 |
-
|
| 83 |
labels_data = {label.description: round(label.score * 100)
|
| 84 |
for label in labels.label_annotations}
|
| 85 |
|
|
@@ -87,15 +87,15 @@ def analyze_image(image, analysis_types):
|
|
| 87 |
objects = client.object_localization(image=vision_image)
|
| 88 |
objects_data = {obj.name: round(obj.score * 100)
|
| 89 |
for obj in objects.localized_object_annotations}
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
box = [(vertex.x * image.width, vertex.y * image.height)
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
|
| 100 |
if "Text" in analysis_types:
|
| 101 |
text = client.text_detection(image=vision_image)
|
|
|
|
| 79 |
draw = ImageDraw.Draw(img_with_boxes)
|
| 80 |
|
| 81 |
if "Labels" in analysis_types:
|
| 82 |
+
labels = client.label_detection(image=vision_image)
|
| 83 |
labels_data = {label.description: round(label.score * 100)
|
| 84 |
for label in labels.label_annotations}
|
| 85 |
|
|
|
|
| 87 |
objects = client.object_localization(image=vision_image)
|
| 88 |
objects_data = {obj.name: round(obj.score * 100)
|
| 89 |
for obj in objects.localized_object_annotations}
|
| 90 |
+
|
| 91 |
+
# Draw object boundaries
|
| 92 |
+
for obj in objects.localized_object_annotations:
|
| 93 |
box = [(vertex.x * image.width, vertex.y * image.height)
|
| 94 |
+
for vertex in obj.bounding_poly.normalized_vertices]
|
| 95 |
+
draw.polygon(box, outline='red', width=2)
|
| 96 |
+
draw.text((box[0][0], box[0][1] - 10),
|
| 97 |
+
f"{obj.name}: {int(obj.score * 100)}%",
|
| 98 |
+
fill='red')
|
| 99 |
|
| 100 |
if "Text" in analysis_types:
|
| 101 |
text = client.text_detection(image=vision_image)
|