CoolFace
Apppublic

Ar-Srivas/BitWise_CSS_env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
reward.py59 linesDownload Raw Back to root
1def compute_reward(2    scores,3    action_valid=True,4    done=False,5    action_repeated=False,6    action_duplicate=False,7    action_irrelevant=False,8    previous_scores=None,9    previous_reward=None,10):11    reward = (12        0.30 * scores.get("color", 0) +13        0.20 * scores.get("spacing", 0) +14        0.20 * scores.get("typography", 0) +15        0.20 * scores.get("contrast", 0) +16        0.10 * scores.get("cleanliness", 0)17    )18 19    progress_bonus = 0.020    if previous_scores:21        tracked = ["color", "spacing", "typography", "contrast", "layout", "cleanliness", "design_quality"]22        deltas = [scores.get(k, 0.0) - previous_scores.get(k, 0.0) for k in tracked]23        avg_delta = sum(deltas) / float(len(tracked))24 25        if avg_delta > 0:26            progress_bonus += min(0.12, avg_delta * 0.8)27        elif avg_delta < 0:28            progress_bonus += max(-0.10, avg_delta * 0.5)29        else:30            progress_bonus -= 0.0231 32    reward += progress_bonus33 34    if not action_valid:35        reward -= 0.1036    if action_repeated:37        reward -= 0.0538    if action_duplicate:39        reward -= 0.0740    if action_irrelevant:41        reward -= 0.0842 43    if done and all(v >= 0.95 for v in scores.values()):44        reward += 0.3545 46    # Keep step-to-step reward progression smooth to reduce spikes.47    if previous_reward is not None:48        prev = float(previous_reward)49        penalized = (not action_valid) or action_repeated or action_duplicate or action_irrelevant50 51        if penalized:52            # Penalized steps should not look like progress.53            reward = min(reward, prev - 0.03)54        else:55            delta = reward - prev56            delta = max(-0.12, min(0.18, delta))57            reward = prev + delta58 59    return float(max(0.0, min(1.2, reward)))