Download example.py from Yannik019/llm_pack_detection: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/datasets/Yannik019/llm_pack_detection/resolve/main/example.py
- Command line
-
hf download hf://datasets/Yannik019/llm_pack_detection/example.py
-
curl -L -o example.py https://huggingface.co/datasets/Yannik019/llm_pack_detection/resolve/main/example.py
1.65 kB
| #!/usr/bin/env python3 | |
| from __future__ import annotations | |
| from datasets import load_dataset | |
| from PIL import ImageDraw | |
| REPO_ID = "Yannik019/llm_pack_detection" | |
| def draw_first_item_location(row: dict): | |
| image = row["image"].copy() | |
| first_label = row["labels"][0] | |
| x = row["annotation_x"][0] | |
| y = row["annotation_y"][0] | |
| draw = ImageDraw.Draw(image) | |
| radius = 18 | |
| draw.ellipse((x - radius, y - radius, x + radius, y + radius), outline="red", width=6) | |
| draw.line((x - 28, y, x + 28, y), fill="red", width=4) | |
| draw.line((x, y - 28, x, y + 28), fill="red", width=4) | |
| draw.text((x + 24, y - 32), first_label, fill="red") | |
| return image, first_label, x, y | |
| def summarize_row(row: dict, index: int) -> None: | |
| image, first_label, first_x, first_y = draw_first_item_location(row) | |
| image_size = getattr(image, "size", None) | |
| labels = ", ".join(row["labels"]) | |
| print(f"Row {index}") | |
| print(f" caption: {row['caption']}") | |
| print(f" bucket: {row['bucket']}") | |
| print(f" sample_id: {row['sample_id']}") | |
| print(f" annotation_count: {row['annotation_count']}") | |
| print(f" labels: {labels}") | |
| print(f" first_item: {first_label} @ ({first_x}, {first_y})") | |
| print(f" image_type: {type(image).__name__}") | |
| print(f" image_size: {image_size}") | |
| image.show() | |
| def main() -> int: | |
| dataset = load_dataset(REPO_ID, split="train") | |
| print(dataset) | |
| print(f"Loaded {len(dataset)} rows from {REPO_ID}") | |
| limit = min(3, len(dataset)) | |
| for index in range(limit): | |
| summarize_row(dataset[index], index) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) |