Summary
Fresh installs from requirements-app.txt are currently broken: import gradio raises ImportError: cannot import name 'HfFolder' from 'huggingface_hub' before app.py runs. The fix is one upper-bound pin in requirements-app.txt.
Reproducer
git clone https://github.com/Zeyi-Lin/HivisionIDPhotos.git
cd HivisionIDPhotos
git checkout v1.3.1
python3.12 -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt -r requirements-app.txt
python app.py --host 127.0.0.1 --port 7860
Result:
File "<...>/.venv/lib/python3.12/site-packages/gradio/oauth.py", line 13, in <module>
from huggingface_hub import HfFolder, whoami
ImportError: cannot import name 'HfFolder' from 'huggingface_hub'
Root cause
| Layer |
Pin |
Resolves to |
Status |
requirements-app.txt |
gradio>=4.43.0 (no upper bound) |
gradio 6.x today |
breaks show_api=False (separate issue) |
With gradio<5 workaround |
— |
gradio 4.44.1 |
OK |
| gradio 4.44.1 → huggingface-hub |
>=0.19.3 (no upper bound) |
huggingface_hub 1.13.0 |
breaks |
| huggingface_hub 1.0.0+ |
— |
(HfFolder removed) |
ImportError |
gradio/oauth.py in 4.x imports HfFolder at module top level, so import gradio triggers the chain and fails.
Verified:
- huggingface_hub 0.36.2 (latest 0.x): exports
HfFolder (4 references in __init__.py)
- huggingface_hub 1.0.0+:
HfFolder removed
- gradio 4.44.1's
oauth.py: from huggingface_hub import HfFolder, whoami (and uses HfFolder.get_token())
Suggested fix
Add one line to requirements-app.txt:
gradio>=4.43.0
+huggingface_hub<1
fastapi
<1 resolves to the highest 0.x (currently 0.36.2). The 0→1 boundary is the canonical breaking-change line in huggingface_hub, so this stays valid through 0.x security patches without freezing to a specific version.
This is a workaround until the gradio 5 upgrade tracked in #187 lands, at which point the right fix is to drop the upper bound on huggingface_hub once gradio 5 imports it correctly.
Related
Context
Surfaced while authoring an OS8 App Store catalog manifest for HivisionIDPhotos. We've worked around it on our side by pinning both gradio<5 and huggingface_hub<1 in our manifest's postInstall, but anyone installing from requirements-app.txt directly is currently blocked at import gradio.
Happy to send a PR if it'd be useful.
Summary
Fresh installs from
requirements-app.txtare currently broken:import gradioraisesImportError: cannot import name 'HfFolder' from 'huggingface_hub'beforeapp.pyruns. The fix is one upper-bound pin inrequirements-app.txt.Reproducer
Result:
Root cause
requirements-app.txtgradio>=4.43.0(no upper bound)show_api=False(separate issue)gradio<5workaround>=0.19.3(no upper bound)ImportErrorgradio/oauth.pyin 4.x importsHfFolderat module top level, soimport gradiotriggers the chain and fails.Verified:
HfFolder(4 references in__init__.py)HfFolderremovedoauth.py:from huggingface_hub import HfFolder, whoami(and usesHfFolder.get_token())Suggested fix
Add one line to
requirements-app.txt:gradio>=4.43.0 +huggingface_hub<1 fastapi<1resolves to the highest 0.x (currently 0.36.2). The 0→1 boundary is the canonical breaking-change line inhuggingface_hub, so this stays valid through 0.x security patches without freezing to a specific version.This is a workaround until the gradio 5 upgrade tracked in #187 lands, at which point the right fix is to drop the upper bound on huggingface_hub once gradio 5 imports it correctly.
Related
Context
Surfaced while authoring an OS8 App Store catalog manifest for HivisionIDPhotos. We've worked around it on our side by pinning both
gradio<5andhuggingface_hub<1in our manifest's postInstall, but anyone installing fromrequirements-app.txtdirectly is currently blocked atimport gradio.Happy to send a PR if it'd be useful.