|  | 
| 1 | 1 | # coding=utf-8 | 
| 2 |  | -# Copyright 2024 suzukimain | 
|  | 2 | +# Copyright 2025 suzukimain | 
| 3 | 3 | # | 
| 4 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | 
| 5 | 5 | # you may not use this file except in compliance with the License. | 
|  | 
| 17 | 17 | import re | 
| 18 | 18 | import types | 
| 19 | 19 | from collections import OrderedDict | 
| 20 |  | -from dataclasses import asdict, dataclass | 
|  | 20 | +from dataclasses import asdict, dataclass, field | 
| 21 | 21 | from typing import Dict, List, Optional, Union | 
| 22 | 22 | 
 | 
| 23 | 23 | import requests | 
| @@ -321,9 +321,9 @@ class SearchResult: | 
| 321 | 321 |     model_path: str = "" | 
| 322 | 322 |     loading_method: Union[str, None] = None | 
| 323 | 323 |     checkpoint_format: Union[str, None] = None | 
| 324 |  | -    repo_status: RepoStatus = RepoStatus() | 
| 325 |  | -    model_status: ModelStatus = ModelStatus() | 
| 326 |  | -    extra_status: ExtraStatus = ExtraStatus() | 
|  | 324 | +    repo_status: RepoStatus = field(default_factory=RepoStatus) | 
|  | 325 | +    model_status: ModelStatus = field(default_factory=ModelStatus) | 
|  | 326 | +    extra_status: ExtraStatus = field(default_factory=ExtraStatus) | 
| 327 | 327 | 
 | 
| 328 | 328 | 
 | 
| 329 | 329 | @validate_hf_hub_args | 
| @@ -589,10 +589,18 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N | 
| 589 | 589 |     gated = kwargs.pop("gated", False) | 
| 590 | 590 |     skip_error = kwargs.pop("skip_error", False) | 
| 591 | 591 | 
 | 
|  | 592 | +    file_list = [] | 
|  | 593 | +    hf_repo_info = {} | 
|  | 594 | +    hf_security_info = {} | 
|  | 595 | +    model_path = "" | 
|  | 596 | +    repo_id, file_name = "", "" | 
|  | 597 | +    diffusers_model_exists = False | 
|  | 598 | + | 
| 592 | 599 |     # Get the type and loading method for the keyword | 
| 593 | 600 |     search_word_status = get_keyword_types(search_word) | 
| 594 | 601 | 
 | 
| 595 | 602 |     if search_word_status["type"]["hf_repo"]: | 
|  | 603 | +        hf_repo_info = hf_api.model_info(repo_id=search_word, securityStatus=True) | 
| 596 | 604 |         if download: | 
| 597 | 605 |             model_path = DiffusionPipeline.download( | 
| 598 | 606 |                 search_word, | 
| @@ -635,13 +643,6 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N | 
| 635 | 643 |         ) | 
| 636 | 644 |         model_dicts = [asdict(value) for value in list(hf_models)] | 
| 637 | 645 | 
 | 
| 638 |  | -        file_list = [] | 
| 639 |  | -        hf_repo_info = {} | 
| 640 |  | -        hf_security_info = {} | 
| 641 |  | -        model_path = "" | 
| 642 |  | -        repo_id, file_name = "", "" | 
| 643 |  | -        diffusers_model_exists = False | 
| 644 |  | - | 
| 645 | 646 |         # Loop through models to find a suitable candidate | 
| 646 | 647 |         for repo_info in model_dicts: | 
| 647 | 648 |             repo_id = repo_info["id"] | 
| @@ -706,6 +707,10 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N | 
| 706 | 707 |                     force_download=force_download, | 
| 707 | 708 |                 ) | 
| 708 | 709 | 
 | 
|  | 710 | +    # `pathlib.PosixPath` may be returned | 
|  | 711 | +    if model_path: | 
|  | 712 | +        model_path = str(model_path) | 
|  | 713 | + | 
| 709 | 714 |     if file_name: | 
| 710 | 715 |         download_url = f"https://huggingface.co/{repo_id}/blob/main/{file_name}" | 
| 711 | 716 |     else: | 
|  | 
0 commit comments