Spaces:
Running on Zero
Running on Zero
Download utils/annotate.py from EmanHassan26/ImagesRAG: direct link, hf CLI and curl.
- Browser
- Download file 765 Bytes
-
https://huggingface.co/spaces/EmanHassan26/ImagesRAG/resolve/main/utils/annotate.py
- Command line
-
hf download hf://spaces/EmanHassan26/ImagesRAG/utils/annotate.py
-
curl -L -o annotate.py https://huggingface.co/spaces/EmanHassan26/ImagesRAG/resolve/main/utils/annotate.py
765 Bytes
| import supervision as sv | |
| from PIL import Image | |
| def annotate_with_boxes(image: Image, detections: sv.Detections) -> Image: | |
| annotated_image = image.copy() | |
| thickness = sv.calculate_optimal_line_thickness(resolution_wh=image.size) | |
| text_scale = sv.calculate_optimal_text_scale(resolution_wh=image.size) | |
| bounding_box_annotator = sv.BoundingBoxAnnotator( | |
| color_lookup=sv.ColorLookup.INDEX, thickness=thickness) | |
| label_annotator = sv.LabelAnnotator( | |
| color_lookup=sv.ColorLookup.INDEX, | |
| text_scale=text_scale, | |
| text_thickness=thickness) | |
| annotated_image = bounding_box_annotator.annotate(annotated_image, detections) | |
| annotated_image = label_annotator.annotate(annotated_image, detections) | |
| return annotated_image | |