freddyaboulton HF staff commited on
Commit
1275c85
1 Parent(s): 63c856e

Updating theme

Browse files
Files changed (4) hide show
  1. app.py +20 -12
  2. requirements.txt +1 -1
  3. theme_dropdown.py +55 -0
  4. themes/[email protected] +1 -0
app.py CHANGED
@@ -2,18 +2,25 @@ import time
2
 
3
  import gradio as gr
4
 
5
- with gr.Blocks(theme='freddyaboulton/dracula_revamped') as demo:
6
- gr.Markdown(
7
- """
8
- # Theme preview: `dracula_revamped`
9
-
10
- To use this theme, set `theme='freddyaboulton/dracula_revamped'` in `gr.Blocks()` or `gr.Interface()`.
11
-
12
- You can append an `@` and a semantic version expression, e.g. @>=1.0.0,<2.0.0 to pin to a given version
13
- of this theme.
14
- """
15
- )
16
- toggle_dark = gr.Button("Toggle Dark").style(full_width=False)
 
 
 
 
 
 
 
17
  toggle_dark.click(
18
  None,
19
  _js="""
@@ -24,6 +31,7 @@ with gr.Blocks(theme='freddyaboulton/dracula_revamped') as demo:
24
  """,
25
  )
26
 
 
27
  name = gr.Textbox(
28
  label="Name",
29
  info="Full name, including middle name. No special characters.",
 
2
 
3
  import gradio as gr
4
 
5
+ from theme_dropdown import create_theme_dropdown
6
+
7
+ dropdown, js = create_theme_dropdown()
8
+
9
+ with gr.Blocks(theme="freddyaboulton/dracula_revamped") as demo:
10
+ with gr.Row().style(equal_height=True):
11
+ with gr.Column(scale=10):
12
+ gr.Markdown("""
13
+ # Theme preview: `dracula_revamped`
14
+ To use this theme, set `theme='freddyaboulton/dracula_revamped'` in `gr.Blocks()` or `gr.Interface()`.
15
+ You can append an `@` and a semantic version expression, e.g. @>=1.0.0,<2.0.0 to pin to a given version
16
+ of this theme.
17
+ """)
18
+ with gr.Column(scale=3):
19
+ with gr.Box():
20
+ dropdown.render()
21
+ toggle_dark = gr.Button(value="Toggle Dark").style(full_width=True)
22
+
23
+ dropdown.change(None, dropdown, None, _js=js)
24
  toggle_dark.click(
25
  None,
26
  _js="""
 
31
  """,
32
  )
33
 
34
+
35
  name = gr.Textbox(
36
  label="Name",
37
  info="Full name, including middle name. No special characters.",
requirements.txt CHANGED
@@ -1 +1 @@
1
- https://gradio-builds.s3.amazonaws.com/theme-share/attempt-8/gradio-3.20.1-py3-none-any.whl
 
1
+ https://gradio-builds.s3.amazonaws.com/theme-share/attempt-8/gradio-3.21.0-py3-none-any.whl
theme_dropdown.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import pathlib
3
+
4
+ from gradio.themes.utils.semver_match import ThemeAsset
5
+
6
+
7
+ def create_theme_dropdown():
8
+ import gradio as gr
9
+
10
+ asset_path = pathlib.Path(__file__).parent / "themes"
11
+ themes = []
12
+ for theme_asset in os.listdir(str(asset_path)):
13
+ themes.append(
14
+ (ThemeAsset(theme_asset), gr.Theme.load(str(asset_path / theme_asset)))
15
+ )
16
+
17
+ def make_else_if(theme_asset):
18
+ return f"""
19
+ else if (theme == '{str(theme_asset[0].version)}') {{
20
+ var theme_css = `{theme_asset[1]._get_theme_css()}`
21
+ }}"""
22
+
23
+ head, tail = themes[0], themes[1:]
24
+ if_statement = f"""
25
+ if (theme == "{str(head[0].version)}") {{
26
+ var theme_css = `{head[1]._get_theme_css()}`
27
+ }} {" ".join(make_else_if(t) for t in tail)}
28
+ """
29
+
30
+ latest_to_oldest = sorted([t[0] for t in themes], key=lambda asset: asset.version)[
31
+ ::-1
32
+ ]
33
+ latest_to_oldest = [str(t.version) for t in latest_to_oldest]
34
+
35
+ component = gr.Dropdown(
36
+ choices=latest_to_oldest, value=latest_to_oldest[0], render=False,
37
+ label="Select Version"
38
+ ).style(container=False)
39
+
40
+ return (
41
+ component,
42
+ f"""
43
+ (theme) => {{
44
+ if (!document.querySelector('.theme-css')) {{
45
+ var theme_elem = document.createElement('style');
46
+ theme_elem.classList.add('theme-css');
47
+ document.head.appendChild(theme_elem);
48
+ }} else {{
49
+ var theme_elem = document.querySelector('.theme-css');
50
+ }}
51
+ {if_statement}
52
+ theme_elem.innerHTML = theme_css;
53
+ }}
54
+ """,
55
+ )
themes/[email protected] ADDED
@@ -0,0 +1 @@
 
 
1
+ {"theme": {"block_background": "#7280ad", "block_background_dark": "*neutral_800", "block_border_color": "*color_border_primary", "block_border_color_dark": "*color_border_primary", "block_border_width": "1px", "block_border_width_dark": "1px", "block_info_color": "#f8f8f2", "block_info_color_dark": "#f8f8f2", "block_info_color_size": "*text_sm", "block_info_color_weight": "400", "block_label_background": "*color_background_primary", "block_label_background_dark": "*color_background_secondary", "block_label_border_color": "*color_border_primary", "block_label_border_color_dark": "*color_border_primary", "block_label_border_width": "1px", "block_label_border_width_dark": "1px", "block_label_color": "#f8f8f2", "block_label_color_dark": "#f8f8f2", "block_label_icon_color": "*block_label_color", "block_label_margin": "0", "block_label_padding": "*spacing_sm *spacing_lg", "block_label_radius": "calc(*radius_lg - 1px) 0 calc(*radius_lg - 1px) 0", "block_label_right_radius": "0 calc(*radius_lg - 1px) 0 calc(*radius_lg - 1px)", "block_label_text_size": "*text_sm", "block_label_text_weight": "400", "block_padding": "*spacing_xl calc(*spacing_xl + 2px)", "block_radius": "*radius_lg", "block_shadow": "none", "block_shadow_dark": "none", "block_title_background": "none", "block_title_background_dark": "none", "block_title_border_color": "none", "block_title_border_color_dark": "none", "block_title_border_width": "0px", "block_title_border_width_dark": "0px", "block_title_color": "#f8f8f2", "block_title_color_dark": "#f8f8f2", "block_title_padding": "0", "block_title_radius": "none", "block_title_text_size": "*text_md", "block_title_text_weight": "400", "body_background_color": "*color_background_primary", "body_background_color_dark": "*color_background_primary", "body_text_color": "#f8f8f2", "body_text_color_dark": "#f8f8f2", "body_text_size": "*text_md", "body_text_weight": "400", "button_border_width": "*input_border_width", "button_cancel_background": "#fecaca", "button_cancel_background_dark": "#b91c1c", "button_cancel_background_hover": "*button_cancel_background", "button_cancel_background_hover_dark": "*button_cancel_background_hover", "button_cancel_border_color": "#fecaca", "button_cancel_border_color_dark": "#dc2626", "button_cancel_border_color_hover": "*button_cancel_border_color", "button_cancel_border_color_hover_dark": "*button_cancel_border_color", "button_cancel_text_color": "#dc2626", "button_cancel_text_color_dark": "white", "button_cancel_text_color_hover": "*button_cancel_text_color", "button_cancel_text_color_hover_dark": "*button_cancel_text_color", "button_large_padding": "*spacing_lg calc(2 * *spacing_lg)", "button_large_radius": "*radius_lg", "button_large_text_size": "*text_lg", "button_large_text_weight": "600", "button_primary_background": "#ffa1d7", "button_primary_background_dark": "#ff79c6", "button_primary_background_hover": "*button_primary_background", "button_primary_background_hover_dark": "*button_primary_background", "button_primary_border_color": "*primary_200", "button_primary_border_color_dark": "*primary_600", "button_primary_border_color_hover": "*button_primary_border_color", "button_primary_border_color_hover_dark": "*button_primary_border_color", "button_primary_text_color": "*primary_600", "button_primary_text_color_dark": "white", "button_primary_text_color_hover": "*button_primary_text_color", "button_primary_text_color_hover_dark": "*button_primary_text_color", "button_secondary_background": "*neutral_200", "button_secondary_background_dark": "*neutral_600", "button_secondary_background_hover": "*button_secondary_background", "button_secondary_background_hover_dark": "*button_secondary_background", "button_secondary_border_color": "*neutral_200", "button_secondary_border_color_dark": "*neutral_600", "button_secondary_border_color_hover": "*button_secondary_border_color", "button_secondary_border_color_hover_dark": "*button_secondary_border_color", "button_secondary_text_color": "#f8f8f2", "button_secondary_text_color_dark": "white", "button_secondary_text_color_hover": "*button_secondary_text_color", "button_secondary_text_color_hover_dark": "*button_secondary_text_color", "button_shadow": "none", "button_shadow_active": "none", "button_shadow_hover": "none", "button_small_padding": "*spacing_sm calc(2 * *spacing_sm)", "button_small_radius": "*radius_lg", "button_small_text_size": "*text_md", "button_small_text_weight": "400", "button_transition": "background-color 0.2s ease", "checkbox_background": "*color_background_primary", "checkbox_background_dark": "*neutral_800", "checkbox_background_focus": "*color_background_primary", "checkbox_background_focus_dark": "*checkbox_background", "checkbox_background_hover": "*color_background_primary", "checkbox_background_hover_dark": "*checkbox_background", "checkbox_background_selected": "#ffa1d7", "checkbox_background_selected_dark": "#ff79c6", "checkbox_border_color": "*neutral_300", "checkbox_border_color_dark": "*neutral_700", "checkbox_border_color_focus": "*secondary_500", "checkbox_border_color_focus_dark": "*secondary_500", "checkbox_border_color_hover": "*neutral_300", "checkbox_border_color_hover_dark": "*neutral_600", "checkbox_border_color_selected": "*secondary_600", "checkbox_border_color_selected_dark": "*secondary_600", "checkbox_border_radius": "*radius_sm", "checkbox_border_width": "*input_border_width", "checkbox_label_background": "*neutral_200", "checkbox_label_background_dark": "*neutral_600", "checkbox_label_background_hover": "*checkbox_label_background", "checkbox_label_background_hover_dark": "*checkbox_label_background", "checkbox_label_background_selected": "*checkbox_label_background", "checkbox_label_background_selected_dark": "*checkbox_label_background", "checkbox_label_border_color": "*color_border_primary", "checkbox_label_border_color_dark": "*color_border_primary", "checkbox_label_border_color_hover": "*color_border_primary", "checkbox_label_border_color_hover_dark": "*color_border_primary", "checkbox_label_border_width": "*input_border_width", "checkbox_label_gap": "*spacing_lg", "checkbox_label_padding": "*spacing_md calc(2 * *spacing_md)", "checkbox_label_shadow": "none", "checkbox_label_text_size": "*text_md", "checkbox_label_text_weight": "400", "checkbox_shadow": "*input_shadow", "checkbox_text_color": "*body_text_color", "checkbox_text_color_dark": "*body_text_color", "checkbox_text_color_selected": "*checkbox_text_color", "checkbox_text_color_selected_dark": "*checkbox_text_color", "color_accent": "*primary_500", "color_accent_soft": "#919cbf", "color_accent_soft_dark": "*neutral_700", "color_background_primary": "#586794", "color_background_primary_dark": "*neutral_950", "color_background_secondary": "#586794", "color_background_secondary_dark": "*neutral_900", "color_border_accent": "#818eb6", "color_border_accent_dark": "*neutral_600", "color_border_primary": "*neutral_200", "color_border_primary_dark": "*neutral_700", "container_radius": "*radius_lg", "embed_radius": "*radius_lg", "error_background": "#fee2e2", "error_background_dark": "*color_background_primary", "error_border_color": "#fecaca", "error_border_color_dark": "*color_border_primary", "error_border_width": "1px", "error_border_width_dark": "*error_border_width", "error_color": "#ef4444", "error_color_dark": "#ef4444", "form_gap_width": "0px", "header_text_weight": "600", "input_background": "*neutral_100", "input_background_dark": "*neutral_700", "input_background_focus": "*secondary_500", "input_background_focus_dark": "*secondary_600", "input_background_hover": "*input_background", "input_background_hover_dark": "*input_background", "input_border_color": "*color_border_primary", "input_border_color_dark": "*color_border_primary", "input_border_color_focus": "*secondary_300", "input_border_color_focus_dark": "*neutral_700", "input_border_color_hover": "*color_border_primary", "input_border_color_hover_dark": "*color_border_primary", "input_border_width": "0px", "input_padding": "*spacing_xl", "input_placeholder_color": "*neutral_400", "input_placeholder_color_dark": "*neutral_500", "input_radius": "*radius_lg", "input_shadow": "none", "input_shadow_dark": "*input_shadow", "input_shadow_focus": "*input_shadow", "input_shadow_focus_dark": "*input_shadow", "input_text_size": "*text_md", "input_text_weight": "400", "layout_gap": "*spacing_xxl", "loader_color": "*color_accent", "loader_color_dark": "*color_accent", "neutral_100": "#919cbf", "neutral_200": "#818eb6", "neutral_300": "#7280ad", "neutral_400": "#6272a4", "neutral_50": "#a1aac8", "neutral_500": "#586794", "neutral_600": "#4e5b83", "neutral_700": "#455073", "neutral_800": "#3b4462", "neutral_900": "#313952", "neutral_950": "#272e42", "panel_background": "*color_background_secondary", "panel_background_dark": "*color_background_secondary", "panel_border_color": "*color_border_primary", "panel_border_color_dark": "*color_border_primary", "panel_border_width": "0", "primary_100": "#fce7f3", "primary_200": "#fbcfe8", "primary_300": "#f9a8d4", "primary_400": "#f472b6", "primary_50": "#fdf2f8", "primary_500": "#ec4899", "primary_600": "#db2777", "primary_700": "#be185d", "primary_800": "#9d174d", "primary_900": "#831843", "primary_950": "#6e1a3d", "prose_text_size": "*text_md", "prose_text_weight": "400", "radius_lg": "8px", "radius_md": "6px", "radius_sm": "4px", "radius_xl": "12px", "radius_xs": "2px", "radius_xxl": "22px", "radius_xxs": "1px", "secondary_100": "#dbeafe", "secondary_200": "#bfdbfe", "secondary_300": "#93c5fd", "secondary_400": "#60a5fa", "secondary_50": "#eff6ff", "secondary_500": "#3b82f6", "secondary_600": "#2563eb", "secondary_700": "#1d4ed8", "secondary_800": "#1e40af", "secondary_900": "#1e3a8a", "secondary_950": "#1d3660", "section_text_size": "*text_md", "section_text_weight": "400", "shadow_drop": "rgba(0,0,0,0.05) 0px 1px 2px 0px", "shadow_drop_lg": "0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)", "shadow_inset": "rgba(0,0,0,0.05) 0px 2px 4px 0px inset", "shadow_spread": "3px", "shadow_spread_dark": "1px", "slider_color": "#ffa1d7", "slider_color_dark": "#ff79c6", "spacing_lg": "8px", "spacing_md": "6px", "spacing_sm": "4px", "spacing_xl": "10px", "spacing_xs": "2px", "spacing_xxl": "16px", "spacing_xxs": "1px", "stat_color_background": "*primary_300", "stat_color_background_dark": "*primary_500", "table_border_color": "*neutral_300", "table_border_color_dark": "*neutral_700", "table_even_background": "#7280ad", "table_even_background_dark": "*neutral_950", "table_odd_background": "*neutral_50", "table_odd_background_dark": "*neutral_900", "table_radius": "*radius_lg", "table_row_focus": "*color_accent_soft", "table_row_focus_dark": "*color_accent_soft", "text_color_code_background": "*neutral_200", "text_color_code_background_dark": "*neutral_800", "text_color_code_border": "*color_border_primary", "text_color_link": "*secondary_600", "text_color_link_active": "*secondary_600", "text_color_link_active_dark": "*secondary_500", "text_color_link_dark": "*secondary_500", "text_color_link_hover": "*secondary_700", "text_color_link_hover_dark": "*secondary_400", "text_color_link_visited": "*secondary_500", "text_color_link_visited_dark": "*secondary_600", "text_color_subdued": "#f8f8f2", "text_color_subdued_dark": "*neutral_400", "text_lg": "16px", "text_md": "14px", "text_sm": "12px", "text_xl": "22px", "text_xs": "10px", "text_xxl": "26px", "text_xxs": "9px"}, "version": "0.2.3"}