Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary fix to be able to load themes from Hub #6311

Merged
merged 7 commits into from Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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