File size: 1,462 Bytes
4107841
 
 
 
 
 
 
 
 
34137dd
0ced688
 
4107841
 
34137dd
 
 
 
 
 
 
4107841
34137dd
0ced688
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4107841
 
 
 
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
"""Gradio theme and the small CSS file (spec section 14)."""

from __future__ import annotations

from pathlib import Path

import gradio as gr

CSS_PATH = Path(__file__).with_name("style.css")
LOGIN_CSS_PATH = Path(__file__).with_name("login.css")
# System fonts only: no request to a font server from a visitor's iPad.
SYSTEM_FONTS = ("ui-sans-serif", "system-ui", "-apple-system", "Segoe UI", "Roboto", "sans-serif")


class AppTheme(gr.themes.Soft):
    """Soft, plus the login page rules: that page loads /theme.css but ignores css= and head=."""

    def _get_theme_css(self) -> str:
        return super()._get_theme_css() + "\n\n" + LOGIN_CSS_PATH.read_text(encoding="utf-8")


def build_theme() -> gr.themes.Base:
    return AppTheme(
        primary_hue="indigo",
        neutral_hue="slate",
        text_size="md",
        spacing_size="md",
        radius_size="lg",
        font=SYSTEM_FONTS,
    ).set(
        button_secondary_background_fill="white",
        button_secondary_background_fill_dark="*neutral_800",
        button_secondary_background_fill_hover="*neutral_100",
        button_secondary_background_fill_hover_dark="*neutral_700",
        button_secondary_border_color="*neutral_200",
        button_secondary_border_color_dark="*neutral_700",
        button_secondary_text_color="*neutral_800",
        button_secondary_text_color_dark="*neutral_100",
    )


def load_css() -> str:
    return CSS_PATH.read_text(encoding="utf-8")