File size: 8,955 Bytes
71c1a2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f81c4b
 
 
 
 
 
 
 
 
 
0fd60fa
71c1a2d
 
 
8f81c4b
71c1a2d
 
 
 
 
 
 
 
 
adcf0d8
71c1a2d
 
 
 
 
 
0fd60fa
 
adcf0d8
 
 
 
 
 
 
 
 
 
 
0fd60fa
 
 
 
 
4b7a0f2
0fd60fa
 
 
 
 
 
 
 
 
71c1a2d
 
 
 
 
 
 
 
 
0fd60fa
 
71c1a2d
 
 
 
 
0fd60fa
71c1a2d
 
 
 
 
 
 
 
 
c72acc1
 
71c1a2d
 
 
0fd60fa
 
 
 
8f81c4b
 
0fd60fa
 
 
 
8f81c4b
0fd60fa
 
 
 
 
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""CraterView.ai's colours and type for the page: dark in both of the visitor's themes."""
from __future__ import annotations

import gradio as gr

GROUND, SOFT, PANEL, RULE = "#070b0d", "#0d1417", "#121a1e", "#203037"
INK, QUIET, ACCENT, LIFT, SAND = "#e9f1f3", "#8ea2a9", "#2f7d6a", "#58b39a", "#b29669"
BUTTON = "linear-gradient(135deg, #2f7d6a, #2f6f96)"

_colours = dict(
    body_background_fill=GROUND, body_text_color=INK, body_text_color_subdued=QUIET,
    background_fill_primary=GROUND, background_fill_secondary=SOFT,
    border_color_primary=RULE, border_color_accent=ACCENT,
    color_accent_soft=SOFT, link_text_color=LIFT, link_text_color_hover=INK,
    link_text_color_active=INK, link_text_color_visited=LIFT,
    block_background_fill=PANEL, block_border_color=RULE, block_label_background_fill=PANEL,
    block_label_text_color=QUIET, block_title_text_color=INK, block_info_text_color=QUIET,
    input_background_fill=SOFT, input_border_color=RULE,
    button_primary_background_fill=BUTTON, button_primary_background_fill_hover=BUTTON,
    button_primary_text_color="#ffffff", button_primary_border_color=ACCENT,
    button_secondary_background_fill=SOFT, button_secondary_background_fill_hover=PANEL,
    button_secondary_text_color=INK, button_secondary_border_color=RULE,
    checkbox_background_color=SOFT, checkbox_background_color_selected=ACCENT,
    checkbox_border_color=QUIET, checkbox_border_color_selected=ACCENT,
    checkbox_label_background_fill=SOFT, checkbox_label_background_fill_hover=PANEL,
    checkbox_label_background_fill_selected=ACCENT, checkbox_label_border_color=RULE,
    checkbox_label_text_color=INK, checkbox_label_text_color_selected="#ffffff",
)

THEME = gr.themes.Base(
    font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"],
    radius_size=gr.themes.sizes.radius_lg,
).set(
    color_accent=ACCENT, block_radius="14px", button_large_radius="10px",
    button_large_text_weight="560", block_border_width="1px", block_shadow="none",
    **_colours, **{f"{name}_dark": value for name, value in _colours.items()},
)

# The page's own root, named twice (`_raised`).
_ROOT = ".gradio-container.gradio-container"

# Hugging Face draws its name badge, 42 px tall and 12 px from the top, over a Space opened at its
# own address, and not over one framed by huggingface.co. The script marks the page when it is not
# framed, and the headline then has room above it for the badge, there and nowhere else.
UNFRAMED = "cv-unframed"
HEAD = (f'<script>if (window.top === window.self) '
        f'document.documentElement.classList.add("{UNFRAMED}");</script>')

_RULES = f"""
.gradio-container {{ max-width: 1140px !important; margin: 0 auto !important; }}
.cv-headline {{ font-size: clamp(1.75rem, 4.2vw, 2.5rem); line-height: 1.15; font-weight: 700;
  letter-spacing: -0.02em; margin: 0 0 8px; color: {INK}; }}
