auto-diffusers 2.0.33__tar.gz → 2.0.36.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: auto_diffusers
3
- Version: 2.0.33
3
+ Version: 2.0.36.dev0
4
4
  Summary: diffusers with search engine
5
5
  Home-page: https://github.com/suzukimain/auto_diffusers
6
6
  Author: suzukimain
7
- Author-email: subarucosmosmain@gmail.com
7
+ Author-email: gt13579552@gmail.com
8
8
  License: Apache 2.0 License
9
9
  Keywords: huggingface civitai diffusers model search deep learning diffusion pytorch stable diffusion
10
10
  Classifier: Development Status :: 5 - Production/Stable
@@ -17,11 +17,24 @@ Classifier: Programming Language :: Python :: 3
17
17
  Classifier: Programming Language :: Python :: 3.8
18
18
  Classifier: Programming Language :: Python :: 3.9
19
19
  Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
20
21
  Requires-Python: >=3.8.0
21
22
  Description-Content-Type: text/markdown
22
23
  License-File: LICENSE
23
- Requires-Dist: diffusers>=0.32.0
24
- Requires-Dist: transformers>=4.41.2
24
+ Requires-Dist: diffusers>=0.36.0
25
+ Requires-Dist: transformers>=4.57.3
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: keywords
33
+ Dynamic: license
34
+ Dynamic: license-file
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
25
38
 
26
39
  <p align="center">
27
40
  <br>
@@ -1,33 +1,24 @@
1
- import os
2
- import re
3
1
  import sys
4
2
 
5
3
  from setuptools import find_packages, setup
6
4
 
7
5
  _deps = [
8
- "diffusers>=0.32.0",
9
- "transformers>=4.41.2",
6
+ "diffusers>=0.36.0",
7
+ "transformers>=4.57.3",
10
8
  ]
11
9
 
12
- deps = {b: a for a, b in (re.findall(r"^(([^!=<>~]+)(?:[!=<>~].*)?$)", x)[0] for x in _deps)}
13
-
14
-
15
- def deps_list(*pkgs):
16
- return [deps[pkg] for pkg in pkgs]
17
-
18
-
19
10
  version_range_max = max(sys.version_info[1], 10) + 1
20
11
 
