Spaces:
Running
Running
File size: 3,011 Bytes
bccaf50 8558676 bccaf50 9ab539a 8558676 b5628ea 8558676 b5628ea 8558676 b5628ea 8558676 b5628ea 8558676 9ab539a bccaf50 |
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 92 93 94 95 |
"""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):
"""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"<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>'
|