prodya-dev commited on
Commit
dc78349
·
1 Parent(s): f25cb9c

fix: restore HfFolder shim (gradio 5.0.0 oauth.py still uses it)

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -29,6 +29,25 @@ import io
29
  import os
30
  import sys
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  import gradio as gr
33
  import torch
34
  import numpy as np
 
29
  import os
30
  import sys
31
 
32
+ # HfFolder was removed from huggingface_hub>=0.26 but gradio[oauth] still uses it.
33
+ # Patch it back before gradio is imported (affects both gradio 4.x and 5.0.x).
34
+ try:
35
+ from huggingface_hub import HfFolder # noqa: F401 — exists, nothing to do
36
+ except ImportError:
37
+ import huggingface_hub as _hfh
38
+ class _HfFolder:
39
+ @staticmethod
40
+ def get_token():
41
+ try:
42
+ from huggingface_hub import get_token
43
+ return get_token()
44
+ except Exception:
45
+ return None
46
+ @staticmethod
47
+ def save_token(token: str) -> None:
48
+ pass
49
+ _hfh.HfFolder = _HfFolder # type: ignore[attr-defined]
50
+
51
  import gradio as gr
52
  import torch
53
  import numpy as np