html.{UNFRAMED} {_ROOT} .cv-headline {{ margin-top: 48px; }}
.cv-headline em {{ font-style: normal; color: transparent; background-clip: text;
  -webkit-background-clip: text;
  background-image: linear-gradient(120deg, #58b39a, #63a9d4 72%); }}
.cv-lede {{ font-size: 1.15rem; line-height: 1.6; color: {QUIET}; margin: 0 0 8px; max-width: 52rem; }}
.cv-card {{ background: {PANEL}; border: 1px solid {RULE}; border-radius: 14px; padding: 20px;
  gap: 14px !important; }}
.cv-label {{ font-size: 0.82rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: {QUIET}; }}
.cv-sub {{ font-size: 0.88rem; font-weight: 600; color: {INK}; }}
.html-container {{ padding: 0 !important; }}
.cv-quiet, .cv-quiet p {{ font-size: 0.88rem; line-height: 1.6; color: {QUIET}; margin: 0; }}
.cv-card .cv-quiet {{ padding: 0 2px; overflow: visible; }}
.cv-photo img {{ border-radius: 10px; }}
.cv-photo {{ border: 1px solid {RULE}; border-radius: 10px; background: {SOFT}; min-height: 180px; }}
.cv-card button {{ min-height: 48px; }}
.cv-card label {{ min-height: 44px; }}
.cv-settings {{ border: 1px solid {RULE} !important; border-radius: 10px !important;
  background: {SOFT} !important; }}
.cv-settings {{ padding: 0 14px !important; }}
.cv-settings .label-wrap {{ font-size: 0.82rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: {QUIET}; align-items: center; min-height: 48px; }}
.cv-settings .label-wrap span {{ display: flex; align-items: center; }}
.cv-settings .label-wrap.open {{ margin-bottom: 6px; }}
.cv-examples, .cv-examples .gallery-container, .cv-examples .grid-wrap {{ height: auto !important;
  min-height: 0 !important; max-height: none !important; }}
.cv-examples .grid-container {{ grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  grid-template-rows: none !important; grid-auto-rows: auto !important; height: auto !important; }}
.cv-examples .gallery-item, .cv-examples .thumbnail-item {{ width: 100% !important;
  height: auto !important; aspect-ratio: 4 / 3; }}
.cv-field, .cv-fields {{ gap: 6px !important; }}
.cv-hint {{ font-size: 0.88rem; line-height: 1.6; color: {QUIET}; margin: 0 2px 8px; }}
.cv-number {{ align-items: end; gap: 8px; }}
.cv-field .form, .cv-field .block {{ border: 0 !important; background: transparent !important;
  box-shadow: none !important; padding: 0 !important; }}
.cv-field .form, .cv-field .block {{ border-radius: 0 !important; overflow: visible !important; }}
.cv-field label {{ min-height: 0; }}
.cv-field span[data-testid="block-info"] {{ font-size: 0.95rem; font-weight: 560; color: {INK}; }}
.cv-field input[type="text"], .cv-field input[type="number"], .cv-field .wrap-inner {{
  min-height: 44px; border: 1px solid {RULE}; border-radius: 8px; background: {GROUND}; }}
.cv-field .min_value, .cv-field .max_value {{ display: none; }}
.cv-field .head input[type="number"] {{ min-height: 0; border: 0; background: transparent;
  color: {LIFT}; text-align: right; }}
.cv-number button {{ min-height: 44px; border: 1px solid {RULE}; border-radius: 8px;
  background: transparent; color: {INK}; font-weight: 560; }}
.cv-card button.cv-go {{ background: {BUTTON}; color: #ffffff; border-color: {ACCENT}; }}
.cv-card button.cv-go:disabled {{ opacity: 0.55; }}
.cv-panel {{ min-height: 260px; box-sizing: border-box; padding: 24px; border-radius: 10px;
  border: 1px dashed {RULE}; background: {SOFT}; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; text-align: center; }}
.cv-panel p {{ margin: 0; max-width: 24rem; color: {QUIET}; font-size: 0.95rem; line-height: 1.6; }}
.cv-idle .cv-title {{ color: {QUIET}; font-weight: 400; font-size: 1rem; }}
.cv-title {{ font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15;
  color: {INK}; }}
.cv-step {{ font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: {QUIET}; }}
.cv-clock {{ font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 0.95rem; color: {QUIET}; }}
.cv-spinner {{ width: 40px; height: 40px; border-radius: 999px; border: 4px solid {RULE};
  border-top-color: {LIFT}; animation: cv-turn 1s linear infinite; }}
@keyframes cv-turn {{ to {{ transform: rotate(360deg); }} }}
@media (prefers-reduced-motion: reduce) {{ .cv-spinner {{ animation: none !important; }} }}
.cv-sign {{ flex: none; width: 24px; height: 24px; border-radius: 999px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; }}
.cv-good {{ color: #57b894; border: 2px solid #57b894; font-size: 0.8rem; }}
.cv-bad {{ color: #d1615a; border: 2px solid #d1615a; }}
.cv-done {{ display: flex; gap: 10px; align-items: flex-start; }}
.cv-done p {{ margin: 0; color: {INK}; font-size: 0.95rem; line-height: 1.6; }}
.cv-about {{ background: {SOFT}; border: 1px solid {RULE}; border-radius: 14px;
  padding: 20px 24px; margin-top: 8px; }}
.cv-about p {{ margin: 0 0 6px; color: {INK}; font-size: 0.95rem; line-height: 1.6; }}
.cv-links {{ display: flex; flex-wrap: wrap; gap: 0 24px; font-weight: 560; padding: 0 !important; }}
.cv-links a {{ margin: 0 !important; padding: 0 !important; }}
.cv-links a {{ min-height: 44px; display: inline-flex; align-items: center; color: {LIFT}; }}
.cv-about p.cv-quiet {{ color: {QUIET}; font-size: 0.88rem; margin: 0; }}
"""


def _raised(rules: str) -> str:
    """Each rule under the page's own root, named twice. Hugging Face serves a Space's styles
    beside Gradio's own at the same weight, and Gradio's then win where both speak. A rule that
    names the root itself, as the unframed headline's does, is left as it is."""
    out = []
    for line in rules.split("}\n"):
        head, brace, body = line.partition("{")
        if brace and not head.lstrip().startswith("@") and ".gradio-container" not in head:
            head = ", ".join(f"{_ROOT} {selector.strip()}" for selector in head.split(",")) + " "
        out.append(head + brace + body)
    return "}\n".join(out)


CSS = _raised(_RULES)