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

* 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>
This commit is contained in:
Abubakar Abid 2023-11-06 15:40:08 -08:00 committed by GitHub
parent 7ab73df48e
commit 176c4d1400
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 12 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:Temporary fix to be able to load themes from Hub

View File

@ -17,8 +17,9 @@ class ThemeAsset:
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)

View File

@ -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"
);

View File

@ -252,17 +252,22 @@ class TestGetThemeAssets:
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)
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)
# 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)
class TestBuiltInThemes: