auto-diffusers 2.0.21.dev1__py3-none-any.whl → 2.0.23__py3-none-any.whl

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,4 +1,4 @@
1
- __version__ = "2.0.21.dev1"
1
+ __version__ = "2.0.23"
2
2
 
3
3
  from .pipeline_easy import (
4
4
  search_huggingface,
@@ -22,10 +22,6 @@ from typing import Dict, List, Optional, Union
22
22
 
23
23
  import requests
24
24
  import torch
25
- from huggingface_hub import hf_api, hf_hub_download
26
- from huggingface_hub.file_download import http_get
27
- from huggingface_hub.utils import validate_hf_hub_args
28
-
29
25
  from diffusers.loaders.single_file_utils import (
30
26
  VALID_URL_PREFIXES,
31
27
  _extract_repo_id_and_weights_name,
@@ -53,14 +49,19 @@ from diffusers.pipelines.stable_diffusion import (
53
49
  StableDiffusionPipeline,
54
50
  StableDiffusionUpscalePipeline,
55
51
  )
56
- from diffusers.pipelines.stable_diffusion_3 import StableDiffusion3Img2ImgPipeline, StableDiffusion3Pipeline
52
+ from diffusers.pipelines.stable_diffusion_3 import (
53
+ StableDiffusion3Img2ImgPipeline,
54
+ StableDiffusion3Pipeline,
55
+ )
57
56
  from diffusers.pipelines.stable_diffusion_xl import (
58
57
  StableDiffusionXLImg2ImgPipeline,
59
58
  StableDiffusionXLInpaintPipeline,
60
59
  StableDiffusionXLPipeline,
61
60
  )
62
61
  from diffusers.utils import logging
63
-
62
+ from huggingface_hub import hf_api, hf_hub_download
63
+ from huggingface_hub.file_download import http_get
64
+ from huggingface_hub.utils import validate_hf_hub_args
64
65
 
65
66
  logger = logging.get_logger(__name__)
66
67
 
@@ -327,7 +328,9 @@ class SearchResult:
327
328
 
328
329
 
329
330
  @validate_hf_hub_args
330
- def load_pipeline_from_single_file(pretrained_model_or_path, pipeline_mapping, **kwargs):
331
+ def load_pipeline_from_single_file(
332
+ pretrained_model_or_path, pipeline_mapping, **kwargs
333
+ ):
331
334
  r"""
332
335
  Instantiate a [`DiffusionPipeline`] from pretrained pipeline weights saved in the `.ckpt` or `.safetensors`
333
336
  format. The pipeline is set in evaluation mode (`model.eval()`) by default.
@@ -587,6 +590,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
587
590
  pipeline_tag = kwargs.pop("pipeline_tag", None)
588
591
  token = kwargs.pop("token", None)
589
592
  gated = kwargs.pop("gated", False)
593
+ cache_dir = kwargs.pop("cache_dir", None)
590
594
  skip_error = kwargs.pop("skip_error", False)
591
595
 
592
596
  file_list = []
@@ -607,6 +611,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
607
611
  revision=revision,
608
612
  token=token,
609
613
  force_download=force_download,
614
+ cache_dir=cache_dir,
610
615
  **kwargs,
611
616
  )
612
617
  else:
@@ -617,8 +622,9 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
617
622
  model_path = hf_hub_download(
618
623
  repo_id=repo_id,
619
624
  filename=weights_name,
620
- force_download=force_download,
621
625
  token=token,
626
+ force_download=force_download,
627
+ cache_dir=cache_dir,
622
628
  )
623
629
  else:
624
630
  model_path = search_word
@@ -628,7 +634,9 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
628
634
  if skip_error:
629
635
  return None
630
636
  else:
631
- raise ValueError("The URL for Civitai is invalid with `for_hf`. Please use `for_civitai` instead.")
637
+ raise ValueError(
638
+ "The URL for Civitai is invalid with `for_hf`. Please use `for_civitai` instead."
639
+ )
632
640
  else:
633
641
  # Get model data from HF API
634
642
  hf_models = hf_api.list_models(
@@ -667,7 +675,8 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
667
675
  any(file_path.endswith(ext) for ext in EXTENSION)
668
676
  and not any(config in file_path for config in CONFIG_FILE_LIST)
669
677
  and not any(exc in file_path for exc in exclusion)
670
- and os.path.basename(os.path.dirname(file_path)) not in DIFFUSERS_CONFIG_DIR
678
+ and os.path.basename(os.path.dirname(file_path))
679
+ not in DIFFUSERS_CONFIG_DIR
671
680
  ):
672
681
  file_list.append(file_path)
673
682
 
@@ -679,13 +688,16 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
679
688
  if skip_error:
680
689
  return None
681
690
  else:
682
- raise ValueError("No models matching your criteria were found on huggingface.")
691
+ raise ValueError(
692
+ "No models matching your criteria were found on huggingface."
693
+ )
683
694
 
684
695
  if diffusers_model_exists:
685
696
  if download:
686
697
  model_path = DiffusionPipeline.download(
687
698
  repo_id,
688
699
  token=token,
700
+ cache_dir=cache_dir,
689
701
  **kwargs,
690
702
  )
691
703
  else:
@@ -694,7 +706,11 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
694
706
  elif file_list:
695
707
  # Sort and find the safest model
696
708
  file_name = next(
697
- (model for model in sorted(file_list, reverse=True) if re.search(r"(?i)[-_](safe|sfw)", model)),
709
+ (
710
+ model
711
+ for model in sorted(file_list, reverse=True)
712
+ if re.search(r"(?i)[-_](safe|sfw)", model)
713
+ ),
698
714
  file_list[0],
699
715
  )
700
716
 
@@ -705,6 +721,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
705
721
  revision=revision,
706
722
  token=token,
707
723
  force_download=force_download,
724
+ cache_dir=cache_dir,
708
725
  )
709
726
 
710
727
  # `pathlib.PosixPath` may be returned
@@ -723,7 +740,9 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
723
740
  model_path=model_path or download_url,
724
741
  loading_method=output_info["loading_method"],
725
742
  checkpoint_format=output_info["checkpoint_format"],
726
- repo_status=RepoStatus(repo_id=repo_id, repo_hash=hf_repo_info.sha, version=revision),
743
+ repo_status=RepoStatus(
744
+ repo_id=repo_id, repo_hash=hf_repo_info.sha, version=revision
745
+ ),
727
746
  model_status=ModelStatus(
728
747
  search_word=search_word,
729
748
  site_url=download_url,
@@ -735,7 +754,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
735
754
  )
736
755
 
737
756
  else:
738
- return model_path
757
+ return model_path or download_url
739
758
 
740
759
 
741
760
  def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]:
@@ -814,7 +833,9 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
814
833
 
815
834
  try:
816
835
  # Make the request to the CivitAI API
817
- response = requests.get("https://civitai.com/api/v1/models", params=params, headers=headers)
836
+ response = requests.get(
837
+ "https://civitai.com/api/v1/models", params=params, headers=headers
838
+ )
818
839
  response.raise_for_status()
819
840
  except requests.exceptions.HTTPError as err:
820
841
  raise requests.HTTPError(f"Could not get elements from the URL: {err}")
@@ -828,7 +849,9 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
828
849
  raise ValueError("Invalid JSON response")
829
850
 
830
851
  # Sort repositories by download count in descending order
831
- sorted_repos = sorted(data["items"], key=lambda x: x["stats"]["downloadCount"], reverse=True)
852
+ sorted_repos = sorted(
853
+ data["items"], key=lambda x: x["stats"]["downloadCount"], reverse=True
854
+ )
832
855
 
833
856
  for selected_repo in sorted_repos:
834
857
  repo_name = selected_repo["name"]
@@ -853,7 +876,8 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
853
876
  model_data["pickleScanResult"] == "Success"
854
877
  and model_data["virusScanResult"] == "Success"
855
878
  and any(file_name.endswith(ext) for ext in EXTENSION)
856
- and os.path.basename(os.path.dirname(file_name)) not in DIFFUSERS_CONFIG_DIR
879
+ and os.path.basename(os.path.dirname(file_name))
880
+ not in DIFFUSERS_CONFIG_DIR
857
881
  ):
858
882
  file_status = {
859
883
  "filename": file_name,
@@ -863,12 +887,16 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
863
887
 
864
888
  if models_list:
865
889
  # Sort the models list by filename and find the safest model
866
- sorted_models = sorted(models_list, key=lambda x: x["filename"], reverse=True)
890
+ sorted_models = sorted(
891
+ models_list, key=lambda x: x["filename"], reverse=True
892
+ )
867
893
  selected_model = next(
868
894
  (
869
895
  model_data
870
896
  for model_data in sorted_models
871
- if bool(re.search(r"(?i)[-_](safe|sfw)", model_data["filename"]))
897
+ if bool(
898
+ re.search(r"(?i)[-_](safe|sfw)", model_data["filename"])
899
+ )
872
900
  ),
873
901
  sorted_models[0],
874
902
  )
@@ -883,7 +911,9 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
883
911
  if skip_error:
884
912
  return None
885
913
  else:
886
- raise ValueError("No model found. Please try changing the word you are searching for.")
914
+ raise ValueError(
915
+ "No model found. Please try changing the word you are searching for."
916
+ )
887
917
 
888
918
  # Define model file status
889
919
  file_name = selected_model["filename"]
@@ -892,7 +922,9 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
892
922
  # Handle file download and setting model information
893
923
  if download:
894
924
  # The path where the model is to be saved.
895
- model_path = os.path.join(str(civitai_cache_dir), str(repo_id), str(version_id), str(file_name))
925
+ model_path = os.path.join(
926
+ str(civitai_cache_dir), str(repo_id), str(version_id), str(file_name)
927
+ )
896
928
  # Download Model File
897
929
  file_downloader(
898
930
  url=download_url,
@@ -916,7 +948,9 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
916
948
  model_path=model_path,
917
949
  loading_method=output_info["loading_method"],
918
950
  checkpoint_format=output_info["checkpoint_format"],
919
- repo_status=RepoStatus(repo_id=repo_name, repo_hash=repo_id, version=version_id),
951
+ repo_status=RepoStatus(
952
+ repo_id=repo_name, repo_hash=repo_id, version=version_id
953
+ ),
920
954
  model_status=ModelStatus(
921
955
  search_word=search_word,
922
956
  site_url=f"https://civitai.com/models/{repo_id}?modelVersionId={version_id}",
@@ -1050,7 +1084,9 @@ class AutoConfig:
1050
1084
  f"Token {token} already in tokenizer vocabulary. Please choose a different token name or remove {token} and embedding from the tokenizer and text encoder."
1051
1085
  )
1052
1086
 
1053
- expected_shape = text_encoder.get_input_embeddings().weight.shape[-1] # Expected shape of tokenizer
1087
+ expected_shape = text_encoder.get_input_embeddings().weight.shape[
1088
+ -1
1089
+ ] # Expected shape of tokenizer
1054
1090
 
1055
1091
  for search_word in pretrained_model_name_or_paths:
1056
1092
  if isinstance(search_word, str):
@@ -1081,16 +1117,23 @@ class AutoConfig:
1081
1117
  f"textual_inversion_path: {search_word} -> {textual_inversion_path.model_status.site_url}"
1082
1118
  )
1083
1119
 
1084
- pretrained_model_name_or_paths[pretrained_model_name_or_paths.index(search_word)] = (
1085
- textual_inversion_path.model_path
1086
- )
1120
+ pretrained_model_name_or_paths[
1121
+ pretrained_model_name_or_paths.index(search_word)
1122
+ ] = textual_inversion_path.model_path
1087
1123
 
1088
1124
  self.load_textual_inversion(
1089
- pretrained_model_name_or_paths, token=tokens, tokenizer=tokenizer, text_encoder=text_encoder, **kwargs
1125
+ pretrained_model_name_or_paths,
1126
+ token=tokens,
1127
+ tokenizer=tokenizer,
1128
+ text_encoder=text_encoder,
1129
+ **kwargs,
1090
1130
  )
1091
1131
 
1092
1132
  def auto_load_lora_weights(
1093
- self, pretrained_model_name_or_path_or_dict: Union[str, Dict[str, torch.Tensor]], adapter_name=None, **kwargs
1133
+ self,
1134
+ pretrained_model_name_or_path_or_dict: Union[str, Dict[str, torch.Tensor]],
1135
+ adapter_name=None,
1136
+ **kwargs,
1094
1137
  ):
1095
1138
  r"""
1096
1139
  Load LoRA weights specified in `pretrained_model_name_or_path_or_dict` into `self.unet` and
@@ -1134,7 +1177,9 @@ class AutoConfig:
1134
1177
  logger.warning(f"trained_words: {lora_path.extra_status.trained_words}")
1135
1178
  pretrained_model_name_or_path_or_dict = lora_path.model_path
1136
1179
 
1137
- self.load_lora_weights(pretrained_model_name_or_path_or_dict, adapter_name=adapter_name, **kwargs)
1180
+ self.load_lora_weights(
1181
+ pretrained_model_name_or_path_or_dict, adapter_name=adapter_name, **kwargs
1182
+ )
1138
1183
 
1139
1184
 
1140
1185
  class EasyPipelineForText2Image(AutoPipelineForText2Image):
@@ -1272,8 +1317,12 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1272
1317
  kwargs.update(_status)
1273
1318
 
1274
1319
  # Search for the model on Hugging Face and get the model status
1275
- hf_checkpoint_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
1276
- logger.warning(f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}")
1320
+ hf_checkpoint_status = search_huggingface(
1321
+ pretrained_model_link_or_path, **kwargs
1322
+ )
1323
+ logger.warning(
1324
+ f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}"
1325
+ )
1277
1326
  checkpoint_path = hf_checkpoint_status.model_path
1278
1327
 
1279
1328
  # Check the format of the model checkpoint
@@ -1530,8 +1579,12 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1530
1579
  kwargs.update(_parmas)
1531
1580
 
1532
1581
  # Search for the model on Hugging Face and get the model status
1533
- hf_checkpoint_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
1534
- logger.warning(f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}")
1582
+ hf_checkpoint_status = search_huggingface(
1583
+ pretrained_model_link_or_path, **kwargs
1584
+ )
1585
+ logger.warning(
1586
+ f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}"
1587
+ )
1535
1588
  checkpoint_path = hf_checkpoint_status.model_path
1536
1589
 
1537
1590
  # Check the format of the model checkpoint
@@ -1789,8 +1842,12 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
1789
1842
  kwargs.update(_status)
1790
1843
 
1791
1844
  # Search for the model on Hugging Face and get the model status
1792
- hf_checkpoint_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
1793
- logger.warning(f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}")
1845
+ hf_checkpoint_status = search_huggingface(
1846
+ pretrained_model_link_or_path, **kwargs
1847
+ )
1848
+ logger.warning(
1849
+ f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}"
1850
+ )
1794
1851
  checkpoint_path = hf_checkpoint_status.model_path
1795
1852
 
1796
1853
  # Check the format of the model checkpoint
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: auto_diffusers
3
- Version: 2.0.21.dev1
4
- Summary: Customized diffusers with model search and other functions.
3
+ Version: 2.0.23
4
+ Summary: diffusers with search engine
5
5
  Home-page: https://github.com/suzukimain/auto_diffusers
6
6
  Author: suzukimain
7
7
  Author-email: subarucosmosmain@gmail.com
@@ -20,10 +20,8 @@ Classifier: Programming Language :: Python :: 3.10
20
20
  Requires-Python: >=3.8.0
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
- Requires-Dist: torch
24
- Requires-Dist: diffusers
25
- Requires-Dist: transformers
26
- Requires-Dist: huggingface-hub >=0.26.2
23
+ Requires-Dist: diffusers >=0.32.0
24
+ Requires-Dist: transformers >=4.41.2
27
25
 
