shubhamofbce commited on
Commit
b4ef1c9
·
verified ·
1 Parent(s): 6dcba87

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -50,6 +50,7 @@ def get_doc_theme_var_groups():
50
  return groups, flat_variables
51
 
52
 
 
53
  variable_groups, flat_variables = get_doc_theme_var_groups()
54
 
55
  css = """
@@ -99,6 +100,18 @@ with gr.Blocks( # noqa: SIM117
99
  show_label=False,
100
  )
101
  load_theme_btn = gr.Button("Load Theme", elem_id="load_theme")
 
 
 
 
 
 
 
 
 
 
 
 
102
  with gr.TabItem("Core Colors"):
103
  gr.Markdown(
104
  """Set the three hues of the theme: `primary_hue`, `secondary_hue`, and `neutral_hue`.
@@ -492,9 +505,13 @@ with gr.Blocks( # noqa: SIM117
492
  + theme_var_input
493
  )
494
 
495
- def load_theme(theme_name):
496
- theme = [theme for theme in themes if theme.__name__ == theme_name][0]
497
-
 
 
 
 
498
  parameters = inspect.signature(theme.__init__).parameters
499
  primary_hue = parameters["primary_hue"].default
500
  secondary_hue = parameters["secondary_hue"].default
@@ -503,7 +520,7 @@ with gr.Blocks( # noqa: SIM117
503
  spacing_size = parameters["spacing_size"].default
504
  radius_size = parameters["radius_size"].default
505
 
506
- theme = theme()
507
 
508
  font = theme._font[:4]
509
  font_mono = theme._font_mono[:4]
@@ -538,6 +555,15 @@ with gr.Blocks( # noqa: SIM117
538
  + var_output
539
  )
540
 
 
 
 
 
 
 
 
 
 
541
  def generate_theme_code(
542
  base_theme, final_theme, core_variables, final_main_fonts, final_mono_fonts
543
  ):
@@ -620,6 +646,7 @@ with gr.Blocks( # noqa: SIM117
620
  diff = True
621
  if diff:
622
  new_final_attr_values = {}
 
623
  for key, val in final_attr_values.items():
624
  if key.startswith(("primary_", "secondary_", "neutral_")):
625
  color_key = "c" + key.split("_")[-1]
@@ -629,7 +656,10 @@ with gr.Blocks( # noqa: SIM117
629
  new_final_attr_values[size_key] = val
630
  else:
631
  new_final_attr_values[key] = val
632
- specific_core_diffs[value_name] = (source_class, new_final_attr_values)
 
 
 
633
 
634
  font_diffs = {}
635
 
 
50
  return groups, flat_variables
51
 
52
 
53
+
54
  variable_groups, flat_variables = get_doc_theme_var_groups()
55
 
56
  css = """
 
100
  show_label=False,
101
  )
102
  load_theme_btn = gr.Button("Load Theme", elem_id="load_theme")
103
+ gr.Markdown(
104
+ """
105
+ Load a custom theme. Note: when you click 'Load Theme', all variable values in other tabs will be overwritten!
106
+ """
107
+ )
108
+
109
+ custom_theme_name = gr.Textbox(
110
+ label="THeme Name",
111
+ placeholder="gradio/seafoam",
112
+ interactive=True,
113
+ )
114
+ load_custom_theme_btn = gr.Button("Load Custom Theme",)
115
  with gr.TabItem("Core Colors"):
116
  gr.Markdown(
117
  """Set the three hues of the theme: `primary_hue`, `secondary_hue`, and `neutral_hue`.
 
505
  + theme_var_input
506
  )
507
 
508
+ def load_theme(theme_name, custom_theme: gr.themes.Base = None):
509
+ if custom_theme:
510
+ theme = custom_theme
511
+ else:
512
+ theme = [theme for theme in themes if theme.__name__ == theme_name][0]
513
+ theme = theme()
514
+ print(theme.__dict__)
515
  parameters = inspect.signature(theme.__init__).parameters
516
  primary_hue = parameters["primary_hue"].default
517
  secondary_hue = parameters["secondary_hue"].default
 
520
  spacing_size = parameters["spacing_size"].default
521
  radius_size = parameters["radius_size"].default
522
 
523
+
524
 
525
  font = theme._font[:4]
526
  font_mono = theme._font_mono[:4]
 
555
  + var_output
556
  )
557
 
558
+ def load_custom_theme(custom_theme_name):
559
+ print("load custom theme")
560
+ theme = gr.Theme.from_hub(custom_theme_name)
561
+ print("loaded custom theme")
562
+ return load_theme(theme.name, theme)
563
+
564
+
565
+ load_custom_theme_btn.click(load_custom_theme, custom_theme_name, theme_inputs, show_api=False)
566
+
567
  def generate_theme_code(
568
  base_theme, final_theme, core_variables, final_main_fonts, final_mono_fonts
569
  ):
 
646
  diff = True
647
  if diff:
648
  new_final_attr_values = {}
649
+ # We need to update the theme keys to match the color and size attribute names
650
  for key, val in final_attr_values.items():
651
  if key.startswith(("primary_", "secondary_", "neutral_")):
652
  color_key = "c" + key.split("_")[-1]
 
656
  new_final_attr_values[size_key] = val
657
  else:
658
  new_final_attr_values[key] = val
659
+ specific_core_diffs[value_name] = (
660
+ source_class,
661
+ new_final_attr_values,
662
+ )
663
 
664
  font_diffs = {}
665