@@ -1378,6 +1378,7 @@ def get_model_files(
1378
1378
model_name_or_path : Union [str , Path ],
1379
1379
subfolder : str = "" ,
1380
1380
cache_dir : str = huggingface_hub .constants .HUGGINGFACE_HUB_CACHE ,
1381
+ use_auth_token : Optional [str ] = None ,
1381
1382
):
1382
1383
request_exception = None
1383
1384
full_model_path = Path (model_name_or_path ) / subfolder
@@ -1391,7 +1392,9 @@ def get_model_files(
1391
1392
try :
1392
1393
if not isinstance (model_name_or_path , str ):
1393
1394
model_name_or_path = str (model_name_or_path )
1394
- all_files = huggingface_hub .list_repo_files (model_name_or_path , repo_type = "model" )
1395
+ all_files = huggingface_hub .list_repo_files (
1396
+ model_name_or_path , repo_type = "model" , token = use_auth_token
1397
+ )
1395
1398
if subfolder != "" :
1396
1399
all_files = [file [len (subfolder ) + 1 :] for file in all_files if file .startswith (subfolder )]
1397
1400
except RequestsConnectionError as e : # Hub not accessible
@@ -1672,6 +1675,7 @@ def infer_library_from_model(
1672
1675
revision : Optional [str ] = None ,
1673
1676
cache_dir : str = huggingface_hub .constants .HUGGINGFACE_HUB_CACHE ,
1674
1677
library_name : Optional [str ] = None ,
1678
+ use_auth_token : Optional [str ] = None ,
1675
1679
):
1676
1680
"""
1677
1681
Infers the library from the model repo.
@@ -1689,13 +1693,17 @@ def infer_library_from_model(
1689
1693
Path to a directory in which a downloaded pretrained model weights have been cached if the standard cache should not be used.
1690
1694
library_name (`Optional[str]`, *optional*):
1691
1695
The library name of the model. Can be any of "transformers", "timm", "diffusers", "sentence_transformers".
1696
+ use_auth_token (`Optional[str]`, defaults to `None`):
1697
+ The token to use as HTTP bearer authorization for remote files.
1692
1698
Returns:
1693
1699
`str`: The library name automatically detected from the model repo.
1694
1700
"""
1695
1701
if library_name is not None :
1696
1702
return library_name
1697
1703
1698
- all_files , _ = TasksManager .get_model_files (model_name_or_path , subfolder , cache_dir )
1704
+ all_files , _ = TasksManager .get_model_files (
1705
+ model_name_or_path , subfolder , cache_dir , use_auth_token = use_auth_token
1706
+ )
1699
1707
1700
1708
if "model_index.json" in all_files :
1701
1709
library_name = "diffusers"
@@ -1710,6 +1718,7 @@ def infer_library_from_model(
1710
1718
"subfolder" : subfolder ,
1711
1719
"revision" : revision ,
1712
1720
"cache_dir" : cache_dir ,
1721
+ "use_auth_token" : use_auth_token ,
1713
1722
}
1714
1723
config_dict , kwargs = PretrainedConfig .get_config_dict (model_name_or_path , ** kwargs )
1715
1724
model_config = PretrainedConfig .from_dict (config_dict , ** kwargs )
0 commit comments