Spaces:
Sleeping
Sleeping
Download src/models/difference.py from so-21-si/spot-the-diff: direct link, hf CLI and curl.
- Browser
- Download file 997 Bytes
-
https://huggingface.co/spaces/so-21-si/spot-the-diff/resolve/main/src/models/difference.py
- Command line
-
hf download hf://spaces/so-21-si/spot-the-diff/src/models/difference.py
-
curl -L -o difference.py https://huggingface.co/spaces/so-21-si/spot-the-diff/resolve/main/src/models/difference.py
997 Bytes
| """Difference and generation result data models.""" | |
| from __future__ import annotations | |
| from dataclasses import dataclass, field, asdict | |
| from typing import Any | |
| import numpy as np | |
| class Difference: | |
| """A single difference applied to the image.""" | |
| id: int | |
| type: str # "deletion", "color_change", "addition" | |
| bbox: list[int] # [x1, y1, x2, y2] | |
| saliency_score: float | |
| description: str = "" | |
| def to_dict(self) -> dict[str, Any]: | |
| return asdict(self) | |
| class GenerationResult: | |
| """Result of the spot-the-difference generation pipeline.""" | |
| original_image: np.ndarray | |
| modified_image: np.ndarray | |
| differences: list[Difference] | |
| metadata: dict[str, Any] = field(default_factory=dict) | |
| def get_metadata_with_differences(self) -> dict[str, Any]: | |
| return { | |
| **self.metadata, | |
| "differences": [d.to_dict() for d in self.differences], | |
| "total_differences": len(self.differences), | |
| } | |