Spaces:
Runtime error
Runtime error
| """End-to-end demo: analyze the four test submissions, write HTML reports, | |
| check verdicts against ground truth, and run one feedback-learning round. | |
| """ | |
| import json | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from plagdetect.pipeline import PlagiarismPipeline # noqa: E402 | |
| from plagdetect.report import write_html # noqa: E402 | |
| ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| SUB_DIR = os.path.join(ROOT, "data", "submissions") | |
| REPORT_DIR = os.path.join(ROOT, "reports") | |
| def main(): | |
| os.makedirs(REPORT_DIR, exist_ok=True) | |
| pipe = PlagiarismPipeline(os.path.join(ROOT, "data", "corpus"), | |
| os.path.join(ROOT, "models")) | |
| with open(os.path.join(SUB_DIR, "truth.json"), "r", encoding="utf-8") as f: | |
| truth = json.load(f) | |
| rows, last_finding = [], None | |
| for name in ["clean", "clone", "mosaic", "idea"]: | |
| print(f"\n=== Analyzing {name}.txt " + "=" * 40) | |
| result = pipe.analyze(os.path.join(SUB_DIR, f"{name}.txt")) | |
| out = os.path.join(REPORT_DIR, f"report_{name}.html") | |
| write_html(result, out) | |
| ok = result["verdict"] in truth[name] | |
| rows.append((name, result["verdict"], "/".join(truth[name]), | |
| f"{result['overall_score']:.2f}", "PASS" if ok else "FAIL")) | |
| print(f"[report] {out}") | |
| if name == "clone" and result["findings"]: | |
| last_finding = max(result["findings"], key=lambda x: x["score"]) | |
| print("\n" + "=" * 64) | |
| print(f"{'submission':<12}{'verdict':<14}{'expected':<26}{'score':<8}check") | |
| for r in rows: | |
| print(f"{r[0]:<12}{r[1]:<14}{r[2]:<26}{r[3]:<8}{r[4]}") | |
| if last_finding is not None: | |
| print("\n[feedback loop] reviewer CONFIRMS the clone finding ->") | |
| w = pipe.feedback(last_finding, confirmed=True) | |
| print(f" updated evidence weights: {w}") | |
| print(f" bandit interventional means E[r|do(arm)]: " | |
| f"{pipe.bandit.interventional_means().round(3).tolist()}") | |
| if __name__ == "__main__": | |
| main() | |