| files = ["src/eval/__init__.py", "src/eval/generation.py"] | |
| imports = [(".clipscore","CLIPScoreEvaluator"),(".vqascore","VQAScoreEvaluator"), | |
| (".geneval","GenEvalEvaluator"),(".dpgbench","DPGEvaluator")] | |
| for fp in files: | |
| s = open(fp).read() | |
| for mod,cls in imports: | |
| old = f"from {mod} import {cls}" | |
| new = f"try:\n from {mod} import {cls}\nexcept Exception:\n {cls} = None" | |
| if old in s and ("try:\n from "+mod) not in s: | |
| s = s.replace(old, new) | |
| open(fp,"w").write(s) | |
| print("patched", fp) | |
| print("PATCH_DONE") | |