Spaces:
Running
Running
fixed HF file system issue
Browse files- src/evaluation/evaluator.py +20 -7
src/evaluation/evaluator.py
CHANGED
|
@@ -77,11 +77,11 @@ class RAGEvaluator:
|
|
| 77 |
self._load_existing_results()
|
| 78 |
|
| 79 |
def _load_existing_results(self):
|
| 80 |
-
"""Load existing results from disk."""
|
| 81 |
results_file = self.results_dir / "results.jsonl"
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
if results_file.exists():
|
| 86 |
try:
|
| 87 |
with open(results_file, 'r') as f:
|
|
@@ -89,10 +89,23 @@ class RAGEvaluator:
|
|
| 89 |
data = json.loads(line)
|
| 90 |
data['hallucination_detected'] = bool(data['hallucination_detected'])
|
| 91 |
self.results.append(EvaluationResult(**data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
except Exception as e:
|
| 93 |
-
|
| 94 |
-
f"Failed to load evaluation results from {results_file}"
|
| 95 |
-
) from e
|
| 96 |
|
| 97 |
def add_result(self, result: EvaluationResult) -> None:
|
| 98 |
"""Add evaluation result."""
|
|
|
|
| 77 |
self._load_existing_results()
|
| 78 |
|
| 79 |
def _load_existing_results(self):
|
| 80 |
+
"""Load existing results from disk or HF raw URL."""
|
| 81 |
results_file = self.results_dir / "results.jsonl"
|
| 82 |
+
loaded = False
|
| 83 |
+
|
| 84 |
+
# Try local file first
|
| 85 |
if results_file.exists():
|
| 86 |
try:
|
| 87 |
with open(results_file, 'r') as f:
|
|
|
|
| 89 |
data = json.loads(line)
|
| 90 |
data['hallucination_detected'] = bool(data['hallucination_detected'])
|
| 91 |
self.results.append(EvaluationResult(**data))
|
| 92 |
+
loaded = True
|
| 93 |
+
except Exception as e:
|
| 94 |
+
print(f"Warning: Could not load local results: {e}")
|
| 95 |
+
|
| 96 |
+
# If no local file or failed, try HF raw URL
|
| 97 |
+
if not loaded:
|
| 98 |
+
hf_url = "https://huggingface.co/spaces/aankitdas/doc-intelligence-rag/raw/main/evaluation_results/results.jsonl"
|
| 99 |
+
try:
|
| 100 |
+
resp = requests.get(hf_url)
|
| 101 |
+
resp.raise_for_status()
|
| 102 |
+
for line in resp.text.strip().split("\n"):
|
| 103 |
+
data = json.loads(line)
|
| 104 |
+
data['hallucination_detected'] = bool(data['hallucination_detected'])
|
| 105 |
+
self.results.append(EvaluationResult(**data))
|
| 106 |
+
print(f"Loaded {len(self.results)} results from HF raw URL")
|
| 107 |
except Exception as e:
|
| 108 |
+
print(f"Warning: Could not load results from HF: {e}")
|
|
|
|
|
|
|
| 109 |
|
| 110 |
def add_result(self, result: EvaluationResult) -> None:
|
| 111 |
"""Add evaluation result."""
|