Download tasks/t23-dance-blob/tests/legacy_v0.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 14.5 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t23-dance-blob/tests/legacy_v0.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/t23-dance-blob/tests/legacy_v0.py
-
curl -L -o legacy_v0.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t23-dance-blob/tests/legacy_v0.py
14.5 kB
| """t23 rubric v0 — recreate the "Dance Blob" loop (Friction, GUI-only). | |
| Source: github.com/nanCreate/AE_Dance-Blob (MIT), its TikTok_Center render. | |
| The agent watches /root/media/reference.mp4 (800x800, 30 fps, 6 s, banner | |
| painted out, muted) and rebuilds the loop from scratch in Friction: | |
| /root/edit/blob.friction + /root/Desktop/final.mp4 (800x800, 30 fps, ~6 s). | |
| Everything is measured on the agent's RENDER (30 fps, 200x200 decode, pure | |
| Python): saturated pixels = blob fill; dark pixels inside a blob = face; | |
| column runs = blobs. Tolerances in tests/beats.json (measured from the source). | |
| A deliverable ................................................... 0.10 | |
| final.mp4 decodes 0.03 · 800x800 0.02 · 6 s ±1 0.03 · a *.friction ≥ 1 KB 0.02 | |
| B scene ........................................................ 0.25 | |
| white background 0.04 · 3-6 blobs in a row on ≥ 90 % of frames 0.06 · | |
| shared baseline (bottoms within 4 % of H per frame) 0.05 · rest | |
| aspect w/h 0.85-1.70 0.04 · faces: dark marks inside ≥ half the full blobs 0.06 | |
| C bounce ....................................................... 0.30 | |
| squash: min/max height 0.50-0.88 0.08 · bottom pinned (std < 2 % H) 0.06 · | |
| hop period 0.36-0.60 s (autocorrelation of height) 0.08 · width holds | |
| (max/min < 1.25) 0.04 · eased: no single-frame height step > 35 % of | |
| the amplitude 0.04 | |
| D side-step .................................................... 0.20 | |
| row drifts RIGHT 0.45-1.70 spacings / s 0.10 · pulsed: ≥ 25 % of frames | |
| still 0.05 · regular spacing (CV < 0.15) 0.05 | |
| E colour ....................................................... 0.15 | |
| ≥ 6 distinct 30° hue bins 0.06 · one shared hue per frame (spread < 40° | |
| on ≥ 80 % of frames) 0.04 · hue bin changes ≥ 4 / s 0.05 | |
| GUI-only gate: any logged terminal attempt → reward 0. | |
| """ | |
| import colorsys | |
| import glob | |
| import json | |
| import os | |
| import subprocess | |
| from _vedit_verifier import Rubric, duration, probe, video_size, write_reward | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| HOME = os.environ.get("T23_HOME", "/root") | |
| FINAL = os.environ.get("T23_FINAL", os.path.join(HOME, "Desktop/final.mp4")) | |
| REWARD_PATH = os.environ.get("T23_REWARD", "/logs/verifier/reward.txt") | |
| TERMINAL_LOG = os.environ.get("T23_TERMINAL_LOG", "/logs/artifacts/terminal-attempts.log") | |
| WORK = os.environ.get("T23_WORK", "/tmp/t23-grade") | |
| BEATS = json.load(open(os.path.join(HERE, "beats.json"))) | |
| S = 200 # decode size (square) | |
| FPS = 30 | |
| FRAME_W, FRAME_H = BEATS["frame"]["w"], BEATS["frame"]["h"] | |
| DUR, DUR_TOL = BEATS["frame"]["duration_s"], 1.0 | |
| MIN_RUN = 8 # px at 200: a blob is ≥ 32 px wide in the 800 frame | |
| FULL_MARGIN = 2 # runs touching the frame edge are clipped blobs | |
| def decode(path): | |
| try: | |
| raw = subprocess.run(["ffmpeg", "-nostdin", "-v", "error", "-i", path, "-vf", "fps=%d,scale=%d:%d" % (FPS, S, S), | |
| "-f", "rawvideo", "-pix_fmt", "rgb24", "-"], capture_output=True, check=True).stdout | |
| except Exception: | |
| return [] | |
| n = len(raw) // (S * S * 3) | |
| return [raw[i * S * S * 3:(i + 1) * S * S * 3] for i in range(n)] | |
| def analyse(f): | |
| """Per frame: background whiteness, blob runs with top/bottom/width/hue/face.""" | |
| sat_col = [0] * S | |
| top = [S] * S | |
| bot = [-1] * S | |
| dark_col = [0] * S | |
| border = 0 | |
| border_n = 0 | |
| for y in range(S): | |
| row = y * S * 3 | |
| edge_row = y < 3 or y >= S - 3 | |
| for x in range(S): | |
| i = row + 3 * x | |
| r, g, b = f[i], f[i + 1], f[i + 2] | |
| mx, mn = max(r, g, b), min(r, g, b) | |
| if edge_row or x < 3 or x >= S - 3: | |
| border += (r + g + b); border_n += 3 | |
| if mx - mn > 50 and mx > 90: | |
| sat_col[x] += 1 | |
| if y < top[x]: | |
| top[x] = y | |
| if y > bot[x]: | |
| bot[x] = y | |
| elif mx < 110: | |
| dark_col[x] += 1 | |
| runs = [] | |
| s = None | |
| for x in range(S + 1): | |
| on = x < S and sat_col[x] >= 3 | |
| if on and s is None: | |
| s = x | |
| if not on and s is not None: | |
| if x - s >= MIN_RUN: | |
| runs.append((s, x - 1)) | |
| s = None | |
| blobs = [] | |
| for s, e in runs: | |
| t = min(top[s:e + 1]); b = max(bot[s:e + 1]) | |
| # hue from the mean colour of the run's saturated pixels (sample rows) | |
| rs = gs = bs = n = 0 | |
| for y in range(t, b + 1, 3): | |
| row = y * S * 3 | |
| for x in range(s, e + 1, 2): | |
| i = row + 3 * x | |
| r, g, bb = f[i], f[i + 1], f[i + 2] | |
| if max(r, g, bb) - min(r, g, bb) > 50: | |
| rs += r; gs += g; bs += bb; n += 1 | |
| hue = colorsys.rgb_to_hsv(rs / n / 255.0, gs / n / 255.0, bs / n / 255.0)[0] * 360 if n else None | |
| dark = sum(dark_col[s:e + 1]) | |
| full = s > FULL_MARGIN and e < S - 1 - FULL_MARGIN | |
| blobs.append({"x0": s, "x1": e, "w": e - s + 1, "top": t, "bot": b, "h": b - t + 1, | |
| "hue": hue, "dark": dark, "full": full}) | |
| return {"white": border / border_n if border_n else 0, "blobs": blobs} | |
| def median(v): | |
| v = sorted(v) | |
| return v[len(v) // 2] if v else None | |
| def circ_spread(hues): | |
| if len(hues) < 2: | |
| return 0.0 | |
| best = 360.0 | |
| hs = sorted(hues) | |
| for i in range(len(hs)): | |
| rot = [(h - hs[i]) % 360 for h in hs] | |
| best = min(best, max(rot)) | |
| return best | |
| def first_ac_peak(sig, lo, hi): | |
| n = len(sig) | |
| m = sum(sig) / n | |
| v = [x - m for x in sig] | |
| den = sum(x * x for x in v) or 1.0 | |
| ac = [] | |
| for k in range(0, hi + 2): | |
| ac.append(sum(v[i] * v[i + k] for i in range(n - k)) / den) | |
| for k in range(max(1, lo), hi + 1): | |
| if ac[k] > ac[k - 1] and ac[k] >= ac[k + 1] and ac[k] > 0.2: | |
| return k, ac[k] | |
| return None, max(ac[lo:hi + 1]) if hi > lo else 0 | |
| def row_shift(a, b, maxs=20): | |
| """Horizontal shift (px, +right) of frame b's blob columns vs frame a, by 1-D correlation.""" | |
| ca = [1 if x else 0 for x in a] | |
| cb = [1 if x else 0 for x in b] | |
| best, bd = -1, 0 | |
| for d in range(-maxs, maxs + 1): | |
| sc = 0 | |
| for x in range(S): | |
| xx = x + d | |
| if 0 <= xx < S and ca[x] and cb[xx]: | |
| sc += 1 | |
| if sc > best: | |
| best, bd = sc, d | |
| return bd | |
| def find_projects(): | |
| out = [] | |
| for p in glob.glob(os.path.join(HOME, "**", "*.friction"), recursive=True): | |
| try: | |
| if os.path.getsize(p) >= 1024: | |
| out.append(p) | |
| except OSError: | |
| pass | |
| return out | |
| def terminal_attempts(): | |
| try: | |
| return [l for l in open(TERMINAL_LOG).read().splitlines() if l.strip()] | |
| except OSError: | |
| return [] | |
| def test_rubric(): | |
| os.makedirs(WORK, exist_ok=True) | |
| r = Rubric("t23-dance-blob v0", REWARD_PATH) | |
| # --- A deliverable --------------------------------------------------- | |
| meta = probe(FINAL) | |
| r.check(0.03, "final.mp4 decodes: %s" % FINAL, meta is not None) | |
| size = video_size(meta) if meta else None | |
| r.check(0.02, "final.mp4 is %dx%d (got %s)" % (FRAME_W, FRAME_H, size), size == (FRAME_W, FRAME_H)) | |
| dur = duration(meta) if meta else None | |
| r.check(0.03, "duration %.2f s = %.1f ±%.1f" % (dur or -1, DUR, DUR_TOL), dur is not None and abs(dur - DUR) <= DUR_TOL) | |
| projects = find_projects() | |
| r.check(0.02, "a Friction project (*.friction ≥ 1 KB) under %s: %s" % (HOME, projects), bool(projects)) | |
| frames = decode(FINAL) if meta else [] | |
| A = [analyse(f) for f in frames] | |
| n = len(A) | |
| measured = {"frames": n} | |
| # --- B scene ----------------------------------------------------------- | |
| white_ok = n > 0 and sum(1 for a in A if a["white"] > 225) >= 0.9 * n | |
| r.check(0.04, "white background (border mean > 225 on ≥ 90 %% of %d frames)" % n, white_ok) | |
| counts = [len(a["blobs"]) for a in A] | |
| row_ok = n > 0 and sum(1 for c in counts if 3 <= c <= 6) >= 0.9 * n | |
| r.check(0.06, "3-6 blobs per frame on ≥ 90 %% of frames (median %s)" % median(counts), row_ok) | |
| base_ok_frames = 0 | |
| for a in A: | |
| bs = [b["bot"] for b in a["blobs"] if b["full"]] | |
| if len(bs) >= 2 and max(bs) - min(bs) <= 0.04 * S: | |
| base_ok_frames += 1 | |
| r.check(0.05, "shared baseline: full blobs' bottoms within 4 %% of H (%d/%d frames)" % (base_ok_frames, n), | |
| n > 0 and base_ok_frames >= 0.8 * n) | |
| med_h = [median([b["h"] for b in a["blobs"] if b["full"]]) for a in A] | |
| med_w = [median([b["w"] for b in a["blobs"] if b["full"]]) for a in A] | |
| hs = [(h, i) for i, h in enumerate(med_h) if h] | |
| rest_i = max(hs)[1] if hs else None | |
| aspect = (med_w[rest_i] / med_h[rest_i]) if rest_i is not None and med_h[rest_i] else None | |
| lo, hi = BEATS["aspect_tol"] | |
| r.check(0.04, "rest aspect w/h %.2f in %.2f-%.2f" % (aspect or -1, lo, hi), aspect is not None and lo <= aspect <= hi) | |
| face_frames = 0 | |
| face_tot = 0 | |
| for a in A: | |
| full = [b for b in a["blobs"] if b["full"]] | |
| if full: | |
| face_tot += 1 | |
| if sum(1 for b in full if b["dark"] >= 6) >= (len(full) + 1) // 2: | |
| face_frames += 1 | |
| r.check(0.06, "faces: dark marks inside ≥ half the full blobs (%d/%d frames)" % (face_frames, face_tot), | |
| face_tot > 0 and face_frames >= 0.7 * face_tot) | |
| # --- C bounce ---------------------------------------------------------- | |
| hsig = [h for h in med_h if h] | |
| hmin, hmax = (min(hsig), max(hsig)) if hsig else (0, 0) | |
| squash = hmin / hmax if hmax else None | |
| lo, hi = BEATS["squash_tol"] | |
| r.check(0.08, "squash: min/max blob height %.2f in %.2f-%.2f" % (squash or -1, lo, hi), squash is not None and lo <= squash <= hi) | |
| bots = [median([b["bot"] for b in a["blobs"] if b["full"]]) for a in A] | |
| bots = [b for b in bots if b is not None] | |
| if bots: | |
| mb = sum(bots) / len(bots) | |
| bstd = (sum((b - mb) ** 2 for b in bots) / len(bots)) ** 0.5 | |
| else: | |
| bstd = None | |
| r.check(0.06, "bottom pinned while bouncing: baseline std %.2f px (< %.1f)" % (bstd if bstd is not None else -1, 0.02 * S), | |
| bstd is not None and bstd < 0.02 * S and squash is not None and squash < 0.95) | |
| lo_s, hi_s = BEATS["hop_tol_s"] | |
| lag, acv = (first_ac_peak(hsig, int(0.25 * FPS), int(0.8 * FPS)) if len(hsig) > FPS * 2 else (None, 0)) | |
| period = lag / FPS if lag else None | |
| r.check(0.08, "hop period %.3f s in %.2f-%.2f (autocorr %.2f)" % (period or -1, lo_s, hi_s, acv or 0), | |
| period is not None and lo_s <= period <= hi_s) | |
| wsig = [w for w in med_w if w] | |
| wratio = (max(wsig) / min(wsig)) if wsig and min(wsig) else None | |
| r.check(0.04, "width holds: max/min median width %.2f (< 1.25)" % (wratio or -1), wratio is not None and wratio < 1.25) | |
| amp = hmax - hmin | |
| steps = [abs(hsig[i + 1] - hsig[i]) for i in range(len(hsig) - 1)] | |
| mstep = max(steps) if steps else 0 | |
| r.check(0.04, "eased: largest single-frame height step %d px ≤ 35 %% of amplitude %d" % (mstep, amp), | |
| amp > 0 and mstep <= 0.35 * amp + 1) | |
| # --- D side-step ------------------------------------------------------- | |
| cols = [] | |
| for f in frames: | |
| c = [False] * S | |
| for x in range(S): | |
| for y in range(0, S, 4): | |
| i = 3 * (y * S + x) | |
| if max(f[i], f[i + 1], f[i + 2]) - min(f[i], f[i + 1], f[i + 2]) > 50: | |
| c[x] = True; break | |
| cols.append(c) | |
| shifts = [row_shift(cols[i], cols[i + 1]) for i in range(len(cols) - 1)] | |
| spacings = [] | |
| for a in A: | |
| xs = sorted(b["x0"] for b in a["blobs"] if b["full"]) | |
| spacings += [xs[i + 1] - xs[i] for i in range(len(xs) - 1)] | |
| sp = median(spacings) | |
| total = sum(shifts) | |
| drift = (total / (len(shifts) / FPS) / sp) if sp and shifts else None | |
| lo, hi = BEATS["drift_tol"] | |
| r.check(0.10, "row drifts right %.2f spacings/s in %.2f-%.2f (spacing %s px)" % (drift or 0, lo, hi, sp), | |
| drift is not None and lo <= drift <= hi) | |
| still = (sum(1 for s in shifts if abs(s) <= 1) / len(shifts)) if shifts else 0 | |
| r.check(0.05, "pulsed motion: %.0f %% of frames still (≥ %.0f %%)" % (still * 100, BEATS["still_fraction_min"] * 100), | |
| still >= BEATS["still_fraction_min"] and drift is not None and drift > 0.2) | |
| if spacings and sp: | |
| msp = sum(spacings) / len(spacings) | |
| cv = (sum((s - msp) ** 2 for s in spacings) / len(spacings)) ** 0.5 / msp | |
| else: | |
| cv = None | |
| r.check(0.05, "regular spacing: CV %.2f (< 0.15)" % (cv if cv is not None else -1), cv is not None and cv < 0.15) | |
| # --- E colour ---------------------------------------------------------- | |
| hues = [median([b["hue"] for b in a["blobs"] if b["hue"] is not None]) for a in A] | |
| hues = [h for h in hues if h is not None] | |
| bins = set(int(h // 30) for h in hues) | |
| r.check(0.06, "colour cycles: %d distinct 30° hue bins (≥ %d)" % (len(bins), BEATS["hue_bins_min"]), len(bins) >= BEATS["hue_bins_min"]) | |
| shared = 0 | |
| for a in A: | |
| hh = [b["hue"] for b in a["blobs"] if b["hue"] is not None and b["full"]] | |
| if len(hh) >= 2 and circ_spread(hh) < BEATS["hue_spread_max_deg"]: | |
| shared += 1 | |
| r.check(0.04, "one shared hue per frame (%d/%d frames)" % (shared, n), n > 0 and shared >= 0.8 * n) | |
| changes = sum(1 for i in range(len(hues) - 1) if int(hues[i] // 30) != int(hues[i + 1] // 30)) | |
| rate = changes / (len(hues) / FPS) if hues else 0 | |
| r.check(0.05, "hue changes %.1f bins/s (≥ %.1f)" % (rate, BEATS["hue_changes_per_s_min"]), rate >= BEATS["hue_changes_per_s_min"]) | |
| measured.update({"squash": squash, "period_s": period, "aspect": aspect, "spacing_px": sp, "drift": drift, | |
| "still": still, "hue_bins": len(bins), "hue_rate": rate, "baseline_std": bstd, "max_step": mstep, | |
| "counts_median": median(counts), "heights": hsig[:200], "shifts": shifts[:200]}) | |
| json.dump(measured, open(os.path.join(WORK, "blob-measured.json"), "w"), indent=1) | |
| attempts = terminal_attempts() | |
| score = r.report() | |
| if attempts: | |
| print(" GUI-ONLY GATE: %d terminal attempt(s) logged -> reward 0 (first: %s)" % (len(attempts), attempts[0][:120])) | |
| write_reward(0.0, REWARD_PATH) | |
| score = 0.0 | |
| assert score >= 0.999, "rubric fraction %.3f < 1.0" % score | |