@@ -535,17 +535,17 @@ def _get_safe_alternatives(filename: str) -> Iterable[str]:
535535 yield filename [:- 4 ] + ".safetensors"
536536
537537
538- def _get_license_from_hf_hub (hf_hub_id : str | None ) -> str | None :
538+ def _get_license_from_hf_hub (model_id : str | None , hf_hub_id : str | None ) -> str | None :
539539 """Retrieve license information for a model from Hugging Face Hub.
540540
541541 Fetches the license field from the model card metadata on Hugging Face Hub
542- for the specified model. This function is called lazily when the license
543- attribute is accessed on PretrainedCfg objects that don't have an explicit
544- license set.
542+ for the specified model. Returns None if the model is not found, if
543+ huggingface_hub is not installed, or if the model is marked as "untrained".
545544
546545 Args:
547- hf_hub_id: The Hugging Face Hub model ID (e.g., 'organization/model').
548- If None or empty, returns None as license cannot be determined.
546+ model_id: The model identifier/name. In the case of None we assume an untrained model.
547+ hf_hub_id: The Hugging Face Hub organization/user ID. If it is None,
548+ we will return None as we cannot infer the license terms.
549549
550550 Returns:
551551 The license string in lowercase if found, None otherwise.
@@ -559,17 +559,17 @@ def _get_license_from_hf_hub(hf_hub_id: str | None) -> str | None:
559559 _logger .warning (msg = msg )
560560 return None
561561
562- if hf_hub_id is None or hf_hub_id == "timm/" :
562+ if not ( model_id and hf_hub_id ) :
563563 return None
564564
565+ repo_id : str = hf_hub_id + model_id
566+
565567 try :
566- info = model_info (repo_id = hf_hub_id )
568+ info = model_info (repo_id = repo_id )
567569
568570 except RepositoryNotFoundError :
569571 # TODO: any wish what happens here? @rwightman
570- return None
571-
572- except Exception as _ :
572+ print (repo_id )
573573 return None
574574
575575 license = info .card_data .get ("license" ).lower () if info .card_data else None
0 commit comments