()
| 663 | |
| 664 | |
| 665 | def _patch_hub(): |
| 666 | import huggingface_hub |
| 667 | from huggingface_hub import hf_api |
| 668 | from huggingface_hub.hf_api import api |
| 669 | from huggingface_hub.hf_api import future_compatible |
| 670 | from modelscope import get_logger |
| 671 | logger = get_logger() |
| 672 | |
| 673 | def _file_exists( |
| 674 | self, |
| 675 | repo_id: str, |
| 676 | filename: str, |
| 677 | *, |
| 678 | repo_type: Optional[str] = None, |
| 679 | revision: Optional[str] = None, |
| 680 | token: Union[str, bool, None] = None, |
| 681 | ): |
| 682 | """Patch huggingface_hub.file_exists""" |
| 683 | if repo_type is not None: |
| 684 | logger.warning( |
| 685 | 'The passed in repo_type will not be used in modelscope. Now only model repo can be queried.' |
| 686 | ) |
| 687 | from modelscope.hub.api import HubApi |
| 688 | api = HubApi() |
| 689 | api.login(token) |
| 690 | if revision is None or revision == 'main': |
| 691 | revision = 'master' |
| 692 | return api.file_exists(repo_id, filename, revision=revision) |
| 693 | |
| 694 | def _file_download(repo_id: str, |
| 695 | filename: str, |
| 696 | *, |
| 697 | subfolder: Optional[str] = None, |
| 698 | repo_type: Optional[str] = None, |
| 699 | revision: Optional[str] = None, |
| 700 | cache_dir: Union[str, Path, None] = None, |
| 701 | local_dir: Union[str, Path, None] = None, |
| 702 | token: Union[bool, str, None] = None, |
| 703 | local_files_only: bool = False, |
| 704 | **kwargs): |
| 705 | """Patch huggingface_hub.hf_hub_download""" |
| 706 | if len(kwargs) > 0: |
| 707 | logger.warning( |
| 708 | 'The passed in library_name,library_version,user_agent,force_download,proxies' |
| 709 | 'etag_timeout,headers,endpoint ' |
| 710 | 'will not be used in modelscope.') |
| 711 | assert repo_type in ( |
| 712 | None, 'model', |
| 713 | 'dataset'), f'repo_type={repo_type} is not supported in ModelScope' |
| 714 | if repo_type in (None, 'model'): |
| 715 | from modelscope.hub.file_download import model_file_download as file_download |
| 716 | else: |
| 717 | from modelscope.hub.file_download import dataset_file_download as file_download |
| 718 | from modelscope import HubApi |
| 719 | api = HubApi() |
| 720 | api.login(token) |
| 721 | if revision is None or revision == 'main': |
| 722 | revision = 'master' |
no test coverage detected
searching dependent graphs…