File size: 1,726 Bytes
d4d998a |
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 |
"""
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>
"""
|