Skip to content

Commit

Permalink
Temporary fix to be able to load themes from Hub (#6311)
Browse files Browse the repository at this point in the history
* Add code

* push temporary fix for tags

* temp fix

* add changeset

* reduce

* trigger ci

---------

Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
3 people committed Nov 6, 2023
1 parent 7ab73df commit 176c4d1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-cups-jump.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:Temporary fix to be able to load themes from Hub
5 changes: 3 additions & 2 deletions gradio/themes/utils/semver_match.py
Expand Up @@ -17,8 +17,9 @@ def __post_init__(self):


def get_theme_assets(space_info: huggingface_hub.hf_api.SpaceInfo) -> list[ThemeAsset]:
if "gradio-theme" not in getattr(space_info, "tags", []):
raise ValueError(f"{space_info.id} is not a valid gradio-theme space!")
# Commenting out as it seems that the `huggingface_hub` library is not parsing tags
# if "gradio-theme" not in getattr(space_info, "tags", []):
# raise ValueError(f"{space_info.id} is not a valid gradio-theme space!")

return [
ThemeAsset(filename.rfilename)
Expand Down
1 change: 1 addition & 0 deletions js/app/test/gallery_component_events.spec.ts
Expand Up @@ -18,6 +18,7 @@ test("Gallery preview mode displays all images correctly.", async ({
test("Gallery select event returns the right value", async ({ page }) => {
await page.getByRole("button", { name: "Run" }).click();
await page.getByLabel("Thumbnail 2 of 3").click();
await page.waitForTimeout(200);
expect(await page.getByLabel("Select Data")).toHaveValue(
"https://gradio-builds.s3.amazonaws.com/assets/lite-logo.png"
);
Expand Down
25 changes: 15 additions & 10 deletions test/test_theme_sharing.py
Expand Up @@ -252,17 +252,22 @@ def test_get_theme_assets(self):
assert gr.Theme._theme_version_exists(space_info, "0.1.1")
assert not gr.Theme._theme_version_exists(space_info, "2.0.0")

def test_raises_if_space_not_properly_tagged(self):
space_info = huggingface_hub.hf_api.SpaceInfo(
id="freddyaboulton/dracula", tags=["gradio"]
)
@pytest.mark.flaky
def test_load_space_from_hub_works(self):
theme = gr.Theme.from_hub("gradio/seafoam")
assert isinstance(theme, gr.Theme)

# def test_raises_if_space_not_properly_tagged(self):
# space_info = huggingface_hub.hf_api.SpaceInfo(
# id="freddyaboulton/dracula", tags=["gradio"]
# )

with pytest.raises(
ValueError,
match="freddyaboulton/dracula is not a valid gradio-theme space!",
):
with patch("huggingface_hub.HfApi.space_info", return_value=space_info):
get_theme_assets(space_info)
# with pytest.raises(
# ValueError,
# match="freddyaboulton/dracula is not a valid gradio-theme space!",
# ):
# with patch("huggingface_hub.HfApi.space_info", return_value=space_info):
# get_theme_assets(space_info)


class TestBuiltInThemes:
Expand Down

0 comments on commit 176c4d1

Please sign in to comment.