28
26
  # auto_diffusers
29
27
 
@@ -0,0 +1,8 @@
1
+ auto_diffusers/__init__.py,sha256=ul-zslqarFVYlV_zLE4WYghrr5TsbG1f_Sq0rACA0jE,228
2
+ auto_diffusers/pipeline_easy.py,sha256=P-35YMLbQYY96v_Y2a-qdVlPJNTXHuhsIBZeT3UdhMo,93510
3
+ auto_diffusers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ auto_diffusers-2.0.23.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
+ auto_diffusers-2.0.23.dist-info/METADATA,sha256=uwRG3Zi_zbJ8gDLBAW1IseDVsqIGpXYBR8Oo4cT2xCo,9853
6
+ auto_diffusers-2.0.23.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
7
+ auto_diffusers-2.0.23.dist-info/top_level.txt,sha256=iYkbnc9T-VKVnoCP6AufdXcDUfUaLZ_yMG-USuYf4UQ,15
8
+ auto_diffusers-2.0.23.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.3.0)
2
+ Generator: setuptools (75.3.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- auto_diffusers/__init__.py,sha256=d7-A3NievjIk-WF7e3bYelitxaE6xa9abi-BPhNqLak,233
2
- auto_diffusers/pipeline_easy.py,sha256=cx3vRXgeyWmIaOaIJplaC9FH-h6p4W0AmYM-7bhRnaE,92593
3
- auto_diffusers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- auto_diffusers-2.0.21.dev1.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
- auto_diffusers-2.0.21.dev1.dist-info/METADATA,sha256=zirapR_cy9m7wyLNwRGQdK9EDJ3Hq41myi0OTuTbwmk,9932
6
- auto_diffusers-2.0.21.dev1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
7
- auto_diffusers-2.0.21.dev1.dist-info/top_level.txt,sha256=iYkbnc9T-VKVnoCP6AufdXcDUfUaLZ_yMG-USuYf4UQ,15
8
- auto_diffusers-2.0.21.dev1.dist-info/RECORD,,