| 1 | """Shared configuration for keyframe candidate generation.""" |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | DEFAULT_IMAGE_CANDIDATES = 2 |
| 6 | |
| 7 | |
| 8 | def validate_image_candidate_count(value: object) -> int: |
| 9 | if isinstance(value, str) and value.strip().isdigit(): |
| 10 | value = int(value.strip()) |
| 11 | if type(value) is not int or value < 1: |
| 12 | raise ValueError("image_selection.num_candidates must be a positive integer") |
| 13 | return value |
| 14 | |
| 15 | |
| 16 | def image_candidate_count_from_config(config: dict) -> int: |
| 17 | override = os.environ.get("VIMAX_IMAGE_NUM_CANDIDATES") |
| 18 | if override is not None: |
| 19 | return validate_image_candidate_count(override) |
| 20 | section = config.get("image_selection", {}) |
| 21 | if not isinstance(section, dict): |
| 22 | raise ValueError("image_selection must be a YAML mapping") |
| 23 | return validate_image_candidate_count(section.get("num_candidates", DEFAULT_IMAGE_CANDIDATES)) |
| 24 |