apsys's picture
init
d4d998a
raw
history blame
1.73 kB
"""
Formatting utilities for the GuardBench Leaderboard.
"""
import pandas as pd
import numpy as np
def make_clickable_model(model_name: str) -> str:
"""
Create a clickable link for a model name.
"""
return f'<a href="https://huggingface.co/{model_name}" target="_blank">{model_name}</a>'
def has_no_nan_values(df: pd.DataFrame, columns: list) -> pd.Series:
"""
Check if a row has no NaN values in the specified columns.
"""
return ~df[columns].isna().any(axis=1)
def format_percentage(value: float) -> str:
"""
Format a value as a percentage.
"""
if pd.isna(value):
return "N/A"
return f"{value * 100:.2f}%"
def format_number(value: float, precision: int = 2) -> str:
"""
Format a number with specified precision.
"""
if pd.isna(value):
return "N/A"
return f"{value:.{precision}f}"
def styled_message(message: str) -> str:
"""
Format a success message with styling.
"""
return f"""
<div style="padding: 10px; border-radius: 5px; background-color: #e6f7e6; color: #2e7d32; border: 1px solid #2e7d32;">
{message}
</div>
"""
def styled_warning(message: str) -> str:
"""
Format a warning message with styling.
"""
return f"""
<div style="padding: 10px; border-radius: 5px; background-color: #fff8e1; color: #ff8f00; border: 1px solid #ff8f00;">
⚠️ {message}
</div>
"""
def styled_error(message: str) -> str:
"""
Format an error message with styling.
"""
return f"""
<div style="padding: 10px; border-radius: 5px; background-color: #ffebee; color: #c62828; border: 1px solid #c62828;">
{message}
</div>
"""