"""Generate the HTML/CSS card preview for the Gradio UI.""" from src.scoring import CardData STYLE_THEMES = { "Starter": { "bg": "linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%)", "accent": "#6366f1", "accent2": "#818cf8", "text": "#1f2937", "subtext": "#4b5563", "card": "#ffffff", "shine": "rgba(255,255,255,0.6)", }, "Legendary": { "bg": "linear-gradient(135deg, #fff1c1 0%, #ff8a00 100%)", "accent": "#b45309", "accent2": "#f59e0b", "text": "#451a03", "subtext": "#78350f", "card": "#fffbeb", "shine": "rgba(255,255,255,0.7)", }, "Dark Mode": { "bg": "linear-gradient(135deg, #0f172a 0%, #4c1d95 100%)", "accent": "#22d3ee", "accent2": "#a855f7", "text": "#f8fafc", "subtext": "#cbd5e1", "card": "#1e293b", "shine": "rgba(255,255,255,0.15)", }, "Researcher": { "bg": "linear-gradient(135deg, #e0f2fe 0%, #0ea5e9 100%)", "accent": "#0369a1", "accent2": "#38bdf8", "text": "#082f49", "subtext": "#0c4a6e", "card": "#f0f9ff", "shine": "rgba(255,255,255,0.6)", }, "Builder": { "bg": "linear-gradient(135deg, #ffedd5 0%, #f97316 100%)", "accent": "#c2410c", "accent2": "#fb923c", "text": "#431407", "subtext": "#7c2d12", "card": "#fff7ed", "shine": "rgba(255,255,255,0.6)", }, "Esport": { "bg": "linear-gradient(135deg, #1a0505 0%, #dc2626 100%)", "accent": "#facc15", "accent2": "#ef4444", "text": "#fef2f2", "subtext": "#fecaca", "card": "#450a0a", "shine": "rgba(255,255,255,0.2)", }, } RARITY_GLYPHS = { "Common": "★", "Rare": "★★", "Epic": "★★★", "Legendary": "★★★★", } def _stat_bar(label: str, value: int, theme: dict) -> str: return f"""
{label}{value}
""" def render_card_html(card: CardData, style: str = "Starter", share_url: str = "") -> str: theme = STYLE_THEMES.get(style, STYLE_THEMES["Starter"]) rarity_glyph = RARITY_GLYPHS.get(card.rarity, "★") attacks = " · ".join(card.attacks) if card.attacks else "Learning" stats_html = "".join( [ _stat_bar("MODEL", card.stats.model, theme), _stat_bar("DATA", card.stats.data, theme), _stat_bar("SPACE", card.stats.space, theme), _stat_bar("IMPACT", card.stats.impact, theme), _stat_bar("COMMUNITY", card.stats.community, theme), _stat_bar("DOCS", card.stats.docs, theme), ] ) share_hint = f"""
Share: {share_url or f'/api/card/{card.username}.png'}
""" return f"""
AI Trainer Card

{card.display_name}

{rarity_glyph}
{card.rarity}
Type
{card.type}
Level
{card.level}
{stats_html}
Attacks
{attacks}
Passive
{card.passive}
Evolution
{card.evolution}
🤗 {card.total_models} models · {card.total_datasets} datasets · {card.total_spaces} spaces ❤️ {card.total_likes} · ⬇️ {card.total_downloads}
{share_hint}
"""