Spaces:
Sleeping
Sleeping
| """ | |
| Wrapper for basic evaluation runner to support HF Spaces deployment. | |
| Attempts to load the real `evaluation/run_evaluation.py` from common repository | |
| locations and re-export `run_eval` and `citation_matches`. Falls back to | |
| stubs that raise ImportError with clear instructions. | |
| """ | |
| import importlib.util | |
| import os | |
| from typing import Optional | |
| def _load_from_candidate(candidate_dir: str) -> Optional[object]: | |
| path = os.path.join(candidate_dir, "run_evaluation.py") | |
| if not os.path.exists(path): | |
| return None | |
| spec = importlib.util.spec_from_file_location("run_evaluation_impl", path) | |
| if spec is None or spec.loader is None: | |
| return None | |
| mod = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(mod) | |
| return mod | |
| _candidates = [ | |
| os.path.join(os.path.dirname(__file__), "..", "..", "evaluation"), | |
| os.path.join(os.path.dirname(__file__), "..", "evaluation"), | |
| os.path.join(os.getcwd(), "evaluation"), | |
| ] | |
| _impl = None | |
| for c in _candidates: | |
| mod = _load_from_candidate(os.path.abspath(c)) | |
| if mod: | |
| _impl = mod | |
| break | |
| if _impl is not None: | |
| run_eval = getattr(_impl, "run_eval", None) | |
| citation_matches = getattr(_impl, "citation_matches", None) | |
| if run_eval is None: | |
| def run_eval(*args, **kwargs): | |
| raise ImportError("run_eval not found in loaded run_evaluation implementation") | |
| if citation_matches is None: | |
| def citation_matches(*args, **kwargs): | |
| raise ImportError("citation_matches not found in loaded run_evaluation implementation") | |
| else: | |
| def run_eval(*args, **kwargs): | |
| raise ImportError( | |
| "run_evaluation implementation not found in deployment. " | |
| "Ensure the repository 'evaluation/run_evaluation.py' is present in the container." | |
| ) | |
| def citation_matches(*args, **kwargs): | |
| raise ImportError("citation_matches not found because run_evaluation implementation is missing.") | |