File size: 997 Bytes
0bdbec3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import annotations

from pathlib import Path
from typing import List

from ..state import AppState, ImageArtifact


def run(state: AppState) -> AppState:
    scores = sorted(state.get("scores", []), key=lambda s: s["score"], reverse=True)
    if not scores:
        return state
    best = scores[0]
    best_img_path = best["image_path"]
    # find the corresponding ImageArtifact
    best_image: ImageArtifact | None = None
    for im in state.get("images", []):
        if im.path == best_img_path:
            best_image = im
            break
    vios = [str(v) for v in best.get("violations", [])]
    # Identify hard violations: explicit HARD marker or labels missing heuristic
    hard = [v for v in vios if v.strip().lower().startswith("hard:")]
    if not hard:
        hard = [v for v in vios if ("labels" in v.lower() and "missing" in v.lower())]

    state["best_image"] = best_image
    state["violations"] = vios
    state["hard_violations"] = hard
    return state