-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
base.py
1815 lines (1748 loc) 路 86.9 KB
/
base.py
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
import json
import re
import tempfile
import textwrap
from pathlib import Path
from typing import Iterable
import huggingface_hub
import requests
import semantic_version as semver
from gradio_client.documentation import document, set_documentation_group
from huggingface_hub import CommitOperationAdd
from gradio.themes.utils import (
colors,
fonts,
get_matching_version,
get_theme_assets,
sizes,
)
from gradio.themes.utils.readme_content import README_CONTENT
set_documentation_group("themes")
class ThemeClass:
def __init__(self):
self._stylesheets = []
self.name = None
def _get_theme_css(self):
css = {}
dark_css = {}
for attr, val in self.__dict__.items():
if attr.startswith("_"):
continue
if val is None:
if attr.endswith("_dark"):
dark_css[attr[:-5]] = None
continue
else:
raise ValueError(
f"Cannot set '{attr}' to None - only dark mode variables can be None."
)
val = str(val)
pattern = r"(\*)([\w_]+)(\b)"
def repl_func(match):
full_match = match.group(0)
if full_match.startswith("*") and full_match.endswith("_dark"):
raise ValueError(
f"Cannot refer '{attr}' to '{val}' - dark variable references are automatically used for dark mode attributes, so do not use the _dark suffix in the value."
)
if (
attr.endswith("_dark")
and full_match.startswith("*")
and attr[:-5] == full_match[1:]
):
raise ValueError(
f"Cannot refer '{attr}' to '{val}' - if dark and light mode values are the same, set dark mode version to None."
)
word = match.group(2)
word = word.replace("_", "-")
return f"var(--{word})"
val = re.sub(pattern, repl_func, val)
attr = attr.replace("_", "-")
if attr.endswith("-dark"):
attr = attr[:-5]
dark_css[attr] = val
else:
css[attr] = val
for attr, val in css.items():
if attr not in dark_css:
dark_css[attr] = val
css_code = (
":root {\n"
+ "\n".join([f" --{attr}: {val};" for attr, val in css.items()])
+ "\n}"
)
dark_css_code = (
".dark {\n"
+ "\n".join([f" --{attr}: {val};" for attr, val in dark_css.items()])
+ "\n}"
)
return f"{css_code}\n{dark_css_code}"
def to_dict(self):
"""Convert the theme into a python dictionary."""
schema = {"theme": {}}
for prop in dir(self):
if (
not prop.startswith("_")
or prop.startswith("_font")
or prop == "_stylesheets"
or prop == "name"
) and isinstance(getattr(self, prop), (list, str)):
schema["theme"][prop] = getattr(self, prop)
return schema
@classmethod
def load(cls, path: str) -> ThemeClass:
"""Load a theme from a json file.
Parameters:
path: The filepath to read.
"""
with open(path) as fp:
return cls.from_dict(json.load(fp, object_hook=fonts.as_font))
@classmethod
def from_dict(cls, theme: dict[str, dict[str, str]]) -> ThemeClass:
"""Create a theme instance from a dictionary representation.
Parameters:
theme: The dictionary representation of the theme.
"""
new_theme = cls()
for prop, value in theme["theme"].items():
setattr(new_theme, prop, value)
# For backwards compatibility, load attributes in base theme not in the loaded theme from the base theme.
base = Base()
for attr in base.__dict__:
if not attr.startswith("_") and not hasattr(new_theme, attr):
setattr(new_theme, attr, getattr(base, attr))
return new_theme
def dump(self, filename: str):
"""Write the theme to a json file.
Parameters:
filename: The path to write the theme too
"""
Path(filename).write_text(json.dumps(self.to_dict(), cls=fonts.FontEncoder))
@classmethod
def from_hub(cls, repo_name: str, hf_token: str | None = None):
"""Load a theme from the hub.
This DOES NOT require a HuggingFace account for downloading publicly available themes.
Parameters:
repo_name: string of the form <author>/<theme-name>@<semantic-version-expression>. If a semantic version expression is omitted, the latest version will be fetched.
hf_token: HuggingFace Token. Only needed to download private themes.
"""
if "@" not in repo_name:
name, version = repo_name, None
else:
name, version = repo_name.split("@")
api = huggingface_hub.HfApi(token=hf_token)
try:
space_info = api.space_info(name)
except requests.HTTPError as e:
raise ValueError(f"The space {name} does not exist") from e
assets = get_theme_assets(space_info)
matching_version = get_matching_version(assets, version)
if not matching_version:
raise ValueError(
f"Cannot find a matching version for expression {version} "
f"from files {[f.filename for f in assets]}"
)
theme_file = huggingface_hub.hf_hub_download(
repo_id=name,
repo_type="space",
filename=f"themes/theme_schema@{matching_version.version}.json",
)
theme = cls.load(theme_file)
theme.name = name
return theme
@staticmethod
def _get_next_version(space_info: huggingface_hub.hf_api.SpaceInfo) -> str:
assets = get_theme_assets(space_info)
latest_version = max(assets, key=lambda asset: asset.version).version
return str(latest_version.next_patch())
@staticmethod
def _theme_version_exists(
space_info: huggingface_hub.hf_api.SpaceInfo, version: str
) -> bool:
assets = get_theme_assets(space_info)
return any(a.version == semver.Version(version) for a in assets)
def push_to_hub(
self,
repo_name: str,
org_name: str | None = None,
version: str | None = None,
hf_token: str | None = None,
theme_name: str | None = None,
description: str | None = None,
private: bool = False,
):
"""Upload a theme to the HuggingFace hub.
This requires a HuggingFace account.
Parameters:
repo_name: The name of the repository to store the theme assets, e.g. 'my_theme' or 'sunset'.
org_name: The name of the org to save the space in. If None (the default), the username corresponding to the logged in user, or h茠_token is used.
version: A semantic version tag for theme. Bumping the version tag lets you publish updates to a theme without changing the look of applications that already loaded your theme.
hf_token: API token for your HuggingFace account
theme_name: Name for the name. If None, defaults to repo_name
description: A long form description to your theme.
"""
from gradio import __version__
api = huggingface_hub.HfApi()
if not hf_token:
try:
author = huggingface_hub.whoami()["name"]
except OSError as e:
raise ValueError(
"In order to push to hub, log in via `huggingface-cli login` "
"or provide a theme_token to push_to_hub. For more information "
"see https://huggingface.co/docs/huggingface_hub/quick-start#login"
) from e
else:
author = huggingface_hub.whoami(token=hf_token)["name"]
space_id = f"{org_name or author}/{repo_name}"
try:
space_info = api.space_info(space_id)
except requests.HTTPError:
space_info = None
space_exists = space_info is not None
# If no version, set the version to next patch release
if not version:
version = self._get_next_version(space_info) if space_exists else "0.0.1"
else:
_ = semver.Version(version)
if space_exists and self._theme_version_exists(space_info, version):
raise ValueError(
f"The space {space_id} already has a "
f"theme with version {version}. See: themes/theme_schema@{version}.json. "
"To manually override this version, use the HuggingFace hub UI."
)
theme_name = theme_name or repo_name
with tempfile.NamedTemporaryFile(
mode="w", delete=False, suffix=".json"
) as css_file:
contents = self.to_dict()
contents["version"] = version
json.dump(contents, css_file, cls=fonts.FontEncoder)
with tempfile.NamedTemporaryFile(mode="w", delete=False) as readme_file:
readme_content = README_CONTENT.format(
theme_name=theme_name,
description=description or "Add a description of this theme here!",
author=author,
gradio_version=__version__,
)
readme_file.write(textwrap.dedent(readme_content))
with tempfile.NamedTemporaryFile(mode="w", delete=False) as app_file:
contents = (Path(__file__).parent / "app.py").read_text()
contents = re.sub(
r"theme=gr.themes.Default\(\)",
f"theme='{space_id}'",
contents,
)
contents = re.sub(r"{THEME}", theme_name or repo_name, contents)
contents = re.sub(r"{AUTHOR}", org_name or author, contents)
contents = re.sub(r"{SPACE_NAME}", repo_name, contents)
app_file.write(contents)
operations = [
CommitOperationAdd(
path_in_repo=f"themes/theme_schema@{version}.json",
path_or_fileobj=css_file.name,
),
CommitOperationAdd(
path_in_repo="README.md", path_or_fileobj=readme_file.name
),
CommitOperationAdd(path_in_repo="app.py", path_or_fileobj=app_file.name),
]
huggingface_hub.create_repo(
space_id,
repo_type="space",
space_sdk="gradio",
token=hf_token,
exist_ok=True,
private=private,
)
api.create_commit(
repo_id=space_id,
commit_message="Updating theme",
repo_type="space",
operations=operations,
token=hf_token,
)
url = f"https://huggingface.co/spaces/{space_id}"
print(f"See your theme here! {url}")
return url
@document("push_to_hub", "from_hub", "load", "dump", "from_dict", "to_dict")
class Base(ThemeClass):
def __init__(
self,
*,
primary_hue: colors.Color | str = colors.blue,
secondary_hue: colors.Color | str = colors.blue,
neutral_hue: colors.Color | str = colors.gray,
text_size: sizes.Size | str = sizes.text_md,
spacing_size: sizes.Size | str = sizes.spacing_md,
radius_size: sizes.Size | str = sizes.radius_md,
font: fonts.Font
| str
| Iterable[fonts.Font | str] = (
fonts.GoogleFont("Source Sans Pro"),
"ui-sans-serif",
"system-ui",
"sans-serif",
),
font_mono: fonts.Font
| str
| Iterable[fonts.Font | str] = (
fonts.GoogleFont("IBM Plex Mono"),
"ui-monospace",
"Consolas",
"monospace",
),
):
"""
Parameters:
primary_hue: The primary hue of the theme. Load a preset, like gradio.themes.colors.green (or just the string "green"), or pass your own gradio.themes.utils.Color object.
secondary_hue: The secondary hue of the theme. Load a preset, like gradio.themes.colors.green (or just the string "green"), or pass your own gradio.themes.utils.Color object.
neutral_hue: The neutral hue of the theme, used . Load a preset, like gradio.themes.colors.green (or just the string "green"), or pass your own gradio.themes.utils.Color object.
text_size: The size of the text. Load a preset, like gradio.themes.sizes.text_sm (or just the string "sm"), or pass your own gradio.themes.utils.Size object.
spacing_size: The size of the spacing. Load a preset, like gradio.themes.sizes.spacing_sm (or just the string "sm"), or pass your own gradio.themes.utils.Size object.
radius_size: The radius size of corners. Load a preset, like gradio.themes.sizes.radius_sm (or just the string "sm"), or pass your own gradio.themes.utils.Size object.
font: The primary font to use for the theme. Pass a string for a system font, or a gradio.themes.font.GoogleFont object to load a font from Google Fonts. Pass a list of fonts for fallbacks.
font_mono: The monospace font to use for the theme, applies to code. Pass a string for a system font, or a gradio.themes.font.GoogleFont object to load a font from Google Fonts. Pass a list of fonts for fallbacks.
"""
self.name = "base"
def expand_shortcut(shortcut, mode="color", prefix=None):
if not isinstance(shortcut, str):
return shortcut
if mode == "color":
for color in colors.Color.all:
if color.name == shortcut:
return color
raise ValueError(f"Color shortcut {shortcut} not found.")
elif mode == "size":
for size in sizes.Size.all:
if size.name == f"{prefix}_{shortcut}":
return size
raise ValueError(f"Size shortcut {shortcut} not found.")
primary_hue = expand_shortcut(primary_hue, mode="color")
secondary_hue = expand_shortcut(secondary_hue, mode="color")
neutral_hue = expand_shortcut(neutral_hue, mode="color")
text_size = expand_shortcut(text_size, mode="size", prefix="text")
spacing_size = expand_shortcut(spacing_size, mode="size", prefix="spacing")
radius_size = expand_shortcut(radius_size, mode="size", prefix="radius")
# Hue ranges
self.primary_50 = primary_hue.c50
self.primary_100 = primary_hue.c100
self.primary_200 = primary_hue.c200
self.primary_300 = primary_hue.c300
self.primary_400 = primary_hue.c400
self.primary_500 = primary_hue.c500
self.primary_600 = primary_hue.c600
self.primary_700 = primary_hue.c700
self.primary_800 = primary_hue.c800
self.primary_900 = primary_hue.c900
self.primary_950 = primary_hue.c950
self.secondary_50 = secondary_hue.c50
self.secondary_100 = secondary_hue.c100
self.secondary_200 = secondary_hue.c200
self.secondary_300 = secondary_hue.c300
self.secondary_400 = secondary_hue.c400
self.secondary_500 = secondary_hue.c500
self.secondary_600 = secondary_hue.c600
self.secondary_700 = secondary_hue.c700
self.secondary_800 = secondary_hue.c800
self.secondary_900 = secondary_hue.c900
self.secondary_950 = secondary_hue.c950
self.neutral_50 = neutral_hue.c50
self.neutral_100 = neutral_hue.c100
self.neutral_200 = neutral_hue.c200
self.neutral_300 = neutral_hue.c300
self.neutral_400 = neutral_hue.c400
self.neutral_500 = neutral_hue.c500
self.neutral_600 = neutral_hue.c600
self.neutral_700 = neutral_hue.c700
self.neutral_800 = neutral_hue.c800
self.neutral_900 = neutral_hue.c900
self.neutral_950 = neutral_hue.c950
# Spacing
self.spacing_xxs = spacing_size.xxs
self.spacing_xs = spacing_size.xs
self.spacing_sm = spacing_size.sm
self.spacing_md = spacing_size.md
self.spacing_lg = spacing_size.lg
self.spacing_xl = spacing_size.xl
self.spacing_xxl = spacing_size.xxl
self.radius_xxs = radius_size.xxs
self.radius_xs = radius_size.xs
self.radius_sm = radius_size.sm
self.radius_md = radius_size.md
self.radius_lg = radius_size.lg
self.radius_xl = radius_size.xl
self.radius_xxl = radius_size.xxl
self.text_xxs = text_size.xxs
self.text_xs = text_size.xs
self.text_sm = text_size.sm
self.text_md = text_size.md
self.text_lg = text_size.lg
self.text_xl = text_size.xl
self.text_xxl = text_size.xxl
# Font
if not isinstance(font, Iterable):
font = [font]
self._font = [
fontfam if isinstance(fontfam, fonts.Font) else fonts.Font(fontfam)
for fontfam in font
]
if not isinstance(font_mono, Iterable):
font_mono = [font_mono]
self._font_mono = [
fontfam if isinstance(fontfam, fonts.Font) else fonts.Font(fontfam)
for fontfam in font_mono
]
self.font = ", ".join(str(font) for font in self._font)
self.font_mono = ", ".join(str(font) for font in self._font_mono)
self._stylesheets = []
for font in self._font + self._font_mono:
font_stylesheet = font.stylesheet()
if font_stylesheet:
self._stylesheets.append(font_stylesheet)
self.set()
def set(
self,
*,
# Body Attributes: These set set the values for the entire body of the app.
body_background_fill=None,
body_background_fill_dark=None,
body_text_color=None,
body_text_color_dark=None,
body_text_size=None,
body_text_color_subdued=None,
body_text_color_subdued_dark=None,
body_text_weight=None,
embed_radius=None,
# Element Colors: These set the colors for common elements.
background_fill_primary=None,
background_fill_primary_dark=None,
background_fill_secondary=None,
background_fill_secondary_dark=None,
border_color_accent=None,
border_color_accent_dark=None,
border_color_primary=None,
border_color_primary_dark=None,
color_accent=None,
color_accent_soft=None,
color_accent_soft_dark=None,
# Text: This sets the text styling for text elements.
link_text_color=None,
link_text_color_dark=None,
link_text_color_active=None,
link_text_color_active_dark=None,
link_text_color_hover=None,
link_text_color_hover_dark=None,
link_text_color_visited=None,
link_text_color_visited_dark=None,
prose_text_size=None,
prose_text_weight=None,
prose_header_text_weight=None,
# Shadows: These set the high-level shadow rendering styles. These variables are often referenced by other component-specific shadow variables.
shadow_drop=None,
shadow_drop_lg=None,
shadow_inset=None,
shadow_spread=None,
shadow_spread_dark=None,
# Layout Atoms: These set the style for common layout elements, such as the blocks that wrap components.
block_background_fill=None,
block_background_fill_dark=None,
block_border_color=None,
block_border_color_dark=None,
block_border_width=None,
block_border_width_dark=None,
block_info_text_color=None,
block_info_text_color_dark=None,
block_info_text_size=None,
block_info_text_weight=None,
block_label_background_fill=None,
block_label_background_fill_dark=None,
block_label_border_color=None,
block_label_border_color_dark=None,
block_label_border_width=None,
block_label_border_width_dark=None,
block_label_shadow=None,
block_label_text_color=None,
block_label_text_color_dark=None,
block_label_margin=None,
block_label_padding=None,
block_label_radius=None,
block_label_right_radius=None,
block_label_text_size=None,
block_label_text_weight=None,
block_padding=None,
block_radius=None,
block_shadow=None,
block_shadow_dark=None,
block_title_background_fill=None,
block_title_background_fill_dark=None,
block_title_border_color=None,
block_title_border_color_dark=None,
block_title_border_width=None,
block_title_border_width_dark=None,
block_title_text_color=None,
block_title_text_color_dark=None,
block_title_padding=None,
block_title_radius=None,
block_title_text_size=None,
block_title_text_weight=None,
container_radius=None,
form_gap_width=None,
layout_gap=None,
panel_background_fill=None,
panel_background_fill_dark=None,
panel_border_color=None,
panel_border_color_dark=None,
panel_border_width=None,
panel_border_width_dark=None,
section_header_text_size=None,
section_header_text_weight=None,
# Component Atoms: These set the style for elements within components.
chatbot_code_background_color=None,
chatbot_code_background_color_dark=None,
checkbox_background_color=None,
checkbox_background_color_dark=None,
checkbox_background_color_focus=None,
checkbox_background_color_focus_dark=None,
checkbox_background_color_hover=None,
checkbox_background_color_hover_dark=None,
checkbox_background_color_selected=None,
checkbox_background_color_selected_dark=None,
checkbox_border_color=None,
checkbox_border_color_dark=None,
checkbox_border_color_focus=None,
checkbox_border_color_focus_dark=None,
checkbox_border_color_hover=None,
checkbox_border_color_hover_dark=None,
checkbox_border_color_selected=None,
checkbox_border_color_selected_dark=None,
checkbox_border_radius=None,
checkbox_border_width=None,
checkbox_border_width_dark=None,
checkbox_check=None,
radio_circle=None,
checkbox_shadow=None,
checkbox_label_background_fill=None,
checkbox_label_background_fill_dark=None,
checkbox_label_background_fill_hover=None,
checkbox_label_background_fill_hover_dark=None,
checkbox_label_background_fill_selected=None,
checkbox_label_background_fill_selected_dark=None,
checkbox_label_border_color=None,
checkbox_label_border_color_dark=None,
checkbox_label_border_color_hover=None,
checkbox_label_border_color_hover_dark=None,
checkbox_label_border_width=None,
checkbox_label_border_width_dark=None,
checkbox_label_gap=None,
checkbox_label_padding=None,
checkbox_label_shadow=None,
checkbox_label_text_size=None,
checkbox_label_text_weight=None,
checkbox_label_text_color=None,
checkbox_label_text_color_dark=None,
checkbox_label_text_color_selected=None,
checkbox_label_text_color_selected_dark=None,
error_background_fill=None,
error_background_fill_dark=None,
error_border_color=None,
error_border_color_dark=None,
error_border_width=None,
error_border_width_dark=None,
error_text_color=None,
error_text_color_dark=None,
error_icon_color=None,
error_icon_color_dark=None,
input_background_fill=None,
input_background_fill_dark=None,
input_background_fill_focus=None,
input_background_fill_focus_dark=None,
input_background_fill_hover=None,
input_background_fill_hover_dark=None,
input_border_color=None,
input_border_color_dark=None,
input_border_color_focus=None,
input_border_color_focus_dark=None,
input_border_color_hover=None,
input_border_color_hover_dark=None,
input_border_width=None,
input_border_width_dark=None,
input_padding=None,
input_placeholder_color=None,
input_placeholder_color_dark=None,
input_radius=None,
input_shadow=None,
input_shadow_dark=None,
input_shadow_focus=None,
input_shadow_focus_dark=None,
input_text_size=None,
input_text_weight=None,
loader_color=None,
loader_color_dark=None,
slider_color=None,
slider_color_dark=None,
stat_background_fill=None,
stat_background_fill_dark=None,
table_border_color=None,
table_border_color_dark=None,
table_even_background_fill=None,
table_even_background_fill_dark=None,
table_odd_background_fill=None,
table_odd_background_fill_dark=None,
table_radius=None,
table_row_focus=None,
table_row_focus_dark=None,
# Buttons: These set the style for buttons.
button_border_width=None,
button_border_width_dark=None,
button_shadow=None,
button_shadow_active=None,
button_shadow_hover=None,
button_transition=None,
button_large_padding=None,
button_large_radius=None,
button_large_text_size=None,
button_large_text_weight=None,
button_small_padding=None,
button_small_radius=None,
button_small_text_size=None,
button_small_text_weight=None,
button_primary_background_fill=None,
button_primary_background_fill_dark=None,
button_primary_background_fill_hover=None,
button_primary_background_fill_hover_dark=None,
button_primary_border_color=None,
button_primary_border_color_dark=None,
button_primary_border_color_hover=None,
button_primary_border_color_hover_dark=None,
button_primary_text_color=None,
button_primary_text_color_dark=None,
button_primary_text_color_hover=None,
button_primary_text_color_hover_dark=None,
button_secondary_background_fill=None,
button_secondary_background_fill_dark=None,
button_secondary_background_fill_hover=None,
button_secondary_background_fill_hover_dark=None,
button_secondary_border_color=None,
button_secondary_border_color_dark=None,
button_secondary_border_color_hover=None,
button_secondary_border_color_hover_dark=None,
button_secondary_text_color=None,
button_secondary_text_color_dark=None,
button_secondary_text_color_hover=None,
button_secondary_text_color_hover_dark=None,
button_cancel_background_fill=None,
button_cancel_background_fill_dark=None,
button_cancel_background_fill_hover=None,
button_cancel_background_fill_hover_dark=None,
button_cancel_border_color=None,
button_cancel_border_color_dark=None,
button_cancel_border_color_hover=None,
button_cancel_border_color_hover_dark=None,
button_cancel_text_color=None,
button_cancel_text_color_dark=None,
button_cancel_text_color_hover=None,
button_cancel_text_color_hover_dark=None,
) -> Base:
"""
Parameters:
body_background_fill: The background of the entire app.
body_background_fill_dark: The background of the entire app in dark mode.
body_text_color: The default text color.
body_text_color_dark: The default text color in dark mode.
body_text_size: The default text size.
body_text_color_subdued: The text color used for softer, less important text.
body_text_color_subdued_dark: The text color used for softer, less important text in dark mode.
body_text_weight: The default text weight.
embed_radius: The corner radius used for embedding when the app is embedded within a page.
background_fill_primary: The background primarily used for items placed directly on the page.
background_fill_primary_dark: The background primarily used for items placed directly on the page in dark mode.
background_fill_secondary: The background primarily used for items placed on top of another item.
background_fill_secondary_dark: The background primarily used for items placed on top of another item in dark mode.
border_color_accent: The border color used for accented items.
border_color_accent_dark: The border color used for accented items in dark mode.
border_color_primary: The border color primarily used for items placed directly on the page.
border_color_primary_dark: The border color primarily used for items placed directly on the page in dark mode.
color_accent: The color used for accented items.
color_accent_soft: The softer color used for accented items.
color_accent_soft_dark: The softer color used for accented items in dark mode.
link_text_color: The text color used for links.
link_text_color_dark: The text color used for links in dark mode.
link_text_color_active: The text color used for links when they are active.
link_text_color_active_dark: The text color used for links when they are active in dark mode.
link_text_color_hover: The text color used for links when they are hovered over.
link_text_color_hover_dark: The text color used for links when they are hovered over in dark mode.
link_text_color_visited: The text color used for links when they have been visited.
link_text_color_visited_dark: The text color used for links when they have been visited in dark mode.
prose_text_size: The text size used for markdown and other prose.
prose_text_weight: The text weight used for markdown and other prose.
prose_header_text_weight: The text weight of a header used for markdown and other prose.
shadow_drop: Drop shadow used by other shadowed items.
shadow_drop_lg: Larger drop shadow used by other shadowed items.
shadow_inset: Inset shadow used by other shadowed items.
shadow_spread: Size of shadow spread used by shadowed items.
shadow_spread_dark: Size of shadow spread used by shadowed items in dark mode.
block_background_fill: The background around an item.
block_background_fill_dark: The background around an item in dark mode.
block_border_color: The border color around an item.
block_border_color_dark: The border color around an item in dark mode.
block_border_width: The border width around an item.
block_border_width_dark: The border width around an item in dark mode.
block_info_text_color: The color of the info text.
block_info_text_color_dark: The color of the info text in dark mode.
block_info_text_size: The size of the info text.
block_info_text_weight: The weight of the info text.
block_label_background_fill: The background of the title label of a media element (e.g. image).
block_label_background_fill_dark: The background of the title label of a media element (e.g. image) in dark mode.
block_label_border_color: The border color of the title label of a media element (e.g. image).
block_label_border_color_dark: The border color of the title label of a media element (e.g. image) in dark mode.
block_label_border_width: The border width of the title label of a media element (e.g. image).
block_label_border_width_dark: The border width of the title label of a media element (e.g. image) in dark mode.
block_label_shadow: The shadow of the title label of a media element (e.g. image).
block_label_text_color: The text color of the title label of a media element (e.g. image).
block_label_text_color_dark: The text color of the title label of a media element (e.g. image) in dark mode.
block_label_margin: The margin of the title label of a media element (e.g. image) from its surrounding container.
block_label_padding: The padding of the title label of a media element (e.g. image).
block_label_radius: The corner radius of the title label of a media element (e.g. image).
block_label_right_radius: The corner radius of a right-aligned helper label.
block_label_text_size: The text size of the title label of a media element (e.g. image).
block_label_text_weight: The text weight of the title label of a media element (e.g. image).
block_padding: The padding around an item.
block_radius: The corner radius around an item.
block_shadow: The shadow under an item.
block_shadow_dark: The shadow under an item in dark mode.
block_title_background_fill: The background of the title of a form element (e.g. textbox).
block_title_background_fill_dark: The background of the title of a form element (e.g. textbox) in dark mode.
block_title_border_color: The border color of the title of a form element (e.g. textbox).
block_title_border_color_dark: The border color of the title of a form element (e.g. textbox) in dark mode.
block_title_border_width: The border width of the title of a form element (e.g. textbox).
block_title_border_width_dark: The border width of the title of a form element (e.g. textbox) in dark mode.
block_title_text_color: The text color of the title of a form element (e.g. textbox).
block_title_text_color_dark: The text color of the title of a form element (e.g. textbox) in dark mode.
block_title_padding: The padding of the title of a form element (e.g. textbox).
block_title_radius: The corner radius of the title of a form element (e.g. textbox).
block_title_text_size: The text size of the title of a form element (e.g. textbox).
block_title_text_weight: The text weight of the title of a form element (e.g. textbox).
container_radius: The corner radius of a layout component that holds other content.
form_gap_width: The border gap between form elements, (e.g. consecutive textboxes).
layout_gap: The gap between items within a row or column.
panel_background_fill: The background of a panel.
panel_background_fill_dark: The background of a panel in dark mode.
panel_border_color: The border color of a panel.
panel_border_color_dark: The border color of a panel in dark mode.
panel_border_width: The border width of a panel.
panel_border_width_dark: The border width of a panel in dark mode.
section_header_text_size: The text size of a section header (e.g. tab name).
section_header_text_weight: The text weight of a section header (e.g. tab name).
chatbot_code_background_color: The background color of code blocks in the chatbot.
chatbot_code_background_color_dark: The background color of code blocks in the chatbot in dark mode.
checkbox_background_color: The background of a checkbox square or radio circle.
checkbox_background_color_dark: The background of a checkbox square or radio circle in dark mode.
checkbox_background_color_focus: The background of a checkbox square or radio circle when focused.
checkbox_background_color_focus_dark: The background of a checkbox square or radio circle when focused in dark mode.
checkbox_background_color_hover: The background of a checkbox square or radio circle when hovered over.
checkbox_background_color_hover_dark: The background of a checkbox square or radio circle when hovered over in dark mode.
checkbox_background_color_selected: The background of a checkbox square or radio circle when selected.
checkbox_background_color_selected_dark: The background of a checkbox square or radio circle when selected in dark mode.
checkbox_border_color: The border color of a checkbox square or radio circle.
checkbox_border_color_dark: The border color of a checkbox square or radio circle in dark mode.
checkbox_border_color_focus: The border color of a checkbox square or radio circle when focused.
checkbox_border_color_focus_dark: The border color of a checkbox square or radio circle when focused in dark mode.
checkbox_border_color_hover: The border color of a checkbox square or radio circle when hovered over.
checkbox_border_color_hover_dark: The border color of a checkbox square or radio circle when hovered over in dark mode.
checkbox_border_color_selected: The border color of a checkbox square or radio circle when selected.
checkbox_border_color_selected_dark: The border color of a checkbox square or radio circle when selected in dark mode.
checkbox_border_radius: The corner radius of a checkbox square.
checkbox_border_width: The border width of a checkbox square or radio circle.
checkbox_border_width_dark: The border width of a checkbox square or radio circle in dark mode.
checkbox_check: The checkmark visual of a checkbox square.
radio_circle: The circle visual of a radio circle.
checkbox_shadow: The shadow of a checkbox square or radio circle.
checkbox_label_background_fill: The background of the surrounding button of a checkbox or radio element.
checkbox_label_background_fill_dark: The background of the surrounding button of a checkbox or radio element in dark mode.
checkbox_label_background_fill_hover: The background of the surrounding button of a checkbox or radio element when hovered over.
checkbox_label_background_fill_hover_dark: The background of the surrounding button of a checkbox or radio element when hovered over in dark mode.
checkbox_label_background_fill_selected: The background of the surrounding button of a checkbox or radio element when selected.
checkbox_label_background_fill_selected_dark: The background of the surrounding button of a checkbox or radio element when selected in dark mode.
checkbox_label_border_color: The border color of the surrounding button of a checkbox or radio element.
checkbox_label_border_color_dark: The border color of the surrounding button of a checkbox or radio element in dark mode.
checkbox_label_border_color_hover: The border color of the surrounding button of a checkbox or radio element when hovered over.
checkbox_label_border_color_hover_dark: The border color of the surrounding button of a checkbox or radio element when hovered over in dark mode.
checkbox_label_border_width: The border width of the surrounding button of a checkbox or radio element.
checkbox_label_border_width_dark: The border width of the surrounding button of a checkbox or radio element in dark mode.
checkbox_label_gap: The gap consecutive checkbox or radio elements.
checkbox_label_padding: The padding of the surrounding button of a checkbox or radio element.
checkbox_label_shadow: The shadow of the surrounding button of a checkbox or radio element.
checkbox_label_text_size: The text size of the label accompanying a checkbox or radio element.
checkbox_label_text_weight: The text weight of the label accompanying a checkbox or radio element.
checkbox_label_text_color: The text color of the label accompanying a checkbox or radio element.
checkbox_label_text_color_dark: The text color of the label accompanying a checkbox or radio element in dark mode.
checkbox_label_text_color_selected: The text color of the label accompanying a checkbox or radio element when selected.
checkbox_label_text_color_selected_dark: The text color of the label accompanying a checkbox or radio element when selected in dark mode.
error_background_fill: The background of an error message.
error_background_fill_dark: The background of an error message in dark mode.
error_border_color: The border color of an error message.
error_border_color_dark: The border color of an error message in dark mode.
error_border_width: The border width of an error message.
error_border_width_dark: The border width of an error message in dark mode.
error_text_color: The text color of an error message.
error_text_color_dark: The text color of an error message in dark mode.
input_background_fill: The background of an input field.
input_background_fill_dark: The background of an input field in dark mode.
input_background_fill_focus: The background of an input field when focused.
input_background_fill_focus_dark: The background of an input field when focused in dark mode.
input_background_fill_hover: The background of an input field when hovered over.
input_background_fill_hover_dark: The background of an input field when hovered over in dark mode.
input_border_color: The border color of an input field.
input_border_color_dark: The border color of an input field in dark mode.
input_border_color_focus: The border color of an input field when focused.
input_border_color_focus_dark: The border color of an input field when focused in dark mode.
input_border_color_hover: The border color of an input field when hovered over.
input_border_color_hover_dark: The border color of an input field when hovered over in dark mode.
input_border_width: The border width of an input field.
input_border_width_dark: The border width of an input field in dark mode.
input_padding: The padding of an input field.
input_placeholder_color: The placeholder text color of an input field.
input_placeholder_color_dark: The placeholder text color of an input field in dark mode.
input_radius: The corner radius of an input field.
input_shadow: The shadow of an input field.
input_shadow_dark: The shadow of an input field in dark mode.
input_shadow_focus: The shadow of an input field when focused.
input_shadow_focus_dark: The shadow of an input field when focused in dark mode.
input_text_size: The text size of an input field.
input_text_weight: The text weight of an input field.
loader_color: The color of the loading animation while a request is pending.
loader_color_dark: The color of the loading animation while a request is pending in dark mode.
slider_color: The color of the slider in a range element.
slider_color_dark: The color of the slider in a range element in dark mode.
stat_background_fill: The background used for stats visuals (e.g. confidence bars in label).
stat_background_fill_dark: The background used for stats visuals (e.g. confidence bars in label) in dark mode.
table_border_color: The border color of a table.
table_border_color_dark: The border color of a table in dark mode.
table_even_background_fill: The background of even rows in a table.
table_even_background_fill_dark: The background of even rows in a table in dark mode.
table_odd_background_fill: The background of odd rows in a table.
table_odd_background_fill_dark: The background of odd rows in a table in dark mode.
table_radius: The corner radius of a table.
table_row_focus: The background of a focused row in a table.
table_row_focus_dark: The background of a focused row in a table in dark mode.
button_border_width: The border width of a button.
button_border_width_dark: The border width of a button in dark mode.
button_cancel_background_fill: The background of a button of "cancel" variant.
button_cancel_background_fill_dark: The background of a button of "cancel" variant in dark mode.
button_cancel_background_fill_hover: The background of a button of "cancel" variant when hovered over.
button_cancel_background_fill_hover_dark: The background of a button of "cancel" variant when hovered over in dark mode.
button_cancel_border_color: The border color of a button of "cancel" variant.
button_cancel_border_color_dark: The border color of a button of "cancel" variant in dark mode.
button_cancel_border_color_hover: The border color of a button of "cancel" variant when hovered over.
button_cancel_border_color_hover_dark: The border color of a button of "cancel" variant when hovered over in dark mode.
button_cancel_text_color: The text color of a button of "cancel" variant.
button_cancel_text_color_dark: The text color of a button of "cancel" variant in dark mode.
button_cancel_text_color_hover: The text color of a button of "cancel" variant when hovered over.
button_cancel_text_color_hover_dark: The text color of a button of "cancel" variant when hovered over in dark mode.
button_large_padding: The padding of a button with the default "large" size.
button_large_radius: The corner radius of a button with the default "large" size.
button_large_text_size: The text size of a button with the default "large" size.
button_large_text_weight: The text weight of a button with the default "large" size.
button_primary_background_fill: The background of a button of "primary" variant.
button_primary_background_fill_dark: The background of a button of "primary" variant in dark mode.
button_primary_background_fill_hover: The background of a button of "primary" variant when hovered over.
button_primary_background_fill_hover_dark: The background of a button of "primary" variant when hovered over in dark mode.
button_primary_border_color: The border color of a button of "primary" variant.
button_primary_border_color_dark: The border color of a button of "primary" variant in dark mode.
button_primary_border_color_hover: The border color of a button of "primary" variant when hovered over.
button_primary_border_color_hover_dark: The border color of a button of "primary" variant when hovered over in dark mode.
button_primary_text_color: The text color of a button of "primary" variant.
button_primary_text_color_dark: The text color of a button of "primary" variant in dark mode.
button_primary_text_color_hover: The text color of a button of "primary" variant when hovered over.
button_primary_text_color_hover_dark: The text color of a button of "primary" variant when hovered over in dark mode.
button_secondary_background_fill: The background of a button of default "secondary" variant.
button_secondary_background_fill_dark: The background of a button of default "secondary" variant in dark mode.
button_secondary_background_fill_hover: The background of a button of default "secondary" variant when hovered over.
button_secondary_background_fill_hover_dark: The background of a button of default "secondary" variant when hovered over in dark mode.
button_secondary_border_color: The border color of a button of default "secondary" variant.
button_secondary_border_color_dark: The border color of a button of default "secondary" variant in dark mode.
button_secondary_border_color_hover: The border color of a button of default "secondary" variant when hovered over.
button_secondary_border_color_hover_dark: The border color of a button of default "secondary" variant when hovered over in dark mode.
button_secondary_text_color: The text color of a button of default "secondary" variant.
button_secondary_text_color_dark: The text color of a button of default "secondary" variant in dark mode.
button_secondary_text_color_hover: The text color of a button of default "secondary" variant when hovered over.
button_secondary_text_color_hover_dark: The text color of a button of default "secondary" variant when hovered over in dark mode.
button_shadow: The shadow under a button.
button_shadow_active: The shadow under a button when pressed.
button_shadow_hover: The shadow under a button when hovered over.
button_small_padding: The padding of a button set to "small" size.
button_small_radius: The corner radius of a button set to "small" size.
button_small_text_size: The text size of a button set to "small" size.
button_small_text_weight: The text weight of a button set to "small" size.
button_transition: The transition animation duration of a button between regular, hover, and focused states.
"""
# Body
self.body_background_fill = body_background_fill or getattr(
self, "body_background_fill", "*background_fill_primary"
)
self.body_background_fill_dark = body_background_fill_dark or getattr(
self, "body_background_fill_dark", "*background_fill_primary"
)
self.body_text_color = body_text_color or getattr(
self, "body_text_color", "*neutral_800"
)
self.body_text_color_dark = body_text_color_dark or getattr(
self, "body_text_color_dark", "*neutral_100"
)
self.body_text_size = body_text_size or getattr(
self, "body_text_size", "*text_md"
)
self.body_text_weight = body_text_weight or getattr(
self, "body_text_weight", "400"
)
self.embed_radius = embed_radius or getattr(self, "embed_radius", "*radius_lg")
# Core Colors
self.color_accent = color_accent or getattr(
self, "color_accent", "*primary_500"
)
self.color_accent_soft = color_accent_soft or getattr(
self, "color_accent_soft", "*primary_50"
)
self.color_accent_soft_dark = color_accent_soft_dark or getattr(
self, "color_accent_soft_dark", "*neutral_700"
)
self.background_fill_primary = background_fill_primary or getattr(
self, "background_primary", "white"
)
self.background_fill_primary_dark = background_fill_primary_dark or getattr(
self, "background_primary_dark", "*neutral_950"
)
self.background_fill_secondary = background_fill_secondary or getattr(
self, "background_secondary", "*neutral_50"
)
self.background_fill_secondary_dark = background_fill_secondary_dark or getattr(
self, "background_secondary_dark", "*neutral_900"
)
self.border_color_accent = border_color_accent or getattr(
self, "border_color_accent", "*primary_300"
)
self.border_color_accent_dark = border_color_accent_dark or getattr(
self, "border_color_accent_dark", "*neutral_600"
)
self.border_color_primary = border_color_primary or getattr(
self, "border_color_primary", "*neutral_200"
)
self.border_color_primary_dark = border_color_primary_dark or getattr(
self, "border_color_primary_dark", "*neutral_700"
)