DawnC commited on
Commit
b7153be
·
verified ·
1 Parent(s): 2f59ff9

Create huggingface_patch.py

Browse files
Files changed (1) hide show
  1. huggingface_patch.py +41 -0
huggingface_patch.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import huggingface_hub
2
+ import sys
3
+ import warnings
4
+
5
+ # Check if cached_download exists
6
+ if not hasattr(huggingface_hub, 'cached_download'):
7
+ # Provide a fallback function
8
+ def cached_download(*args, **kwargs):
9
+ """
10
+ Simulates the behavior of the deprecated cached_download function.
11
+ Internally uses the newer hf_hub_download function.
12
+ """
13
+ warnings.warn(
14
+ "Using a simulated version of cached_download. This function has been removed in the newer version of huggingface_hub.",
15
+ DeprecationWarning,
16
+ stacklevel=2
17
+ )
18
+ # Call the new equivalent function
19
+ return huggingface_hub.hf_hub_download(*args, **kwargs)
20
+
21
+ # Add the simulated function to the huggingface_hub module
22
+ huggingface_hub.cached_download = cached_download
23
+ print("Successfully added simulated cached_download function to huggingface_hub")
24
+ else:
25
+ print("huggingface_hub already includes the cached_download function")
26
+
27
+ # For more comprehensive patching, check and add the model_info function
28
+ if not hasattr(huggingface_hub, 'model_info') and hasattr(huggingface_hub, 'api'):
29
+ def model_info(*args, **kwargs):
30
+ """Simulated version of the deprecated model_info function"""
31
+ warnings.warn(
32
+ "Using a simulated version of model_info. This function may have been moved or renamed in the newer version of huggingface_hub.",
33
+ DeprecationWarning,
34
+ stacklevel=2
35
+ )
36
+ # Use the newer equivalent API
37
+ return huggingface_hub.api.model_info(*args, **kwargs)
38
+
39
+ # Add to the module
40
+ huggingface_hub.model_info = model_info
41
+ print("Successfully added simulated model_info function to huggingface_hub")