Spaces:
Running
Running
"""Helper functions to style our gradio elements""" | |
import re | |
import os | |
def model_hyperlink(link, model_name): | |
return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{model_name}</a>' | |
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): | |
"""Return the direct URL to the assessment report without any formatting""" | |
# Just return the URL string directly | |
return report_url | |
def styled_error(error): | |
return f"<p style='color: red; font-size: 20px; text-align: center;'>{error}</p>" | |
def styled_warning(warn): | |
return f"<p style='color: orange; font-size: 20px; text-align: center;'>{warn}</p>" | |
def styled_message(message): | |
return f"<p style='color: green; font-size: 20px; text-align: center;'>{message}</p>" | |
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'<a href="{github_url}" target="_blank">{library_name}</a>' | |
def styled_message(message) -> str: | |
"""Format a message with a green header""" | |
return f'<span style="color: green">✅ Success:</span> {message}' | |
def styled_warning(message) -> str: | |
"""Format a warning message with an orange header""" | |
return f'<span style="color: orange">⚠️ Warning:</span> {message}' | |
def styled_error(message) -> str: | |
"""Format an error message with a red header""" | |
return f'<span style="color: red">❌ Error:</span> {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'<span style="color: green">{score:.1f}</span>' | |
elif score < 7: | |
return f'<span style="color: orange">{score:.1f}</span>' | |
else: | |
return f'<span style="color: red">{score:.1f}</span>' | |