"""Helper functions to style our gradio elements""" import re import os def model_hyperlink(link, model_name): return f'{model_name}' def make_clickable_model(model_name): link = f"https://huggingface.co/{model_name}" return model_hyperlink(link, model_name) def make_clickable_report(report_url): """Create a clickable link to the assessment report If the report_url is a full URL (starts with http), use it directly Otherwise, assume it's a local file path and construct a local link using Gradio's markdown format that works in table cells. """ if not report_url: return "" # Check if this is a URL or local file reference if report_url.startswith("http"): # External URL, use markdown format return f"[📝 View Report]({report_url})" else: # Local file reference, create a relative path to the public directory # Use Gradio's file URL format which renders correctly in markdown cells report_path = f"file/reports/{report_url}" return f"[📝 Report]({report_path})" def styled_error(error): return f"

{error}

" def styled_warning(warn): return f"

{warn}

" def styled_message(message): return f"

{message}

" def has_no_nan_values(df, columns): return df[columns].notna().all(axis=1) def has_nan_values(df, columns): return df[columns].isna().any(axis=1) def make_clickable_library(library_name: str) -> str: """Link to the GitHub repository""" library_path = library_name.replace(" ", "-").lower() # If this is a GitHub repository, link directly github_url = f"https://github.com/{library_path}" return f'{library_name}' def styled_message(message) -> str: """Format a message with a green header""" return f'✅ Success: {message}' def styled_warning(message) -> str: """Format a warning message with an orange header""" return f'⚠️ Warning: {message}' def styled_error(message) -> str: """Format an error message with a red header""" return f'❌ Error: {message}' # Risk severity coloring for risk scores def colorize_risk_score(score): """ Apply color coding to risk scores: 0-3.9: Green (Low risk) 4-6.9: Orange (Medium risk) 7-10: Red (High risk) """ if score < 4: return f'{score:.1f}' elif score < 7: return f'{score:.1f}' else: return f'{score:.1f}'