amitlals commited on
Commit
39d5e86
·
1 Parent(s): 512757f

Add huggingface_hub HfFolder compatibility shim

Browse files
Files changed (1) hide show
  1. app_gradio.py +39 -0
app_gradio.py CHANGED
@@ -9,6 +9,45 @@ Main Gradio application with tabs:
9
  - OData: Connect to SAP OData services
10
  """
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  import gradio as gr
13
  print(f"Gradio version: {gr.__version__}")
14
  import pandas as pd
 
9
  - OData: Connect to SAP OData services
10
  """
11
 
12
+ import importlib
13
+ import os
14
+
15
+
16
+ def _ensure_hf_folder_compat():
17
+ """Reintroduce gradio's expected huggingface_hub.HfFolder symbol."""
18
+ try:
19
+ from huggingface_hub import HfFolder # noqa: F401
20
+ return
21
+ except ImportError:
22
+ pass
23
+
24
+ try:
25
+ hub_module = importlib.import_module("huggingface_hub")
26
+ except ModuleNotFoundError:
27
+ return
28
+
29
+ if hasattr(hub_module, "HfFolder"):
30
+ return
31
+
32
+ class _CompatHfFolder:
33
+ @staticmethod
34
+ def get_token(token_path=None):
35
+ return os.getenv("HUGGINGFACE_TOKEN")
36
+
37
+ @staticmethod
38
+ def save_token(token, token_path=None):
39
+ if token:
40
+ os.environ["HUGGINGFACE_TOKEN"] = token
41
+
42
+ @staticmethod
43
+ def delete_token(token_path=None):
44
+ os.environ.pop("HUGGINGFACE_TOKEN", None)
45
+
46
+ hub_module.HfFolder = _CompatHfFolder
47
+
48
+
49
+ _ensure_hf_folder_compat()
50
+
51
  import gradio as gr
52
  print(f"Gradio version: {gr.__version__}")
53
  import pandas as pd