Spaces:
Running
Running
File size: 2,659 Bytes
ed2eb44 06d4ee9 ed2eb44 06d4ee9 ed2eb44 |
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
"""
Data processing utilities for the leaderboard application.
"""
import pandas as pd
import numpy as np
def apply_value_formatting(value, is_numeric=True):
"""
Apply formatting to a value based on its properties
Args:
value: The value to format
is_numeric (bool): Whether the value is numeric
Returns:
dict: Dictionary with formatting information
"""
if not is_numeric or value == '-':
return {'value': value, 'class': ''}
numeric_value = float(value)
if numeric_value > 0:
return {'value': value, 'class': 'positive-value'}
elif numeric_value < 0:
return {'value': value, 'class': 'negative-value'}
else:
return {'value': value, 'class': ''}
def get_model_type_style(model_type):
"""
Get styling for different model types
Args:
model_type (str): The model type
Returns:
dict: Dictionary with styling information
"""
if model_type == "Open Source":
return {'color': '#4ade80'} # Brighter green
elif model_type == "Open Weights":
return {'color': '#93c5fd'} # Brighter blue
elif model_type == "Closed Source":
return {'color': '#cbd5e1'} # Lighter gray
elif model_type == "Human":
return {'color': '#f472b6', 'font-weight': '600'} # Pink with emphasis for Human
else:
return {'color': ''}
def get_rank_style(rank):
"""
Get styling for different ranks
Args:
rank (str): The rank
Returns:
dict: Dictionary with styling information
"""
if "🥇" in str(rank):
return {'color': 'gold', 'font-weight': '700', 'font-size': '16px'}
elif "🥈" in str(rank):
return {'color': 'silver', 'font-weight': '700', 'font-size': '16px'}
elif "🥉" in str(rank):
return {'color': '#cd7f32', 'font-weight': '700', 'font-size': '16px'}
elif str(rank) == "-":
return {'color': '#f472b6', 'font-style': 'italic'} # Style for non-ranked (human)
else:
return {}
def calculate_task_statistics(metric_data):
"""
Calculate statistics for each task
Args:
metric_data (dict): Dictionary containing the metric data
Returns:
dict: Dictionary with task statistics
"""
stats = {}
for task, models in metric_data.items():
values = list(models.values())
stats[task] = {
'mean': np.mean(values),
'median': np.median(values),
'min': min(values),
'max': max(values),
'std': np.std(values)
}
return stats |