Spaces:
Running
Running
| """ | |
| grader.py (Task 1 β Targeted Vulnerability Detection) | |
| ------------------------------------------------------- | |
| Deterministic grader. Score range: 0.0 β 1.0 | |
| 1.0 β correct function + correct vulnerability keyword | |
| 0.5 β correct function + wrong/unrecognised vulnerability keyword | |
| 0.0 β wrong function name | |
| """ | |
| from __future__ import annotations | |
| from typing import Dict | |
| from utils import SemanticMatcher | |
| class Task1Grader: | |
| def __init__(self, target_function: str, vulnerability_issue: str) -> None: | |
| self.target_function = target_function.lower() | |
| self.vulnerability_issue = vulnerability_issue | |
| def grade_submission(self, submitted_function: str, submitted_vuln_type: str) -> float: | |
| if submitted_function.strip().lower() != self.target_function: | |
| return 0.0 | |
| return 1.0 if SemanticMatcher().match(self.vulnerability_issue, submitted_vuln_type) else 0.5 | |
| def reward_for_score(self, score: float) -> float: | |
| if score == 1.0: return 5.0 | |
| if score == 0.5: return 1.0 | |
| return -1.5 | |
| def get_canonical_answer(self) -> Dict[str, str]: | |
| return {"function": self.target_function, "vulnerability": self.vulnerability_issue} | |