wenjiao's picture
refactor repo code
b15b21e
import gradio as gr
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, result_file=""):
link = f"https://huggingface.co/{model_name}"
return model_hyperlink(link, model_name)
def styled_error(error: str) -> str:
"""Return a styled error card (HTML)."""
return (
f"<div style='"
f"font-family:Manrope,sans-serif;"
f"background:linear-gradient(135deg,#fef2f2 0%,#fff1f2 100%);"
f"border:1px solid #fca5a5;"
f"border-radius:16px;"
f"padding:18px 24px;"
f"max-width:480px;"
f"margin:16px auto;"
f"box-shadow:0 4px 16px rgba(239,68,68,0.10);"
f"'>"
f"<div style='display:flex;align-items:flex-start;gap:10px;'>"
f"<span style='font-size:20px;flex-shrink:0;'>\u274c</span>"
f"<span style='font-size:14px;font-weight:600;color:#991b1b;line-height:1.5;'>{error}</span>"
f"</div>"
f"</div>"
)
def styled_warning(warn: str) -> str:
"""Return a styled warning card (HTML)."""
return (
f"<div style='"
f"font-family:Manrope,sans-serif;"
f"background:linear-gradient(135deg,#fffbeb 0%,#fef9c3 100%);"
f"border:1px solid #fde68a;"
f"border-radius:16px;"
f"padding:18px 24px;"
f"max-width:480px;"
f"margin:16px auto;"
f"box-shadow:0 4px 16px rgba(234,179,8,0.10);"
f"'>"
f"<div style='display:flex;align-items:flex-start;gap:10px;'>"
f"<span style='font-size:20px;flex-shrink:0;'>\u26a0\ufe0f</span>"
f"<span style='font-size:14px;font-weight:600;color:#92400e;line-height:1.5;'>{warn}</span>"
f"</div>"
f"</div>"
)
def styled_message(message):
gr.Info(message)
return ""
def styled_success(title: str, eta: str, subtitle: str = "") -> str:
"""Return a styled success card with ETA (rendered in the output Markdown area)."""
sub_html = (
f"<div style='font-size:13px;color:#475569;margin-top:6px;'>{subtitle}</div>"
if subtitle else ""
)
return (
f"<div style='"
f"font-family:Manrope,sans-serif;"
f"background:linear-gradient(135deg,#f0fdf4 0%,#ecfdf5 100%);"
f"border:1px solid #86efac;"
f"border-radius:16px;"
f"padding:22px 28px;"
f"max-width:480px;"
f"margin:16px auto;"
f"box-shadow:0 4px 16px rgba(34,197,94,0.10);"
f"'>"
# Title row
f"<div style='display:flex;align-items:center;gap:8px;margin-bottom:8px;'>"
f"<span style='font-size:22px;'>✅</span>"
f"<span style='font-size:15px;font-weight:700;color:#166534;'>{title}</span>"
f"</div>"
# ETA badge
f"<div style='display:inline-flex;align-items:center;gap:6px;"
f"background:#dcfce7;border-radius:20px;padding:6px 16px;'>"
f"<span style='font-size:16px;'>⏱</span>"
f"<span style='font-size:14px;font-weight:600;color:#15803d;'>"
f"Estimated completion time: {eta}</span>"
f"</div>"
f"{sub_html}"
f"</div>"
)
def styled_progress(step: int, total: int, message: str) -> str:
"""Return a styled progress indicator (HTML)."""
pct = min(int(step / total * 100) if total > 0 else 0, 99)
# Dots indicator: filled for completed steps, hollow for remaining
dots = "".join(
"<span style='display:inline-block;width:10px;height:10px;border-radius:50%;"
f"background:{'#2563eb' if i < step else '#cbd5e1'};"
"margin:0 3px;transition:background 0.3s;'></span>"
for i in range(total)
)
return (
f"<div style='"
f"font-family:Manrope,sans-serif;"
f"background:linear-gradient(135deg,#eff6ff 0%,#f0fdf4 100%);"
f"border:1px solid #bfdbfe;"
f"border-radius:16px;"
f"padding:20px 28px;"
f"max-width:520px;"
f"margin:16px auto;"
f"box-shadow:0 4px 16px rgba(37,99,235,0.10);"
f"'>"
# Step label
f"<div style='display:flex;align-items:center;justify-content:space-between;margin-bottom:12px;'>"
f"<span style='font-size:14px;font-weight:600;color:#1e3a8a;'>⚙ {message}</span>"
f"<span style='font-size:12px;font-weight:700;color:#2563eb;"
f"background:#dbeafe;border-radius:20px;padding:2px 10px;'>{step}/{total}</span>"
f"</div>"
# Progress bar
f"<div style='background:#e2e8f0;border-radius:999px;height:8px;overflow:hidden;'>"
f"<div style='height:100%;width:{pct}%;"
f"background:linear-gradient(90deg,#2563eb,#38bdf8);"
f"border-radius:999px;"
f"transition:width 0.4s cubic-bezier(.4,0,.2,1);'>"
f"</div></div>"
# Dots + percentage
f"<div style='display:flex;align-items:center;justify-content:space-between;margin-top:10px;'>"
f"<div>{dots}</div>"
f"<span style='font-size:12px;color:#64748b;font-weight:600;'>{pct}%</span>"
f"</div>"
f"</div>"
)
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)