File size: 1,972 Bytes
f884e6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
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.")