21
12
  setup(
22
13
  name="auto_diffusers",
23
- version="2.0.33",
14
+ version="2.0.36dev0",
24
15
  description="diffusers with search engine",
25
16
  long_description=open("README.md", "r", encoding="utf-8").read(),
26
17
  long_description_content_type="text/markdown",
27
18
  keywords="huggingface civitai diffusers model search deep learning diffusion pytorch stable diffusion",
28
19
  license="Apache 2.0 License",
29
20
  author="suzukimain",
30
- author_email="subarucosmosmain@gmail.com",
21
+ author_email="gt13579552@gmail.com",
31
22
  url="https://github.com/suzukimain/auto_diffusers",
32
23
  package_dir={"": "src"},
33
24
  packages=find_packages("src"),
@@ -1,4 +1,4 @@
1
- __version__ = "2.0.33"
1
+ __version__ = "2.0.36dev0"
2
2
 
3
3
  from .pipeline_easy import (
4
4
  search_huggingface,
@@ -65,7 +65,7 @@ from diffusers import (
65
65
  StableDiffusionXLControlNetImg2ImgPipeline,
66
66
  )
67
67
 
68
- from huggingface_hub import hf_api, hf_hub_download
68
+ from huggingface_hub import hf_api, hf_hub_download, hf_hub_url
69
69
  from huggingface_hub.file_download import http_get
70
70
  from huggingface_hub.utils import validate_hf_hub_args
71
71
 
@@ -429,6 +429,7 @@ def load_pipeline_from_single_file(
429
429
  )
430
430
 
431
431
  else:
432
+ # Load the pipeline from the checkpoint
432
433
  return pipeline_class.from_single_file(pretrained_model_or_path, **kwargs)
433
434
 
434
435
 
@@ -479,6 +480,12 @@ def get_keyword_types(keyword):
479
480
  if not os.path.exists(os.path.join(keyword, "model_index.json")):
480
481
  status["extra_type"]["missing_model_index"] = True
481
482
 
483
+ # Check if the keyword is a Civitai API download URL
484
+ elif keyword.startswith("https://civitai.com/api/download/"):
485
+ status["type"]["civitai_url"] = True
486
+ status["checkpoint_format"] = "single_file"
487
+ status["loading_method"] = "from_single_file"
488
+
482
489
  # Check if the keyword is a Civitai URL
483
490
  elif keyword.startswith("https://civitai.com/"):
484
491
  status["type"]["civitai_url"] = True
@@ -512,6 +519,54 @@ def get_keyword_types(keyword):
512
519
  return status
513
520
 
514
521
 
522
+ def validate_url_with_head(
523
+ url: str,
524
+ token: Optional[str] = None,
525
+ headers: Optional[Dict] = None,
526
+ timeout: int = 2
527
+ ) -> None:
528
+ """
529
+ Validates a URL is accessible by performing a HEAD request.
530
+ Raises HTTPError for any 4xx/5xx status codes (including 401 Unauthorized).
531
+ Logs and continues for other errors.
532
+
533
+ Parameters:
534
+ url (`str`):
535
+ The URL to validate.
536
+ token (`str`, *optional*):
537
+ Authentication token for the request.
538
+ headers (`dict`, *optional*):
539
+ Dictionary of HTTP Headers to send with the request.
540
+ If provided, takes precedence over token.
541
+ timeout (`int`, *optional*, defaults to `2`):
542
+ Timeout in seconds for the HEAD request.
543
+
544
+ Raises:
545
+ requests.HTTPError: If the URL returns any 4xx or 5xx status code.
546
+ """
547
+ if headers is None:
548
+ headers = {}
549
+ else:
550
+ # Create a copy to avoid modifying the original
551
+ headers = dict(headers)
552
+
553
+ # If token is provided and authorization not already in headers, add it
554
+ # Check case-insensitively since HTTP headers are case-insensitive
555
+ if token and not any(k.lower() == "authorization" for k in headers):
556
+ headers["Authorization"] = f"Bearer {token}"
557
+
558
+ try:
559
+ response = requests.head(url, headers=headers, allow_redirects=True, timeout=timeout)
560
+ # Raise HTTPError for any 4xx/5xx status codes (including 401)
561
+ response.raise_for_status()
562
+ except requests.HTTPError:
563
+ # Re-raise HTTPError (primarily for 401, but also other 4xx/5xx from raise_for_status)
564
+ raise
565
+ except requests.exceptions.RequestException as e:
566
+ # Log other request errors but don't fail - the actual download may still succeed
567
+ logger.info(f"HEAD check failed (continuing to download): {url} -> {e}")
568
+
569
+
515
570
  def file_downloader(
516
571
  url,
517
572
  save_path,
@@ -577,15 +632,10 @@ def file_downloader(
577
632
  mode = "ab"
578
633
  file_size = os.path.getsize(save_path)
579
634
 
580
- # Check if the URL is accessible before downloading. If HEAD returns 401,
581
- # raise an HTTPError so callers can try the next candidate. Other HEAD
582
- # failures are logged and the download is still attempted.
583
- try:
584
- response = requests.head(url, headers=headers, allow_redirects=True, timeout=2)
585
- if response.status_code == 401:
586
- raise requests.HTTPError(f"401 Unauthorized: {url}")
587
- except requests.exceptions.RequestException as e:
588
- logger.info(f"HEAD check failed (continuing to download): {url} -> {e}")
635
+ # Check if the URL is accessible before downloading. If the HEAD request returns any
636
+ # 4xx or 5xx status code, an HTTPError is raised so callers can try the next candidate.
637
+ # Only successful (2xx) responses will proceed to download.
638
+ validate_url_with_head(url, headers=headers)
589
639
 
590
640
  # Open the file in the appropriate mode (write or append)
591
641
  with open(save_path, mode) as model_file:
@@ -654,7 +704,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
654
704
  hf_security_info = {}
655
705
  model_path = ""
656
706
  repo_id, file_name = "", ""
657
- diffusers_model_exists = False
707
+ candidate_index = kwargs.pop("candidate_index", 0)
658
708
 
659
709
  # Get the type and loading method for the keyword
660
710
  search_word_status = get_keyword_types(search_word)
@@ -709,13 +759,19 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
709
759
  )
710
760
  model_dicts = [asdict(value) for value in list(hf_models)]
711
761
 
712
- # Loop through models to find a suitable candidate
762
+ # Collect all valid candidates first
763
+ candidates = []
713
764
  for repo_info in model_dicts:
714
765
  repo_id = repo_info["id"]
715
766
  file_list = []
716
- hf_repo_info = asdict(
717
- hf_api.model_info(repo_id=repo_id, securityStatus=True)
718
- )
767
+ try:
768
+ hf_repo_info = asdict(
769
+ hf_api.model_info(repo_id=repo_id, securityStatus=True)
770
+ )
771
+ except Exception as e:
772
+ logger.info(f"Failed to get repo info for {repo_id}: {e}")
773
+ continue
774
+
719
775
  # Lists files with security issues.
720
776
  hf_security_info = hf_repo_info["security_repo_status"]
721
777
  exclusion = [issue["path"] for issue in hf_security_info["filesWithIssues"]]
@@ -728,7 +784,12 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
728
784
  "diffusers",
729
785
  "all",
730
786
  ]:
731
- diffusers_model_exists = True
787
+ # Found diffusers model
788
+ candidates.append({
789
+ "type": "diffusers",
790
+ "repo_id": repo_id,
791
+ "repo_info": hf_repo_info,
792
+ })
732
793
  break
733
794
 
734
795
  elif (
@@ -743,11 +804,26 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
743
804
  )
744
805
  ):
745
806
  file_list.append(file_path)
746
-
747
- # Exit from the loop if a multi-folder diffusers model or valid file is found
748
- if diffusers_model_exists or file_list:
749
- break
750
- else:
807
+
808
+ # Add single file candidates
809
+ if file_list:
810
+ # Sort and find the safest model
811
+ file_name = next(
812
+ (
813
+ model
814
+ for model in sorted(file_list, reverse=True)
815
+ if re.search(r"(?i)[-_](safe|sfw)", model)
816
+ ),
817
+ file_list[0],
818
+ )
819
+ candidates.append({
820
+ "type": "single_file",
821
+ "repo_id": repo_id,
822
+ "file_name": file_name,
823
+ "repo_info": hf_repo_info,
824
+ })
825
+
826
+ if not candidates:
751
827
  # Handle case where no models match the criteria
752
828
  if skip_error:
753
829
  return None
@@ -756,37 +832,74 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
756
832
  "No models matching your criteria were found on huggingface."
757
833
  )
758
834
 
759
- if diffusers_model_exists:
760
- if download:
761
- model_path = DiffusionPipeline.download(
762
- repo_id,
763
- token=token,
764
- cache_dir=cache_dir,
765
- **kwargs,
766
- )
835
+ # Check if candidate_index is valid
836
+ if candidate_index >= len(candidates):
837
+ if skip_error:
838
+ return None
767
839
  else:
768
- model_path = repo_id
769
-
770
- elif file_list:
771
- # Sort and find the safest model
772
- file_name = next(
773
- (
774
- model
775
- for model in sorted(file_list, reverse=True)
776
- if re.search(r"(?i)[-_](safe|sfw)", model)
777
- ),
778
- file_list[0],
779
- )
780
-
781
- if download:
782
- model_path = hf_hub_download(
783
- repo_id=repo_id,
784
- filename=file_name,
785
- revision=revision,
786
- token=token,
787
- force_download=force_download,
788
- cache_dir=cache_dir,
789
- )
840
+ raise ValueError(f"No more candidates available (requested index {candidate_index}, total {len(candidates)})")
841
+
842
+ # Get the candidate at the specified index
843
+ candidate = candidates[candidate_index]
844
+ repo_id = candidate["repo_id"]
845
+ hf_repo_info = candidate["repo_info"]
846
+
847
+ try:
848
+ if candidate["type"] == "diffusers":
849
+ # Validate URL early to detect 401 errors
850
+ if download:
851
+ # Validate URL accessibility before downloading
852
+ # Check if model_index.json is accessible
853
+ model_index_url = hf_hub_url(
854
+ repo_id=repo_id,
855
+ filename="model_index.json",
856
+ revision=revision
857
+ )
858
+ validate_url_with_head(model_index_url, token=token)
859
+
860
+ model_path = DiffusionPipeline.download(
861
+ repo_id,
862
+ token=token,
863
+ cache_dir=cache_dir,
864
+ **kwargs,
865
+ )
866
+ else:
867
+ model_path = repo_id
868
+
869
+ file_name = ""
870
+
871
+ elif candidate["type"] == "single_file":
872
+ file_name = candidate["file_name"]
873
+
874
+ # Validate URL early to detect 401 errors
875
+ if download:
876
+ # Validate URL accessibility before downloading
877
+ # Construct the download URL for validation using hf_hub_url
878
+ file_url = hf_hub_url(
879
+ repo_id=repo_id,
880
+ filename=file_name,
881
+ revision=revision
882
+ )
883
+ validate_url_with_head(file_url, token=token)
884
+
885
+ model_path = hf_hub_download(
886
+ repo_id=repo_id,
887
+ filename=file_name,
888
+ revision=revision,
889
+ token=token,
890
+ force_download=force_download,
891
+ cache_dir=cache_dir,
892
+ )
893
+ else:
894
+ model_path = f"https://huggingface.co/{repo_id}/blob/main/{file_name}"
895
+
896
+ except Exception as e:
897
+ # Log the error and let the caller decide whether to retry
898
+ logger.info(f"Candidate {candidate_index+1}/{len(candidates)} ({repo_id}) failed: {e}")
899
+ if skip_error:
900
+ return None
901
+ else:
902
+ raise
790
903
 
