Spaces:
Running
Running
Refactor annotation loading to use DATASET_ANNOTATIONS_PATH and handle errors more gracefully
Browse files- src/analytics/chat_evaluator.py +18 -12
src/analytics/chat_evaluator.py
CHANGED
|
@@ -8,7 +8,7 @@ import datetime
|
|
| 8 |
from typing import List, Dict, Any, Tuple, Optional
|
| 9 |
import io
|
| 10 |
import logging
|
| 11 |
-
from huggingface_hub import HfApi
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
|
@@ -296,18 +296,23 @@ class ChatEvaluator:
|
|
| 296 |
Returns:
|
| 297 |
Annotation object or None if not found
|
| 298 |
"""
|
| 299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
return None
|
| 301 |
-
|
| 302 |
-
filepath = os.path.join(self.annotations_dir, f"annotation_{conversation_id}.json")
|
| 303 |
-
if os.path.exists(filepath):
|
| 304 |
-
try:
|
| 305 |
-
with open(filepath, 'r', encoding='utf-8') as f:
|
| 306 |
-
return json.load(f)
|
| 307 |
-
except Exception as e:
|
| 308 |
-
print(f"Error loading annotation for {conversation_id}: {str(e)}")
|
| 309 |
-
|
| 310 |
-
return None
|
| 311 |
|
| 312 |
def export_training_data(self, output_file: str, min_rating: int = 4) -> Tuple[bool, str]:
|
| 313 |
"""
|
|
@@ -417,3 +422,4 @@ class ChatEvaluator:
|
|
| 417 |
|
| 418 |
|
| 419 |
|
|
|
|
|
|
| 8 |
from typing import List, Dict, Any, Tuple, Optional
|
| 9 |
import io
|
| 10 |
import logging
|
| 11 |
+
#from huggingface_hub import HfApi
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
|
|
|
|
| 296 |
Returns:
|
| 297 |
Annotation object or None if not found
|
| 298 |
"""
|
| 299 |
+
try:
|
| 300 |
+
# Используем DATASET_ANNOTATIONS_PATH для формирования пути
|
| 301 |
+
filename = f"{DATASET_ANNOTATIONS_PATH}/annotation_{conversation_id}.json"
|
| 302 |
+
|
| 303 |
+
# Download and parse annotation file
|
| 304 |
+
content = self.api.hf_hub_download(
|
| 305 |
+
repo_id=self.dataset_id,
|
| 306 |
+
filename=filename,
|
| 307 |
+
repo_type="dataset"
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
with open(content, 'r', encoding='utf-8') as f:
|
| 311 |
+
return json.load(f)
|
| 312 |
+
|
| 313 |
+
except Exception as e:
|
| 314 |
+
logger.error(f"Error loading annotation for {conversation_id}: {e}")
|
| 315 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
def export_training_data(self, output_file: str, min_rating: int = 4) -> Tuple[bool, str]:
|
| 318 |
"""
|
|
|
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
+
|