Skip to content

Commit

Permalink
Bugfix: Fix color and size keys in theme builder app (gradio-app#7756)
Browse files Browse the repository at this point in the history
* Bugfix: Update color and size keys in theme builder app

* add changeset

* add changeset

* changes

* changes

---------

Co-authored-by: gradio-pr-bot <[email protected]>
Co-authored-by: aliabid94 <[email protected]>
Co-authored-by: Ali Abid <[email protected]>
  • Loading branch information
4 people authored Apr 2, 2024
1 parent bbdbd28 commit b729f10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/cruel-actors-say.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Bugfix: Fix color and size keys in theme builder app
23 changes: 19 additions & 4 deletions gradio/themes/builder_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,21 @@ def generate_theme_code(
if getattr(source_obj, attr) != final_attr_values[final_theme_attr]:
diff = True
if diff:
specific_core_diffs[value_name] = (source_class, final_attr_values)
new_final_attr_values = {}
# We need to update the theme keys to match the color and size attribute names
for key, val in final_attr_values.items():
if key.startswith(("primary_", "secondary_", "neutral_")):
color_key = "c" + key.split("_")[-1]
new_final_attr_values[color_key] = val
elif key.startswith(("text_", "spacing_", "radius_")):
size_key = key.split("_")[-1]
new_final_attr_values[size_key] = val
else:
new_final_attr_values[key] = val
specific_core_diffs[value_name] = (
source_class,
new_final_attr_values,
)

font_diffs = {}

Expand Down Expand Up @@ -653,9 +667,10 @@ def generate_theme_code(
cls, vals = specific_core_diffs[var_name]
core_diffs_code += f""" {var_name}=gr.themes.{cls.__name__}({', '.join(f'''{k}="{v}"''' for k, v in vals.items())}),\n"""
elif var_name in core_diffs:
core_diffs_code += (
f""" {var_name}="{core_diffs[var_name]}",\n"""
)
var_val = core_diffs[var_name]
if var_name.endswith("_size"):
var_val = var_val.split("_")[-1]
core_diffs_code += f""" {var_name}="{var_val}",\n"""

font_diffs_code = ""

Expand Down

0 comments on commit b729f10

Please sign in to comment.