791
904
  # `pathlib.PosixPath` may be returned
792
905
  if model_path:
@@ -877,6 +990,96 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
877
990
  selected_version = {}
878
991
  civitai_cache_dir = cache_dir or os.path.join(CACHE_HOME, "Civitai")
879
992
 
993
+ # Handle direct Civitai API download URLs
994
+ if search_word.startswith("https://civitai.com/api/download/"):
995
+ # Extract model version ID from URL
996
+ match = re.search(r'/models/(\d+)', search_word)
997
+ if match:
998
+ version_id = match.group(1)
999
+ # Try to get model info from API
1000
+ headers = {}
1001
+ if token:
1002
+ headers["Authorization"] = f"Bearer {token}"
1003
+
1004
+ try:
1005
+ # Get version info to extract model name and ID
1006
+ response = requests.get(
1007
+ f"https://civitai.com/api/v1/model-versions/{version_id}",
1008
+ headers=headers
1009
+ )
1010
+ response.raise_for_status()
1011
+ version_data = response.json()
1012
+
1013
+ repo_name = version_data.get("model", {}).get("name", f"model_{version_id}")
1014
+ repo_id = str(version_data.get("modelId", ""))
1015
+ trainedWords = version_data.get("trainedWords", [])
1016
+
1017
+ # Get primary file info
1018
+ files = version_data.get("files", [])
1019
+ if files:
1020
+ primary_file = files[0]
1021
+ file_name = primary_file.get("name", f"model_{version_id}.safetensors")
1022
+ else:
1023
+ file_name = f"model_{version_id}.safetensors"
1024
+
1025
+ except Exception as e:
1026
+ logger.info(f"Could not fetch model info from API: {e}. Using fallback values.")
1027
+ repo_name = f"model_{version_id}"
1028
+ repo_id = ""
1029
+ file_name = f"model_{version_id}.safetensors"
1030
+ trainedWords = []
1031
+
1032
+ download_url = search_word
1033
+
1034
+ if download:
1035
+ # Download from the direct URL
1036
+ local_path = os.path.join(civitai_cache_dir, file_name)
1037
+
1038
+ try:
1039
+ file_downloader(
1040
+ url=download_url,
1041
+ save_path=local_path,
1042
+ resume=resume,
1043
+ force_download=force_download,
1044
+ displayed_filename=file_name,
1045
+ headers=headers,
1046
+ )
1047
+ model_path = local_path
1048
+ except Exception as e:
1049
+ if skip_error:
1050
+ return None
1051
+ else:
1052
+ raise ValueError(f"Failed to download from direct URL: {e}")
1053
+ else:
1054
+ model_path = download_url
1055
+
1056
+ output_info = get_keyword_types(model_path)
1057
+
1058
+ if not include_params:
1059
+ return model_path
1060
+ else:
1061
+ return SearchResult(
1062
+ model_path=model_path,
1063
+ loading_method=output_info["loading_method"],
1064
+ checkpoint_format=output_info["checkpoint_format"],
1065
+ repo_status=RepoStatus(
1066
+ repo_id=repo_name, repo_hash=repo_id, version=version_id
1067
+ ),
1068
+ model_status=ModelStatus(
1069
+ search_word=search_word,
1070
+ site_url=f"https://civitai.com/models/{repo_id}?modelVersionId={version_id}" if repo_id else download_url,
1071
+ download_url=download_url,
1072
+ file_name=file_name,
1073
+ local=output_info["type"]["local"],
1074
+ ),
1075
+ extra_status=ExtraStatus(trained_words=trainedWords or None),
1076
+ )
1077
+ else:
1078
+ if skip_error:
1079
+ return None
1080
+ else:
1081
+ raise ValueError("Could not extract model version ID from Civitai API URL")
1082
+
880
1083
  # Set up parameters and headers for the CivitAI API request
881
1084
  params = {
882
1085
  "query": search_word,
@@ -981,9 +1184,17 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
981
1184
  timeout=2,
982
1185
  allow_redirects=True
983
1186
  )
1187
+ _resp.raise_for_status()
984
1188
  selected_model = candidate_model
985
1189
  logger.info(f"Validated download URL: {candidate_model['download_url']}")
986
1190
  break # Exit the version loop if a valid model is found
1191
+ except requests.HTTPError as e:
1192
+ if "403" in str(e) or "401" in str(e):
1193
+ logger.info(f"Access denied ({e.response.status_code}) for {candidate_model['download_url']}, trying next version...")
1194
+ continue
1195
+ else:
1196
+ logger.info(f"HTTP error for {candidate_model['download_url']}: {e}, trying next version...")
1197
+ continue
987
1198
  except requests.exceptions.RequestException as e:
988
1199
  logger.info(f"Failed to validate URL {candidate_model['download_url']}: {e}, trying next version...")
989
1200
  continue
@@ -1008,7 +1219,7 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1008
1219
 
1009
1220
  # Handle file download and setting model information
1010
1221
  if download:
1011
- # Try downloading from the models list, retrying on 401 errors
1222
+ # Try downloading from the models list, retrying on 401/403 errors
1012
1223
  download_success = False
1013
1224
  # Create a sorted list of all available models to try
1014
1225
  sorted_models = sorted(
@@ -1039,14 +1250,18 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1039
1250
  logger.info(f"Successfully downloaded model from: {download_url}")
1040
1251
  break
1041
1252
  except requests.HTTPError as e:
1042
- if "401" in str(e):
1043
- logger.info(f"401 error for {download_url}, trying next candidate...")
1253
+ if "401" in str(e) or "403" in str(e):
1254
+ logger.info(f"Access denied ({e.response.status_code if hasattr(e, 'response') else 'unknown'}) for {download_url}, trying next candidate...")
1044
1255
  continue
1045
1256
  else:
1046
- raise
1257
+ logger.info(f"HTTP error for {download_url}: {e}, trying next candidate...")
1258
+ continue
1047
1259
 
1048
1260
  if not download_success:
1049
- raise ValueError(f"Failed to download any model file from {repo_name}. All URLs returned 401 errors.")
1261
+ if skip_error:
1262
+ return None
1263
+ else:
1264
+ raise ValueError(f"Failed to download any model file from {repo_name}. All URLs returned access denied or other errors.")
1050
1265
 
1051
1266
  else:
1052
1267
  model_path = download_url
@@ -1074,6 +1289,94 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
1074
1289
  )
1075
1290
 
1076
1291
 
1292
+ def _load_pipeline_with_retries(cls, pretrained_model_link_or_path, pipeline_mapping, **kwargs):
1293
+ """
1294
+ Helper function to load a pipeline with retry logic using an iterative loop.
1295
+ Handles candidate selection, retries, and error tracking.
1296
+
1297
+ Parameters:
1298
+ cls: The pipeline class
1299
+ pretrained_model_link_or_path: Model identifier or path
1300
+ pipeline_mapping: Pipeline mapping for single file checkpoints
1301
+ **kwargs: Additional arguments
1302
+
1303
+ Returns:
1304
+ Loaded pipeline with methods added
1305
+ """
1306
+ # Extract retry parameters from kwargs
1307
+ max_retries = kwargs.pop('_max_retries', 9)
1308
+ failed_count = 0
1309
+
1310
+ # Update kwargs to ensure the model is downloaded and parameters are included
1311
+ _status = {
1312
+ "download": True,
1313
+ "include_params": True,
1314
+ "skip_error": False,
1315
+ "pipeline_tag": kwargs.pop('_pipeline_tag', None),
1316
+ }
1317
+ kwargs.update(_status)
1318
+
1319
+ # Try each candidate up to max_retries times
1320
+ for attempt in range(max_retries + 1):
1321
+ # Search for the model on Hugging Face
1322
+ try:
1323
+ hf_checkpoint_status = search_huggingface(
1324
+ pretrained_model_link_or_path, candidate_index=attempt, **kwargs
1325
+ )
1326
+ except Exception as e:
1327
+ logger.info(f"Candidate {attempt + 1}/{max_retries + 1} search failed: {e}")
1328
+ failed_count += 1
1329
+ if attempt < max_retries:
1330
+ logger.info(f"Trying next candidate (attempt {attempt + 2}/{max_retries + 1})...")
1331
+ continue
1332
+ else:
1333
+ logger.warning(
1334
+ f"Note: {failed_count} model(s) skipped due to errors. "
1335
+ f"To access gated models, provide a token via the 'token' parameter."
1336
+ )
1337
+ raise
1338
+
1339
+ checkpoint_path = hf_checkpoint_status.model_path # type: ignore
1340
+
1341
+ # Check the format of the model checkpoint and load pipeline
1342
+ try:
1343
+ if hf_checkpoint_status.loading_method == "from_single_file": # type: ignore
1344
+ # Load the pipeline from a single file checkpoint
1345
+ pipeline = load_pipeline_from_single_file(
1346
+ pretrained_model_or_path=checkpoint_path,
1347
+ pipeline_mapping=pipeline_mapping,
1348
+ **kwargs,
1349
+ )
1350
+ else:
1351
+ pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
1352
+
1353
+ logger.info(
1354
+ f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}" # type: ignore
1355
+ )
1356
+
1357
+ # Success - show warning if some candidates were skipped
1358
+ if failed_count > 0:
1359
+ logger.warning(
1360
+ f"Note: {failed_count} model(s) skipped due to errors. "
1361
+ f"To access gated models, provide a token via the 'token' parameter."
1362
+ )
1363
+
1364
+ return add_methods(pipeline)
1365
+
1366
+ except Exception as e:
1367
+ logger.info(f"Failed to load pipeline: {e}")
1368
+ failed_count += 1
1369
+ if attempt < max_retries:
1370
+ logger.info(f"Trying next candidate (attempt {attempt + 2}/{max_retries + 1})...")
1371
+ continue
1372
+ else:
1373
+ logger.warning(
1374
+ f"Note: {failed_count} model(s) skipped due to errors. "
1375
+ f"To access gated models, provide a token via the 'token' parameter."
1376
+ )
1377
+ raise
1378
+
1379
+
1077
1380
  def add_methods(pipeline):
1078
1381
  r"""
1079
1382
  Add methods from `AutoConfig` to the pipeline.
@@ -1444,26 +1747,15 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1444
1747
  }
1445
1748
  kwargs.update(_status)
1446
1749
 
1447
- # Search for the model on Hugging Face and get the model status
1448
- hf_checkpoint_status = search_huggingface(
1449
- pretrained_model_link_or_path, **kwargs
1450
- )
1451
- logger.warning(
1452
- f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}" # type: ignore
1750
+ # Use the helper function to load the pipeline with retries
1751
+ kwargs['_max_retries'] = 9
1752
+ kwargs['_pipeline_tag'] = 'text-to-image'
1753
+ return _load_pipeline_with_retries(
1754
+ cls,
1755
+ pretrained_model_link_or_path,
1756
+ SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING,
1757
+ **kwargs
1453
1758
  )
1454
- checkpoint_path = hf_checkpoint_status.model_path # type: ignore
1455
-
1456
- # Check the format of the model checkpoint
1457
- if hf_checkpoint_status.loading_method == "from_single_file": # type: ignore
1458
- # Load the pipeline from a single file checkpoint
1459
- pipeline = load_pipeline_from_single_file(
1460
- pretrained_model_or_path=checkpoint_path,
1461
- pipeline_mapping=SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING,
1462
- **kwargs,
1463
- )
1464
- else:
1465
- pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
1466
- return add_methods(pipeline)
1467
1759
 
1468
1760
  @classmethod
1469
1761
  def from_civitai(cls, pretrained_model_link_or_path, **kwargs):
@@ -1697,36 +1989,15 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1697
1989
  >>> image = pipeline(prompt, image).images[0]
1698
1990
  ```
1699
1991
  """
1700
- # Update kwargs to ensure the model is downloaded and parameters are included
1701
- _parmas = {
1702
- "download": True,
1703
- "include_params": True,
1704
- "skip_error": False,
1705
- "pipeline_tag": "image-to-image",
1706
- }
1707
- kwargs.update(_parmas)
1708
-
1709
- # Search for the model on Hugging Face and get the model status
1710
- hf_checkpoint_status = search_huggingface(
1711
- pretrained_model_link_or_path, **kwargs
1992
+ # Use the helper function to load the pipeline with retries
1993
+ kwargs['_max_retries'] = 9
1994
+ kwargs['_pipeline_tag'] = 'image-to-image'
1995
+ return _load_pipeline_with_retries(
1996
+ cls,
1997
+ pretrained_model_link_or_path,
1998
+ SINGLE_FILE_CHECKPOINT_IMAGE2IMAGE_PIPELINE_MAPPING,
1999
+ **kwargs
1712
2000
  )
1713
- logger.warning(
1714
- f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}" # type: ignore
1715
- )
1716
- checkpoint_path = hf_checkpoint_status.model_path # type: ignore
1717
-
1718
- # Check the format of the model checkpoint
1719
- if hf_checkpoint_status.loading_method == "from_single_file": # type: ignore
1720
- # Load the pipeline from a single file checkpoint
1721
- pipeline = load_pipeline_from_single_file(
1722
- pretrained_model_or_path=checkpoint_path,
1723
- pipeline_mapping=SINGLE_FILE_CHECKPOINT_IMAGE2IMAGE_PIPELINE_MAPPING,
1724
- **kwargs,
1725
- )
1726
- else:
1727
- pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
1728
-
1729
- return add_methods(pipeline)
1730
2001
 
1731
2002
  @classmethod
1732
2003
  def from_civitai(cls, pretrained_model_link_or_path, **kwargs):
@@ -1960,35 +2231,15 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
1960
2231
  >>> image = pipeline(prompt, image=init_image, mask_image=mask_image).images[0]
1961
2232
  ```
1962
2233
  """
1963
- # Update kwargs to ensure the model is downloaded and parameters are included
1964
- _status = {
1965
- "download": True,
1966
- "include_params": True,
1967
- "skip_error": False,
1968
- "pipeline_tag": "image-to-image",
1969
- }
1970
- kwargs.update(_status)
1971
-
1972
- # Search for the model on Hugging Face and get the model status
1973
- hf_checkpoint_status = search_huggingface(
1974
- pretrained_model_link_or_path, **kwargs
1975
- )
1976
- logger.warning(
1977
- f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}" # type: ignore
2234
+ # Use the helper function to load the pipeline with retries
2235
+ kwargs['_max_retries'] = 9
2236
+ kwargs['_pipeline_tag'] = 'inpainting'
2237
+ return _load_pipeline_with_retries(
2238
+ cls,
2239
+ pretrained_model_link_or_path,
2240
+ SINGLE_FILE_CHECKPOINT_INPAINT_PIPELINE_MAPPING,
2241
+ **kwargs
1978
2242
  )
1979
- checkpoint_path = hf_checkpoint_status.model_path # type: ignore
1980
-
1981
- # Check the format of the model checkpoint
1982
- if hf_checkpoint_status.loading_method == "from_single_file": # type: ignore
1983
- # Load the pipeline from a single file checkpoint
1984
- pipeline = load_pipeline_from_single_file(
1985
- pretrained_model_or_path=checkpoint_path,
1986
- pipeline_mapping=SINGLE_FILE_CHECKPOINT_INPAINT_PIPELINE_MAPPING,
1987
- **kwargs,
1988
- )
1989
- else:
1990
- pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
1991
- return add_methods(pipeline)
1992
2243
 
1993
2244
  @classmethod
1994
2245
  def from_civitai(cls, pretrained_model_link_or_path, **kwargs):
@@ -1,10 +1,10 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: auto_diffusers
3
- Version: 2.0.33
3
+ Version: 2.0.36.dev0
4
4
  Summary: diffusers with search engine
5
5
  Home-page: https://github.com/suzukimain/auto_diffusers
6
6
  Author: suzukimain
7
- Author-email: subarucosmosmain@gmail.com
7
+ Author-email: gt13579552@gmail.com
8
8
  License: Apache 2.0 License
9
9
  Keywords: huggingface civitai diffusers model search deep learning diffusion pytorch stable diffusion
10
10
  Classifier: Development Status :: 5 - Production/Stable
@@ -17,11 +17,24 @@ Classifier: Programming Language :: Python :: 3
17
17
  Classifier: Programming Language :: Python :: 3.8
18
18
  Classifier: Programming Language :: Python :: 3.9
19
19
  Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
20
21
  Requires-Python: >=3.8.0
21
22
  Description-Content-Type: text/markdown
22
23
  License-File: LICENSE
23
- Requires-Dist: diffusers>=0.32.0
24
- Requires-Dist: transformers>=4.41.2
24
+ Requires-Dist: diffusers>=0.36.0
25
+ Requires-Dist: transformers>=4.57.3
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: keywords
33
+ Dynamic: license
34
+ Dynamic: license-file
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
25
38
 
26
39
  <p align="center">
27
40
  <br>
@@ -0,0 +1,2 @@
1
+ diffusers>=0.36.0
2
+ transformers>=4.57.3
@@ -1,2 +0,0 @@
1
- diffusers>=0.32.0
2
- transformers>=4.41.2