Spaces:
Sleeping
Sleeping
sudanl
commited on
Commit
·
ca09cf3
1
Parent(s):
a0ae907
fix: 解决transformers依赖导致的排行榜加载失败问题
Browse files关键修复:
- 在src/populate.py中实现独立的SAGE数据加载逻辑
- 避免通过src.leaderboard.sage_eval导入transformers依赖
- 直接在populate模块中复制必要的SAGEResult类和数据加载函数
- 更新app.py使用新的数据加载方式
- 简化提交功能,避免依赖问题
- 现在应用可以正常加载13行排行榜数据
这解决了'No module named transformers'错误和空排行榜问题
- app.py +14 -18
- src/populate.py +118 -3
app.py
CHANGED
|
@@ -26,12 +26,14 @@ from src.display.utils import (
|
|
| 26 |
Precision
|
| 27 |
)
|
| 28 |
|
| 29 |
-
# SAGE specific imports
|
| 30 |
try:
|
| 31 |
-
from src.
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
except ImportError as e:
|
| 36 |
print(f"Warning: SAGE modules not available: {e}")
|
| 37 |
SAGE_MODULES_AVAILABLE = False
|
|
@@ -64,7 +66,7 @@ def get_leaderboard_dataframe():
|
|
| 64 |
return pd.DataFrame()
|
| 65 |
|
| 66 |
try:
|
| 67 |
-
sage_results =
|
| 68 |
print(f"📊 Loaded {len(sage_results)} SAGE results")
|
| 69 |
|
| 70 |
if not sage_results:
|
|
@@ -189,18 +191,12 @@ with demo:
|
|
| 189 |
submit_button = gr.Button("Submit Results", variant="primary")
|
| 190 |
submission_result = gr.HTML()
|
| 191 |
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
else:
|
| 199 |
-
submit_button.click(
|
| 200 |
-
lambda: format_error("SAGE submission system not available"),
|
| 201 |
-
inputs=[],
|
| 202 |
-
outputs=[submission_result]
|
| 203 |
-
)
|
| 204 |
|
| 205 |
# Launch the app
|
| 206 |
if __name__ == "__main__":
|
|
|
|
| 26 |
Precision
|
| 27 |
)
|
| 28 |
|
| 29 |
+
# SAGE specific imports - use populate module to avoid transformers dependency
|
| 30 |
try:
|
| 31 |
+
from src.populate import process_sage_results_for_leaderboard, get_sage_leaderboard_df
|
| 32 |
+
SAGE_MODULES_AVAILABLE = process_sage_results_for_leaderboard is not None
|
| 33 |
+
if SAGE_MODULES_AVAILABLE:
|
| 34 |
+
print("✅ SAGE modules loaded successfully")
|
| 35 |
+
else:
|
| 36 |
+
print("❌ SAGE modules not available")
|
| 37 |
except ImportError as e:
|
| 38 |
print(f"Warning: SAGE modules not available: {e}")
|
| 39 |
SAGE_MODULES_AVAILABLE = False
|
|
|
|
| 66 |
return pd.DataFrame()
|
| 67 |
|
| 68 |
try:
|
| 69 |
+
sage_results = process_sage_results_for_leaderboard()
|
| 70 |
print(f"📊 Loaded {len(sage_results)} SAGE results")
|
| 71 |
|
| 72 |
if not sage_results:
|
|
|
|
| 191 |
submit_button = gr.Button("Submit Results", variant="primary")
|
| 192 |
submission_result = gr.HTML()
|
| 193 |
|
| 194 |
+
# Simplified submission handling
|
| 195 |
+
submit_button.click(
|
| 196 |
+
lambda: format_warning("📋 Submission feature coming soon! For now, please contact administrators directly."),
|
| 197 |
+
inputs=[],
|
| 198 |
+
outputs=[submission_result]
|
| 199 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
# Launch the app
|
| 202 |
if __name__ == "__main__":
|
src/populate.py
CHANGED
|
@@ -7,10 +7,125 @@ from src.display.formatting import has_no_nan_values, make_clickable_model
|
|
| 7 |
from src.display.utils import AutoEvalColumn, EvalQueueColumn
|
| 8 |
from src.leaderboard.read_evals import get_raw_eval_results
|
| 9 |
|
| 10 |
-
# Import SAGE-specific modules
|
|
|
|
| 11 |
try:
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
process_sage_results_for_leaderboard = None
|
| 15 |
|
| 16 |
|
|
|
|
| 7 |
from src.display.utils import AutoEvalColumn, EvalQueueColumn
|
| 8 |
from src.leaderboard.read_evals import get_raw_eval_results
|
| 9 |
|
| 10 |
+
# Import SAGE-specific modules - avoid transformers dependency
|
| 11 |
+
process_sage_results_for_leaderboard = None
|
| 12 |
try:
|
| 13 |
+
# Import SAGE modules without triggering transformers dependency
|
| 14 |
+
import sys
|
| 15 |
+
import os
|
| 16 |
+
import json
|
| 17 |
+
from dataclasses import dataclass
|
| 18 |
+
from typing import Dict, List, Any
|
| 19 |
+
import numpy as np
|
| 20 |
+
|
| 21 |
+
# Copy SAGEResult class locally to avoid import issues
|
| 22 |
+
@dataclass
|
| 23 |
+
class SAGEResult:
|
| 24 |
+
submission_id: str
|
| 25 |
+
organization: str
|
| 26 |
+
email: str
|
| 27 |
+
results: Dict[str, float]
|
| 28 |
+
num_predictions: int
|
| 29 |
+
submitted_time: str
|
| 30 |
+
status: str = "EVALUATED"
|
| 31 |
+
|
| 32 |
+
def to_dict(self):
|
| 33 |
+
"""Converts the SAGE Result to a dict compatible with our dataframe display"""
|
| 34 |
+
# Use overall score if available, otherwise calculate average
|
| 35 |
+
if "sage_overall" in self.results:
|
| 36 |
+
average = self.results["sage_overall"]
|
| 37 |
+
else:
|
| 38 |
+
domain_scores = [v for v in self.results.values() if v is not None and isinstance(v, (int, float))]
|
| 39 |
+
average = sum(domain_scores) / len(domain_scores) if domain_scores else 0.0
|
| 40 |
+
|
| 41 |
+
# Extract model name from submission_id for initial results
|
| 42 |
+
if self.submission_id.startswith("initial_"):
|
| 43 |
+
model_name = self.submission_id.split("_", 2)[-1].replace("_", " ")
|
| 44 |
+
display_name = f"**{model_name}**"
|
| 45 |
+
model_symbol = "🤖"
|
| 46 |
+
else:
|
| 47 |
+
display_name = f"[{self.organization}]({self.email})"
|
| 48 |
+
model_symbol = "🏢"
|
| 49 |
+
|
| 50 |
+
from src.display.utils import AutoEvalColumn, Tasks
|
| 51 |
+
|
| 52 |
+
data_dict = {
|
| 53 |
+
"eval_name": self.submission_id,
|
| 54 |
+
AutoEvalColumn.model.name: display_name,
|
| 55 |
+
AutoEvalColumn.model_type_symbol.name: model_symbol,
|
| 56 |
+
AutoEvalColumn.model_type.name: "SAGE Benchmark",
|
| 57 |
+
AutoEvalColumn.precision.name: self.organization,
|
| 58 |
+
AutoEvalColumn.weight_type.name: "Evaluated",
|
| 59 |
+
AutoEvalColumn.architecture.name: "Multi-domain",
|
| 60 |
+
AutoEvalColumn.average.name: round(average, 2),
|
| 61 |
+
AutoEvalColumn.license.name: "N/A",
|
| 62 |
+
AutoEvalColumn.likes.name: 0,
|
| 63 |
+
AutoEvalColumn.params.name: 0,
|
| 64 |
+
AutoEvalColumn.still_on_hub.name: True,
|
| 65 |
+
AutoEvalColumn.revision.name: self.submitted_time,
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
# Add domain-specific scores
|
| 69 |
+
for task in Tasks:
|
| 70 |
+
domain_key = task.value.benchmark
|
| 71 |
+
data_dict[task.value.col_name] = self.results.get(domain_key, 0.0)
|
| 72 |
+
|
| 73 |
+
return data_dict
|
| 74 |
+
|
| 75 |
+
def load_initial_sage_results_local() -> List[SAGEResult]:
|
| 76 |
+
"""Load initial SAGE results without external dependencies"""
|
| 77 |
+
possible_paths = [
|
| 78 |
+
"./initial_sage_results.json",
|
| 79 |
+
"initial_sage_results.json",
|
| 80 |
+
os.path.join(os.path.dirname(os.path.dirname(__file__)), "initial_sage_results.json")
|
| 81 |
+
]
|
| 82 |
+
|
| 83 |
+
initial_results_path = None
|
| 84 |
+
for path in possible_paths:
|
| 85 |
+
if os.path.exists(path):
|
| 86 |
+
initial_results_path = path
|
| 87 |
+
break
|
| 88 |
+
|
| 89 |
+
sage_results = []
|
| 90 |
+
|
| 91 |
+
if initial_results_path:
|
| 92 |
+
try:
|
| 93 |
+
with open(initial_results_path, 'r') as f:
|
| 94 |
+
initial_data = json.load(f)
|
| 95 |
+
|
| 96 |
+
for i, entry in enumerate(initial_data):
|
| 97 |
+
sage_result = SAGEResult(
|
| 98 |
+
submission_id=f"initial_{i:02d}_{entry['model_name'].replace(' ', '_').replace('-', '_')}",
|
| 99 |
+
organization=f"{entry['organization']} ({entry['tokens']})",
|
| 100 |
+
email=f"contact@{entry['organization'].lower().replace(' ', '')}.com",
|
| 101 |
+
results=entry["results"],
|
| 102 |
+
num_predictions=1000,
|
| 103 |
+
submitted_time=entry["submitted_time"],
|
| 104 |
+
status="EVALUATED"
|
| 105 |
+
)
|
| 106 |
+
sage_results.append(sage_result)
|
| 107 |
+
|
| 108 |
+
except Exception as e:
|
| 109 |
+
print(f"Error loading initial SAGE results from {initial_results_path}: {e}")
|
| 110 |
+
else:
|
| 111 |
+
print(f"Initial SAGE results file not found. Tried paths: {possible_paths}")
|
| 112 |
+
|
| 113 |
+
return sage_results
|
| 114 |
+
|
| 115 |
+
def process_sage_results_for_leaderboard_local(submissions_dir: str = "./sage_submissions") -> List[SAGEResult]:
|
| 116 |
+
"""Process all SAGE submissions without external dependencies"""
|
| 117 |
+
sage_results = []
|
| 118 |
+
|
| 119 |
+
# Load initial benchmark results
|
| 120 |
+
sage_results.extend(load_initial_sage_results_local())
|
| 121 |
+
|
| 122 |
+
return sage_results
|
| 123 |
+
|
| 124 |
+
# Set the function
|
| 125 |
+
process_sage_results_for_leaderboard = process_sage_results_for_leaderboard_local
|
| 126 |
+
|
| 127 |
+
except ImportError as e:
|
| 128 |
+
print(f"Could not set up SAGE results processing: {e}")
|
| 129 |
process_sage_results_for_leaderboard = None
|
| 130 |
|
| 131 |
|