Skip to content

fix: bump gradio to v5 (resolves HfFolder ImportError on Space)#3

Merged
malteos merged 2 commits into
mainfrom
fix/gradio5-bump
May 7, 2026
Merged

fix: bump gradio to v5 (resolves HfFolder ImportError on Space)#3
malteos merged 2 commits into
mainfrom
fix/gradio5-bump

Conversation

@malteos

@malteos malteos commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

The leaderboard Space (commoncrawl/commonlid) failed to boot with:

File ".../gradio/oauth.py", line 13, in <module>
    from huggingface_hub import HfFolder, whoami
ImportError: cannot import name 'HfFolder' from 'huggingface_hub'

gradio 4.x imports HfFolder from huggingface_hub. huggingface-hub 1.0 removed that name. Both deps were unbounded above, so the Space container resolved gradio==4.44.0 + huggingface-hub>=1.0 — the broken combination. Gradio 5 dropped the HfFolder import.

Changes

  • pyproject.toml: bump gradio>=4.44gradio>=5 in both the leaderboard and dev extras, with a one-line comment recording the reason.
  • hf-space/README.md: bump Space metadata sdk_version 4.44.05.9.1.
  • uv.lock: re-resolved (only the two gradio constraint markers change; the locked version moves up).
  • Makefile: add make leaderboard-hf that mirrors what the deployed Space does — loads summaries from commoncrawl/commonlid-results (the live HF dataset) instead of ./data/results/. Lets us smoke-test the Space entrypoint locally before pushing without needing a populated local results tree.

Test plan

  • make lint, make format-check, make typecheck, make test — all green (231 passed, 94.60% coverage)
  • make leaderboard-hf — boots the Gradio app locally under gradio 6.14.0 (the latest 6.x our >=5 constraint resolves to), serves on 127.0.0.1:7860, populates the leaderboard tabs from the live HF dataset. UI renders correctly (per-dataset tabs + per-row drilldowns work).
  • After merge: re-upload hf-space/ to the Space and confirm the build no longer crashes on HfFolder.

Compatibility note

Our app uses only the most stable subset of the Gradio API (Blocks, Tabs, Tab, Markdown, Dataframe, Accordion, SelectData). All forward-compatible across Gradio 4 → 5 → 6, so the only user-visible change is the bug fix.

🤖 Generated with Claude Code

malteos and others added 2 commits May 7, 2026 16:30
The deployed leaderboard Space crashed at runtime with:

  ImportError: cannot import name 'HfFolder' from 'huggingface_hub'

Cause: gradio 4.x imports `HfFolder` from `huggingface_hub`, but
`huggingface-hub` 1.0 removed that name. The Space container resolves
both unbounded and ends up with `gradio==4.44.0` + `huggingface-hub>=1`,
which is the broken combination. Gradio 5 dropped the `HfFolder`
import.

Changes:
- `pyproject.toml`: bump `gradio>=4.44` -> `gradio>=5` in both the
  `leaderboard` and `dev` extras (with a one-line comment recording
  why).
- `hf-space/README.md`: bump Space metadata `sdk_version`
  4.44.0 -> 5.9.1.
- `uv.lock`: re-resolved.
- `Makefile`: add `make leaderboard-hf` that mirrors what the deployed
  Space does (loads summaries from `commoncrawl/commonlid-results`
  instead of `./data/results/`), so we can smoke-test the Space
  entrypoint locally before pushing.

Verified locally: `make leaderboard-hf` boots the Gradio app under
gradio 6.14.0 (the latest 6.x in our resolve), serves on
127.0.0.1:7860, populates the leaderboard tabs from the live HF
dataset. No Space-side warnings about sdk_version mismatch (HF Spaces
docs: "All versions of Gradio are supported").

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add tests/hf-space/test_space_entrypoint.py with two tests:

1. `test_space_app_py_boots_and_returns_blocks` — loads
   `hf-space/app.py` exactly the way the Space runtime does (top-level
   module via `spec_from_file_location`, not via the package), with
   `commonlid.leaderboard.app.build_app` patched to read summaries from
   a tmp_path so we never touch the network. Asserts the resulting
   `demo` is a `gradio.Blocks` instance.

2. `test_gradio_imports_cleanly` — direct guard against the failure
   mode that took the production Space down: gradio 4.x + huggingface-
   hub 1.0 raised `ImportError: cannot import name 'HfFolder'` from
   inside gradio's own import chain. The existing leaderboard tests
   used `pytest.importorskip("gradio")`, which silently skips on any
   `ImportError` and would have hidden a broken-gradio environment
   behind a green CI badge. The new helper checks installation via
   `importlib.metadata` so the suite skips only when gradio is *truly
   missing* and fails when it's installed but broken.

Verified: both tests pass under the current `gradio>=5` resolve, and
both fail hard with the original `HfFolder` ImportError when forced
into a fresh venv with `gradio==4.44.0 huggingface-hub==1.14.0`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@malteos malteos merged commit 858327d into main May 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant