auto-diffusers 2.0.14__tar.gz → 2.0.20__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,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: auto_diffusers
3
- Version: 2.0.14
3
+ Version: 2.0.20
4
4
  Summary: Customized diffusers with model search and other functions.
5
5
  Home-page: https://github.com/suzukimain/auto_diffusers
6
6
  Author: suzukimain
@@ -11,6 +11,7 @@ Classifier: Development Status :: 5 - Production/Stable
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: Intended Audience :: Education
13
13
  Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: Apache Software License
14
15
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
16
  Classifier: Programming Language :: Python :: 3
16
17
  Classifier: Programming Language :: Python :: 3.8
@@ -22,7 +23,18 @@ Description-Content-Type: text/markdown
22
23
  License-File: LICENSE
23
24
  Requires-Dist: torch
24
25
  Requires-Dist: diffusers
26
+ Requires-Dist: transformers
25
27
  Requires-Dist: huggingface-hub>=0.26.2
28
+ Dynamic: author
29
+ Dynamic: author-email
30
+ Dynamic: classifier
31
+ Dynamic: description
32
+ Dynamic: description-content-type
33
+ Dynamic: home-page
34
+ Dynamic: keywords
35
+ Dynamic: license
36
+ Dynamic: requires-dist
37
+ Dynamic: summary
26
38
 
27
39
  # auto_diffusers
28
40
 
@@ -61,46 +73,26 @@ pip install --quiet auto_diffusers
61
73
  from auto_diffusers import EasyPipelineForText2Image
62
74
 
63
75
  # Search for Huggingface
64
- pipe = EasyPipelineForText2Image.from_huggingface("any").to("cuda")
76
+ pipe = EasyPipelineForText2Image.from_huggingface("search_word").to("cuda")
65
77
  img = pipe("cat").images[0]
66
78
  img.save("cat.png")
67
79
 
68
80
 
69
81
  # Search for Civitai
70
- pipe = EasyPipelineForText2Image.from_civitai("any").to("cuda")
82
+ pipe = EasyPipelineForText2Image.from_civitai("search_word").to("cuda")
71
83
  image = pipe("cat").images[0]
72
84
  image.save("cat.png")
73
85
 
74
86
  ```
75
87
 
76
- ## Search Civitai and Huggingfacee<a name = "Search_Civitai_and_Huggingfacee"></a>
88
+ ## Search Civitai and Huggingfacee<a name = "Search_Civitai_and_Huggingface"></a>
77
89
 
78
90
  ```python
79
- from pipeline_easy import (
80
- search_huggingface,
81
- search_civitai,
82
- )
83
-
84
- # Search Lora
85
- Lora = search_civitai(
86
- "Keyword_to_search_Lora",
87
- model_type="LORA",
88
- base_model = "SD 1.5",
89
- download=True,
90
- )
91
91
  # Load Lora into the pipeline.
92
- pipeline.load_lora_weights(Lora)
92
+ pipe.auto_load_lora_weights("Detail Tweaker")
93
93
 
94
-
95
- # Search TextualInversion
96
- TextualInversion = search_civitai(
97
- "EasyNegative",
98
- model_type="TextualInversion",
99
- base_model = "SD 1.5",
100
- download=True
101
- )
102
94
  # Load TextualInversion into the pipeline.
103
- pipeline.load_textual_inversion(TextualInversion, token="EasyNegative")
95
+ pipe.auto_load_textual_inversion("EasyNegative", token="EasyNegative")
104
96
  ```
105
97
 
106
98
  ### Search Civitai<a name = "Search_Civitai"></a>
@@ -35,46 +35,26 @@ pip install --quiet auto_diffusers
35
35
  from auto_diffusers import EasyPipelineForText2Image
36
36
 
37
37
  # Search for Huggingface
38
- pipe = EasyPipelineForText2Image.from_huggingface("any").to("cuda")
38
+ pipe = EasyPipelineForText2Image.from_huggingface("search_word").to("cuda")
39
39
  img = pipe("cat").images[0]
40
40
  img.save("cat.png")
41
41
 
42
42
 
43
43
  # Search for Civitai
44
- pipe = EasyPipelineForText2Image.from_civitai("any").to("cuda")
44
+ pipe = EasyPipelineForText2Image.from_civitai("search_word").to("cuda")
45
45
  image = pipe("cat").images[0]
46
46
  image.save("cat.png")
47
47
 
48
48
  ```
49
49
 
50
- ## Search Civitai and Huggingfacee<a name = "Search_Civitai_and_Huggingfacee"></a>
50
+ ## Search Civitai and Huggingfacee<a name = "Search_Civitai_and_Huggingface"></a>
51
51
 
52
52
  ```python
53
- from pipeline_easy import (
54
- search_huggingface,
55
- search_civitai,
56
- )
57
-
58
- # Search Lora
59
- Lora = search_civitai(
60
- "Keyword_to_search_Lora",
61
- model_type="LORA",
62
- base_model = "SD 1.5",
63
- download=True,
64
- )
65
53
  # Load Lora into the pipeline.
66
- pipeline.load_lora_weights(Lora)
54
+ pipe.auto_load_lora_weights("Detail Tweaker")
67
55
 
68
-
69
- # Search TextualInversion
70
- TextualInversion = search_civitai(
71
- "EasyNegative",
72
- model_type="TextualInversion",
73
- base_model = "SD 1.5",
74
- download=True
75
- )
76
56
  # Load TextualInversion into the pipeline.
77
- pipeline.load_textual_inversion(TextualInversion, token="EasyNegative")
57
+ pipe.auto_load_textual_inversion("EasyNegative", token="EasyNegative")
78
58
  ```
79
59
 
80
60
  ### Search Civitai<a name = "Search_Civitai"></a>
@@ -7,15 +7,12 @@ from setuptools import find_packages, setup
7
7
  _deps = [
8
8
  "torch",
9
9
  "diffusers",
10
+ "transformers",
10
11
  "huggingface-hub>=0.26.2",
11
12
  ]
12
13
 
13
14
  deps = {b: a for a, b in (re.findall(r"^(([^!=<>~]+)(?:[!=<>~].*)?$)", x)[0] for x in _deps)}
14
15
 
15
- def read_version():
16
- with open(os.path.join(os.path.dirname(__file__), 'Version.txt')) as version_file:
17
- return version_file.read().strip()
18
-
19
16
 
20
17
  def deps_list(*pkgs):
21
18
  return [deps[pkg] for pkg in pkgs]
@@ -25,7 +22,7 @@ version_range_max = max(sys.version_info[1], 10) + 1
25
22
 
26
23
  setup(
27
24
  name="auto_diffusers",
28
- version=read_version(),
25
+ version="2.0.20",
29
26
  description="Customized diffusers with model search and other functions.",
30
27
  long_description=open("README.md", "r", encoding="utf-8").read(),
31
28
  long_description_content_type="text/markdown",
@@ -44,6 +41,7 @@ setup(
44
41
  "Intended Audience :: Developers",
45
42
  "Intended Audience :: Education",
46
43
  "Intended Audience :: Science/Research",
44
+ "License :: OSI Approved :: Apache Software License",
47
45
  "Topic :: Scientific/Engineering :: Artificial Intelligence",
48
46
  "Programming Language :: Python :: 3",
49
47
  ]
@@ -1,3 +1,5 @@
1
+ __version__ = "2.0.20"
2
+
1
3
  from .pipeline_easy import (
2
4
  search_huggingface,
3
5
  search_civitai,
@@ -1,5 +1,5 @@
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.
@@ -15,11 +15,13 @@
15
15
 
16
16
  import os
17
17
  import re
18
+ import types
18
19
  from collections import OrderedDict
19
- from dataclasses import asdict, dataclass
20
- from typing import Union
20
+ from dataclasses import asdict, dataclass, field
21
+ from typing import Dict, List, Optional, Union
21
22
 
22
23
  import requests
24
+ import torch
23
25
  from huggingface_hub import hf_api, hf_hub_download
24
26
  from huggingface_hub.file_download import http_get
25
27
  from huggingface_hub.utils import validate_hf_hub_args
@@ -30,6 +32,7 @@ from diffusers.loaders.single_file_utils import (
30
32
  infer_diffusers_model_type,
31
33
  load_single_file_checkpoint,
32
34
  )
35
+ from diffusers.pipelines.animatediff import AnimateDiffPipeline, AnimateDiffSDXLPipeline
33
36
  from diffusers.pipelines.auto_pipeline import (
34
37
  AutoPipelineForImage2Image,
35
38
  AutoPipelineForInpainting,
@@ -39,13 +42,18 @@ from diffusers.pipelines.controlnet import (
39
42
  StableDiffusionControlNetImg2ImgPipeline,
40
43
  StableDiffusionControlNetInpaintPipeline,
41
44
  StableDiffusionControlNetPipeline,
45
+ StableDiffusionXLControlNetImg2ImgPipeline,
46
+ StableDiffusionXLControlNetPipeline,
42
47
  )
48
+ from diffusers.pipelines.flux import FluxImg2ImgPipeline, FluxPipeline
43
49
  from diffusers.pipelines.pipeline_utils import DiffusionPipeline
44
50
  from diffusers.pipelines.stable_diffusion import (
45
51
  StableDiffusionImg2ImgPipeline,
46
52
  StableDiffusionInpaintPipeline,
47
53
  StableDiffusionPipeline,
54
+ StableDiffusionUpscalePipeline,
48
55
  )
56
+ from diffusers.pipelines.stable_diffusion_3 import StableDiffusion3Img2ImgPipeline, StableDiffusion3Pipeline
49
57
  from diffusers.pipelines.stable_diffusion_xl import (
50
58
  StableDiffusionXLImg2ImgPipeline,
51
59
  StableDiffusionXLInpaintPipeline,
@@ -59,46 +67,133 @@ logger = logging.get_logger(__name__)
59
67
 
60
68
  SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING = OrderedDict(
61
69
  [
62
- ("xl_base", StableDiffusionXLPipeline),
63
- ("xl_refiner", StableDiffusionXLPipeline),
64
- ("xl_inpaint", None),
65
- ("playground-v2-5", StableDiffusionXLPipeline),
66
- ("upscale", None),
70
+ ("animatediff_rgb", AnimateDiffPipeline),
71
+ ("animatediff_scribble", AnimateDiffPipeline),
72
+ ("animatediff_sdxl_beta", AnimateDiffSDXLPipeline),
73
+ ("animatediff_v1", AnimateDiffPipeline),
74
+ ("animatediff_v2", AnimateDiffPipeline),
75
+ ("animatediff_v3", AnimateDiffPipeline),
76
+ ("autoencoder-dc-f128c512", None),
77
+ ("autoencoder-dc-f32c32", None),
78
+ ("autoencoder-dc-f32c32-sana", None),
79
+ ("autoencoder-dc-f64c128", None),
80
+ ("controlnet", StableDiffusionControlNetPipeline),
81
+ ("controlnet_xl", StableDiffusionXLControlNetPipeline),
82
+ ("controlnet_xl_large", StableDiffusionXLControlNetPipeline),
83
+ ("controlnet_xl_mid", StableDiffusionXLControlNetPipeline),
84
+ ("controlnet_xl_small", StableDiffusionXLControlNetPipeline),
85
+ ("flux-depth", FluxPipeline),
86
+ ("flux-dev", FluxPipeline),
87
+ ("flux-fill", FluxPipeline),
88
+ ("flux-schnell", FluxPipeline),
89
+ ("hunyuan-video", None),
67
90
  ("inpainting", None),
68
91
  ("inpainting_v2", None),
69
- ("controlnet", StableDiffusionControlNetPipeline),
70
- ("v2", StableDiffusionPipeline),
92
+ ("ltx-video", None),
93
+ ("ltx-video-0.9.1", None),
94
+ ("mochi-1-preview", None),
95
+ ("playground-v2-5", StableDiffusionXLPipeline),
96
+ ("sd3", StableDiffusion3Pipeline),
97
+ ("sd35_large", StableDiffusion3Pipeline),
98
+ ("sd35_medium", StableDiffusion3Pipeline),
99
+ ("stable_cascade_stage_b", None),
100
+ ("stable_cascade_stage_b_lite", None),
101
+ ("stable_cascade_stage_c", None),
102
+ ("stable_cascade_stage_c_lite", None),
103
+ ("upscale", StableDiffusionUpscalePipeline),
71
104
  ("v1", StableDiffusionPipeline),
105
+ ("v2", StableDiffusionPipeline),
106
+ ("xl_base", StableDiffusionXLPipeline),
107
+ ("xl_inpaint", None),
108
+ ("xl_refiner", StableDiffusionXLPipeline),
72
109
  ]
73
110
  )
74
111
 
75
112
  SINGLE_FILE_CHECKPOINT_IMAGE2IMAGE_PIPELINE_MAPPING = OrderedDict(
76
113
  [
77
- ("xl_base", StableDiffusionXLImg2ImgPipeline),
78
- ("xl_refiner", StableDiffusionXLImg2ImgPipeline),
79
- ("xl_inpaint", None),
80
- ("playground-v2-5", StableDiffusionXLImg2ImgPipeline),
81
- ("upscale", None),
114
+ ("animatediff_rgb", AnimateDiffPipeline),
115
+ ("animatediff_scribble", AnimateDiffPipeline),
116
+ ("animatediff_sdxl_beta", AnimateDiffSDXLPipeline),
117
+ ("animatediff_v1", AnimateDiffPipeline),
118
+ ("animatediff_v2", AnimateDiffPipeline),
119
+ ("animatediff_v3", AnimateDiffPipeline),
120
+ ("autoencoder-dc-f128c512", None),
121
+ ("autoencoder-dc-f32c32", None),
122
+ ("autoencoder-dc-f32c32-sana", None),
123
+ ("autoencoder-dc-f64c128", None),
124
+ ("controlnet", StableDiffusionControlNetImg2ImgPipeline),
125
+ ("controlnet_xl", StableDiffusionXLControlNetImg2ImgPipeline),
126
+ ("controlnet_xl_large", StableDiffusionXLControlNetImg2ImgPipeline),
127
+ ("controlnet_xl_mid", StableDiffusionXLControlNetImg2ImgPipeline),
128
+ ("controlnet_xl_small", StableDiffusionXLControlNetImg2ImgPipeline),
129
+ ("flux-depth", FluxImg2ImgPipeline),
130
+ ("flux-dev", FluxImg2ImgPipeline),
131
+ ("flux-fill", FluxImg2ImgPipeline),
132
+ ("flux-schnell", FluxImg2ImgPipeline),
133
+ ("hunyuan-video", None),
82
134
  ("inpainting", None),
83
135
  ("inpainting_v2", None),
84
- ("controlnet", StableDiffusionControlNetImg2ImgPipeline),
85
- ("v2", StableDiffusionImg2ImgPipeline),
136
+ ("ltx-video", None),
137
+ ("ltx-video-0.9.1", None),
138
+ ("mochi-1-preview", None),
139
+ ("playground-v2-5", StableDiffusionXLImg2ImgPipeline),
140
+ ("sd3", StableDiffusion3Img2ImgPipeline),
141
+ ("sd35_large", StableDiffusion3Img2ImgPipeline),
142
+ ("sd35_medium", StableDiffusion3Img2ImgPipeline),
143
+ ("stable_cascade_stage_b", None),
144
+ ("stable_cascade_stage_b_lite", None),
145
+ ("stable_cascade_stage_c", None),
146
+ ("stable_cascade_stage_c_lite", None),
147
+ ("upscale", StableDiffusionUpscalePipeline),
86
148
  ("v1", StableDiffusionImg2ImgPipeline),
149
+ ("v2", StableDiffusionImg2ImgPipeline),
150
+ ("xl_base", StableDiffusionXLImg2ImgPipeline),
151
+ ("xl_inpaint", None),
152
+ ("xl_refiner", StableDiffusionXLImg2ImgPipeline),
87
153
  ]
88
154
  )
89
155
 
90
156
  SINGLE_FILE_CHECKPOINT_INPAINT_PIPELINE_MAPPING = OrderedDict(
91
157
  [
92
- ("xl_base", None),
93
- ("xl_refiner", None),
94
- ("xl_inpaint", StableDiffusionXLInpaintPipeline),
95
- ("playground-v2-5", None),
96
- ("upscale", None),
158
+ ("animatediff_rgb", None),
159
+ ("animatediff_scribble", None),
160
+ ("animatediff_sdxl_beta", None),
161
+ ("animatediff_v1", None),
162
+ ("animatediff_v2", None),
163
+ ("animatediff_v3", None),
164
+ ("autoencoder-dc-f128c512", None),
165
+ ("autoencoder-dc-f32c32", None),
166
+ ("autoencoder-dc-f32c32-sana", None),
167
+ ("autoencoder-dc-f64c128", None),
168
+ ("controlnet", StableDiffusionControlNetInpaintPipeline),
169
+ ("controlnet_xl", None),
170
+ ("controlnet_xl_large", None),
171
+ ("controlnet_xl_mid", None),
172
+ ("controlnet_xl_small", None),
173
+ ("flux-depth", None),
174
+ ("flux-dev", None),
175
+ ("flux-fill", None),
176
+ ("flux-schnell", None),
177
+ ("hunyuan-video", None),
97
178
  ("inpainting", StableDiffusionInpaintPipeline),
98
179
  ("inpainting_v2", StableDiffusionInpaintPipeline),
99
- ("controlnet", StableDiffusionControlNetInpaintPipeline),
100
- ("v2", None),
180
+ ("ltx-video", None),
181
+ ("ltx-video-0.9.1", None),
182
+ ("mochi-1-preview", None),
183
+ ("playground-v2-5", None),
184
+ ("sd3", None),
185
+ ("sd35_large", None),
186
+ ("sd35_medium", None),
187
+ ("stable_cascade_stage_b", None),
188
+ ("stable_cascade_stage_b_lite", None),
189
+ ("stable_cascade_stage_c", None),
190
+ ("stable_cascade_stage_c_lite", None),
191
+ ("upscale", StableDiffusionUpscalePipeline),
101
192
  ("v1", None),
193
+ ("v2", None),
194
+ ("xl_base", None),
195
+ ("xl_inpaint", StableDiffusionXLInpaintPipeline),
196
+ ("xl_refiner", None),
102
197
  ]
103
198
  )
104
199
 
@@ -116,14 +211,33 @@ CONFIG_FILE_LIST = [
116
211
  "diffusion_pytorch_model.non_ema.safetensors",
117
212
  ]
118
213
 
119
- DIFFUSERS_CONFIG_DIR = ["safety_checker", "unet", "vae", "text_encoder", "text_encoder_2"]
120
-
121
- INPAINT_PIPELINE_KEYS = [
122
- "xl_inpaint",
123
- "inpainting",
124
- "inpainting_v2",
214
+ DIFFUSERS_CONFIG_DIR = [
215
+ "safety_checker",
216
+ "unet",
217
+ "vae",
218
+ "text_encoder",
219
+ "text_encoder_2",
125
220
  ]
126
221
 
222
+ TOKENIZER_SHAPE_MAP = {
223
+ 768: [
224
+ "SD 1.4",
225
+ "SD 1.5",
226
+ "SD 1.5 LCM",
227
+ "SDXL 0.9",
228
+ "SDXL 1.0",
229
+ "SDXL 1.0 LCM",
230
+ "SDXL Distilled",
231
+ "SDXL Turbo",
232
+ "SDXL Lightning",
233
+ "PixArt a",
234
+ "Playground v2",
235
+ "Pony",
236
+ ],
237
+ 1024: ["SD 2.0", "SD 2.0 768", "SD 2.1", "SD 2.1 768", "SD 2.1 Unclip"],
238
+ }
239
+
240
+
127
241
  EXTENSION = [".safetensors", ".ckpt", ".bin"]
128
242
 
129
243
  CACHE_HOME = os.path.expanduser("~/.cache")
@@ -162,12 +276,28 @@ class ModelStatus:
162
276
  The name of the model file.
163
277
  local (`bool`):
164
278
  Whether the model exists locally
279
+ site_url (`str`):
280
+ The URL of the site where the model is hosted.
165
281
  """
166
282
 
167
283
  search_word: str = ""
168
284
  download_url: str = ""
169
285
  file_name: str = ""
170
286
  local: bool = False
287
+ site_url: str = ""
288
+
289
+
290
+ @dataclass
291
+ class ExtraStatus:
292
+ r"""
293
+ Data class for storing extra status information.
294
+
295
+ Attributes:
296
+ trained_words (`str`):
297
+ The words used to trigger the model
298
+ """
299
+
300
+ trained_words: Union[List[str], None] = None
171
301
 
172
302
 
173
303
  @dataclass
@@ -191,8 +321,9 @@ class SearchResult:
191
321
  model_path: str = ""
192
322
  loading_method: Union[str, None] = None
193
323
  checkpoint_format: Union[str, None] = None
194
- repo_status: RepoStatus = RepoStatus()
195
- model_status: ModelStatus = ModelStatus()
324
+ repo_status: RepoStatus = field(default_factory=RepoStatus)
325
+ model_status: ModelStatus = field(default_factory=ModelStatus)
326
+ extra_status: ExtraStatus = field(default_factory=ExtraStatus)
196
327
 
197
328
 
198
329
  @validate_hf_hub_args
@@ -385,6 +516,7 @@ def file_downloader(
385
516
  proxies = kwargs.pop("proxies", None)
386
517
  force_download = kwargs.pop("force_download", False)
387
518
  displayed_filename = kwargs.pop("displayed_filename", None)
519
+
388
520
  # Default mode for file writing and initial file size
389
521
  mode = "wb"
390
522
  file_size = 0
@@ -396,7 +528,7 @@ def file_downloader(
396
528
  if os.path.exists(save_path):
397
529
  if not force_download:
398
530
  # If the file exists and force_download is False, skip the download
399
- logger.warning(f"File already exists: {save_path}, skipping download.")
531
+ logger.info(f"File already exists: {save_path}, skipping download.")
400
532
  return None
401
533
  elif resume:
402
534
  # If resuming, set mode to append binary and get current file size
@@ -457,10 +589,18 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
457
589
  gated = kwargs.pop("gated", False)
458
590
  skip_error = kwargs.pop("skip_error", False)
459
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
+
460
599
  # Get the type and loading method for the keyword
461
600
  search_word_status = get_keyword_types(search_word)
462
601
 
463
602
  if search_word_status["type"]["hf_repo"]:
603
+ hf_repo_info = hf_api.model_info(repo_id=search_word, securityStatus=True)
464
604
  if download:
465
605
  model_path = DiffusionPipeline.download(
466
606
  search_word,
@@ -503,13 +643,6 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
503
643
  )
504
644
  model_dicts = [asdict(value) for value in list(hf_models)]
505
645
 
506
- file_list = []
507
- hf_repo_info = {}
508
- hf_security_info = {}
509
- model_path = ""
510
- repo_id, file_name = "", ""
511
- diffusers_model_exists = False
512
-
513
646
  # Loop through models to find a suitable candidate
514
647
  for repo_info in model_dicts:
515
648
  repo_id = repo_info["id"]
@@ -523,7 +656,10 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
523
656
  if hf_security_info["scansDone"]:
524
657
  for info in repo_info["siblings"]:
525
658
  file_path = info["rfilename"]
526
- if "model_index.json" == file_path and checkpoint_format in ["diffusers", "all"]:
659
+ if "model_index.json" == file_path and checkpoint_format in [
660
+ "diffusers",
661
+ "all",
662
+ ]:
527
663
  diffusers_model_exists = True
528
664
  break
529
665
 
@@ -571,6 +707,10 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
571
707
  force_download=force_download,
572
708
  )
573
709
 
710
+ # `pathlib.PosixPath` may be returned
711
+ if model_path:
712
+ model_path = str(model_path)
713
+
574
714
  if file_name:
575
715
  download_url = f"https://huggingface.co/{repo_id}/blob/main/{file_name}"
576
716
  else:
@@ -586,10 +726,12 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
586
726
  repo_status=RepoStatus(repo_id=repo_id, repo_hash=hf_repo_info.sha, version=revision),
587
727
  model_status=ModelStatus(
588
728
  search_word=search_word,
729
+ site_url=download_url,
589
730
  download_url=download_url,
590
731
  file_name=file_name,
591
732
  local=download,
592
733
  ),
734
+ extra_status=ExtraStatus(trained_words=None),
593
735
  )
594
736
 
595
737
  else:
@@ -605,6 +747,8 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
605
747
  The search query string.
606
748
  model_type (`str`, *optional*, defaults to `Checkpoint`):
607
749
  The type of model to search for.
750
+ sort (`str`, *optional*):
751
+ The order in which you wish to sort the results(for example, `Highest Rated`, `Most Downloaded`, `Newest`).
608
752
  base_model (`str`, *optional*):
609
753
  The base model to filter by.
610
754
  download (`bool`, *optional*, defaults to `False`):
@@ -628,6 +772,7 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
628
772
 
629
773
  # Extract additional parameters from kwargs
630
774
  model_type = kwargs.pop("model_type", "Checkpoint")
775
+ sort = kwargs.pop("sort", None)
631
776
  download = kwargs.pop("download", False)
632
777
  base_model = kwargs.pop("base_model", None)
633
778
  force_download = kwargs.pop("force_download", False)
@@ -642,6 +787,7 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
642
787
  repo_name = ""
643
788
  repo_id = ""
644
789
  version_id = ""
790
+ trainedWords = ""
645
791
  models_list = []
646
792
  selected_repo = {}
647
793
  selected_model = {}
@@ -652,12 +798,16 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
652
798
  params = {
653
799
  "query": search_word,
654
800
  "types": model_type,
655
- "sort": "Most Downloaded",
656
801
  "limit": 20,
657
802
  }
658
803
  if base_model is not None:
804
+ if not isinstance(base_model, list):
805
+ base_model = [base_model]
659
806
  params["baseModel"] = base_model
660
807
 
808
+ if sort is not None:
809
+ params["sort"] = sort
810
+
661
811
  headers = {}
662
812
  if token:
663
813
  headers["Authorization"] = f"Bearer {token}"
@@ -686,25 +836,30 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
686
836
 
687
837
  # Sort versions within the selected repo by download count
688
838
  sorted_versions = sorted(
689
- selected_repo["modelVersions"], key=lambda x: x["stats"]["downloadCount"], reverse=True
839
+ selected_repo["modelVersions"],
840
+ key=lambda x: x["stats"]["downloadCount"],
841
+ reverse=True,
690
842
  )
691
843
  for selected_version in sorted_versions:
692
844
  version_id = selected_version["id"]
845
+ trainedWords = selected_version["trainedWords"]
693
846
  models_list = []
694
- for model_data in selected_version["files"]:
695
- # Check if the file passes security scans and has a valid extension
696
- file_name = model_data["name"]
697
- if (
698
- model_data["pickleScanResult"] == "Success"
699
- and model_data["virusScanResult"] == "Success"
700
- and any(file_name.endswith(ext) for ext in EXTENSION)
701
- and os.path.basename(os.path.dirname(file_name)) not in DIFFUSERS_CONFIG_DIR
702
- ):
703
- file_status = {
704
- "filename": file_name,
705
- "download_url": model_data["downloadUrl"],
706
- }
707
- models_list.append(file_status)
847
+ # When searching for textual inversion, results other than the values entered for the base model may come up, so check again.
848
+ if base_model is None or selected_version["baseModel"] in base_model:
849
+ for model_data in selected_version["files"]:
850
+ # Check if the file passes security scans and has a valid extension
851
+ file_name = model_data["name"]
852
+ if (
853
+ model_data["pickleScanResult"] == "Success"
854
+ and model_data["virusScanResult"] == "Success"
855
+ 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
857
+ ):
858
+ file_status = {
859
+ "filename": file_name,
860
+ "download_url": model_data["downloadUrl"],
861
+ }
862
+ models_list.append(file_status)
708
863
 
709
864
  if models_list:
710
865
  # Sort the models list by filename and find the safest model
@@ -764,19 +919,229 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
764
919
  repo_status=RepoStatus(repo_id=repo_name, repo_hash=repo_id, version=version_id),
765
920
  model_status=ModelStatus(
766
921
  search_word=search_word,
922
+ site_url=f"https://civitai.com/models/{repo_id}?modelVersionId={version_id}",
767
923
  download_url=download_url,
768
924
  file_name=file_name,
769
925
  local=output_info["type"]["local"],
770
926
  ),
927
+ extra_status=ExtraStatus(trained_words=trainedWords or None),
771
928
  )
772
929
 
773
930
 
774
- class EasyPipelineForText2Image(AutoPipelineForText2Image):
931
+ def add_methods(pipeline):
775
932
  r"""
933
+ Add methods from `AutoConfig` to the pipeline.
776
934
 
777
- [`AutoPipelineForText2Image`] is a generic pipeline class that instantiates a text-to-image pipeline class. The
935
+ Parameters:
936
+ pipeline (`Pipeline`):
937
+ The pipeline to which the methods will be added.
938
+ """
939
+ for attr_name in dir(AutoConfig):
940
+ attr_value = getattr(AutoConfig, attr_name)
941
+ if callable(attr_value) and not attr_name.startswith("__"):
942
+ setattr(pipeline, attr_name, types.MethodType(attr_value, pipeline))
943
+ return pipeline
944
+
945
+
946
+ class AutoConfig:
947
+ def auto_load_textual_inversion(
948
+ self,
949
+ pretrained_model_name_or_path: Union[str, List[str]],
950
+ token: Optional[Union[str, List[str]]] = None,
951
+ base_model: Optional[Union[str, List[str]]] = None,
952
+ tokenizer=None,
953
+ text_encoder=None,
954
+ **kwargs,
955
+ ):
956
+ r"""
957
+ Load Textual Inversion embeddings into the text encoder of [`StableDiffusionPipeline`] (both 🤗 Diffusers and
958
+ Automatic1111 formats are supported).
959
+
960
+ Parameters:
961
+ pretrained_model_name_or_path (`str` or `os.PathLike` or `List[str or os.PathLike]` or `Dict` or `List[Dict]`):
962
+ Can be either one of the following or a list of them:
963
+
964
+ - Search keywords for pretrained model (for example `EasyNegative`).
965
+ - A string, the *model id* (for example `sd-concepts-library/low-poly-hd-logos-icons`) of a
966
+ pretrained model hosted on the Hub.
967
+ - A path to a *directory* (for example `./my_text_inversion_directory/`) containing the textual
968
+ inversion weights.
969
+ - A path to a *file* (for example `./my_text_inversions.pt`) containing textual inversion weights.
970
+ - A [torch state
971
+ dict](https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict).
972
+
973
+ token (`str` or `List[str]`, *optional*):
974
+ Override the token to use for the textual inversion weights. If `pretrained_model_name_or_path` is a
975
+ list, then `token` must also be a list of equal length.
976
+ text_encoder ([`~transformers.CLIPTextModel`], *optional*):
977
+ Frozen text-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)).
978
+ If not specified, function will take self.tokenizer.
979
+ tokenizer ([`~transformers.CLIPTokenizer`], *optional*):
980
+ A `CLIPTokenizer` to tokenize text. If not specified, function will take self.tokenizer.
981
+ weight_name (`str`, *optional*):
982
+ Name of a custom weight file. This should be used when:
983
+
984
+ - The saved textual inversion file is in 🤗 Diffusers format, but was saved under a specific weight
985
+ name such as `text_inv.bin`.
986
+ - The saved textual inversion file is in the Automatic1111 format.
987
+ cache_dir (`Union[str, os.PathLike]`, *optional*):
988
+ Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
989
+ is not used.
990
+ force_download (`bool`, *optional*, defaults to `False`):
991
+ Whether or not to force the (re-)download of the model weights and configuration files, overriding the
992
+ cached versions if they exist.
993
+
994
+ proxies (`Dict[str, str]`, *optional*):
995
+ A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
996
+ 'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
997
+ local_files_only (`bool`, *optional*, defaults to `False`):
998
+ Whether to only load local model weights and configuration files or not. If set to `True`, the model
999
+ won't be downloaded from the Hub.
1000
+ token (`str` or *bool*, *optional*):
1001
+ The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
1002
+ `diffusers-cli login` (stored in `~/.huggingface`) is used.
1003
+ revision (`str`, *optional*, defaults to `"main"`):
1004
+ The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
1005
+ allowed by Git.
1006
+ subfolder (`str`, *optional*, defaults to `""`):
1007
+ The subfolder location of a model file within a larger model repository on the Hub or locally.
1008
+ mirror (`str`, *optional*):
1009
+ Mirror source to resolve accessibility issues if you're downloading a model in China. We do not
1010
+ guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
1011
+ information.
1012
+
1013
+ Examples:
1014
+
1015
+ ```py
1016
+ >>> from auto_diffusers import EasyPipelineForText2Image
1017
+
1018
+ >>> pipeline = EasyPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
1019
+
1020
+ >>> pipeline.auto_load_textual_inversion("EasyNegative", token="EasyNegative")
1021
+
1022
+ >>> image = pipeline(prompt).images[0]
1023
+ ```
1024
+
1025
+ """
1026
+ # 1. Set tokenizer and text encoder
1027
+ tokenizer = tokenizer or getattr(self, "tokenizer", None)
1028
+ text_encoder = text_encoder or getattr(self, "text_encoder", None)
1029
+
1030
+ # Check if tokenizer and text encoder are provided
1031
+ if tokenizer is None or text_encoder is None:
1032
+ raise ValueError("Tokenizer and text encoder must be provided.")
1033
+
1034
+ # 2. Normalize inputs
1035
+ pretrained_model_name_or_paths = (
1036
+ [pretrained_model_name_or_path]
1037
+ if not isinstance(pretrained_model_name_or_path, list)
1038
+ else pretrained_model_name_or_path
1039
+ )
1040
+
1041
+ # 2.1 Normalize tokens
1042
+ tokens = [token] if not isinstance(token, list) else token
1043
+ if tokens[0] is None:
1044
+ tokens = tokens * len(pretrained_model_name_or_paths)
1045
+
1046
+ for check_token in tokens:
1047
+ # Check if token is already in tokenizer vocabulary
1048
+ if check_token in tokenizer.get_vocab():
1049
+ raise ValueError(
1050
+ 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
+ )
1052
+
1053
+ expected_shape = text_encoder.get_input_embeddings().weight.shape[-1] # Expected shape of tokenizer
1054
+
1055
+ for search_word in pretrained_model_name_or_paths:
1056
+ if isinstance(search_word, str):
1057
+ # Update kwargs to ensure the model is downloaded and parameters are included
1058
+ _status = {
1059
+ "download": True,
1060
+ "include_params": True,
1061
+ "skip_error": False,
1062
+ "model_type": "TextualInversion",
1063
+ }
1064
+ # Get tags for the base model of textual inversion compatible with tokenizer.
1065
+ # If the tokenizer is 768-dimensional, set tags for SD 1.x and SDXL.
1066
+ # If the tokenizer is 1024-dimensional, set tags for SD 2.x.
1067
+ if expected_shape in TOKENIZER_SHAPE_MAP:
1068
+ # Retrieve the appropriate tags from the TOKENIZER_SHAPE_MAP based on the expected shape
1069
+ tags = TOKENIZER_SHAPE_MAP[expected_shape]
1070
+ if base_model is not None:
1071
+ if isinstance(base_model, list):
1072
+ tags.extend(base_model)
1073
+ else:
1074
+ tags.append(base_model)
1075
+ _status["base_model"] = tags
1076
+
1077
+ kwargs.update(_status)
1078
+ # Search for the model on Civitai and get the model status
1079
+ textual_inversion_path = search_civitai(search_word, **kwargs)
1080
+ logger.warning(
1081
+ f"textual_inversion_path: {search_word} -> {textual_inversion_path.model_status.site_url}"
1082
+ )
1083
+
1084
+ pretrained_model_name_or_paths[pretrained_model_name_or_paths.index(search_word)] = (
1085
+ textual_inversion_path.model_path
1086
+ )
1087
+
1088
+ self.load_textual_inversion(
1089
+ pretrained_model_name_or_paths, token=tokens, tokenizer=tokenizer, text_encoder=text_encoder, **kwargs
1090
+ )
1091
+
1092
+ def auto_load_lora_weights(
1093
+ self, pretrained_model_name_or_path_or_dict: Union[str, Dict[str, torch.Tensor]], adapter_name=None, **kwargs
1094
+ ):
1095
+ r"""
1096
+ Load LoRA weights specified in `pretrained_model_name_or_path_or_dict` into `self.unet` and
1097
+ `self.text_encoder`.
1098
+
1099
+ All kwargs are forwarded to `self.lora_state_dict`.
1100
+
1101
+ See [`~loaders.StableDiffusionLoraLoaderMixin.lora_state_dict`] for more details on how the state dict is
1102
+ loaded.
1103
+
1104
+ See [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_into_unet`] for more details on how the state dict is
1105
+ loaded into `self.unet`.
1106
+
1107
+ See [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_into_text_encoder`] for more details on how the state
1108
+ dict is loaded into `self.text_encoder`.
1109
+
1110
+ Parameters:
1111
+ pretrained_model_name_or_path_or_dict (`str` or `os.PathLike` or `dict`):
1112
+ See [`~loaders.StableDiffusionLoraLoaderMixin.lora_state_dict`].
1113
+ adapter_name (`str`, *optional*):
1114
+ Adapter name to be used for referencing the loaded adapter model. If not specified, it will use
1115
+ `default_{i}` where i is the total number of adapters being loaded.
1116
+ low_cpu_mem_usage (`bool`, *optional*):
1117
+ Speed up model loading by only loading the pretrained LoRA weights and not initializing the random
1118
+ weights.
1119
+ kwargs (`dict`, *optional*):
1120
+ See [`~loaders.StableDiffusionLoraLoaderMixin.lora_state_dict`].
1121
+ """
1122
+ if isinstance(pretrained_model_name_or_path_or_dict, str):
1123
+ # Update kwargs to ensure the model is downloaded and parameters are included
1124
+ _status = {
1125
+ "download": True,
1126
+ "include_params": True,
1127
+ "skip_error": False,
1128
+ "model_type": "LORA",
1129
+ }
1130
+ kwargs.update(_status)
1131
+ # Search for the model on Civitai and get the model status
1132
+ lora_path = search_civitai(pretrained_model_name_or_path_or_dict, **kwargs)
1133
+ logger.warning(f"lora_path: {lora_path.model_status.site_url}")
1134
+ logger.warning(f"trained_words: {lora_path.extra_status.trained_words}")
1135
+ pretrained_model_name_or_path_or_dict = lora_path.model_path
1136
+
1137
+ self.load_lora_weights(pretrained_model_name_or_path_or_dict, adapter_name=adapter_name, **kwargs)
1138
+
1139
+
1140
+ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1141
+ r"""
1142
+ [`EasyPipelineForText2Image`] is a generic pipeline class that instantiates a text-to-image pipeline class. The
778
1143
  specific underlying pipeline class is automatically selected from either the
779
- [`~AutoPipelineForText2Image.from_pretrained`] or [`~AutoPipelineForText2Image.from_pipe`] methods.
1144
+ [`~EasyPipelineForText2Image.from_pretrained`], [`~EasyPipelineForText2Image.from_pipe`], [`~EasyPipelineForText2Image.from_huggingface`] or [`~EasyPipelineForText2Image.from_civitai`] methods.
780
1145
 
781
1146
  This class cannot be instantiated using `__init__()` (throws an error).
782
1147
 
@@ -891,9 +1256,9 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
891
1256
  Examples:
892
1257
 
893
1258
  ```py
894
- >>> from diffusers import AutoPipelineForText2Image
1259
+ >>> from auto_diffusers import EasyPipelineForText2Image
895
1260
 
896
- >>> pipeline = AutoPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
1261
+ >>> pipeline = EasyPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
897
1262
  >>> image = pipeline(prompt).images[0]
898
1263
  ```
899
1264
  """
@@ -907,20 +1272,21 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
907
1272
  kwargs.update(_status)
908
1273
 
909
1274
  # Search for the model on Hugging Face and get the model status
910
- hf_model_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
911
- logger.warning(f"checkpoint_path: {hf_model_status.model_status.download_url}")
912
- checkpoint_path = hf_model_status.model_path
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}")
1277
+ checkpoint_path = hf_checkpoint_status.model_path
913
1278
 
914
1279
  # Check the format of the model checkpoint
915
- if hf_model_status.checkpoint_format == "single_file":
1280
+ if hf_checkpoint_status.loading_method == "from_single_file":
916
1281
  # Load the pipeline from a single file checkpoint
917
- return load_pipeline_from_single_file(
1282
+ pipeline = load_pipeline_from_single_file(
918
1283
  pretrained_model_or_path=checkpoint_path,
919
1284
  pipeline_mapping=SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING,
920
1285
  **kwargs,
921
1286
  )
922
1287
  else:
923
- return cls.from_pretrained(checkpoint_path, **kwargs)
1288
+ pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
1289
+ return add_methods(pipeline)
924
1290
 
925
1291
  @classmethod
926
1292
  def from_civitai(cls, pretrained_model_link_or_path, **kwargs):
@@ -999,9 +1365,9 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
999
1365
  Examples:
1000
1366
 
1001
1367
  ```py
1002
- >>> from diffusers import AutoPipelineForText2Image
1368
+ >>> from auto_diffusers import EasyPipelineForText2Image
1003
1369
 
1004
- >>> pipeline = AutoPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
1370
+ >>> pipeline = EasyPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
1005
1371
  >>> image = pipeline(prompt).images[0]
1006
1372
  ```
1007
1373
  """
@@ -1015,24 +1381,25 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
1015
1381
  kwargs.update(_status)
1016
1382
 
1017
1383
  # Search for the model on Civitai and get the model status
1018
- model_status = search_civitai(pretrained_model_link_or_path, **kwargs)
1019
- logger.warning(f"checkpoint_path: {model_status.model_status.download_url}")
1020
- checkpoint_path = model_status.model_path
1384
+ checkpoint_status = search_civitai(pretrained_model_link_or_path, **kwargs)
1385
+ logger.warning(f"checkpoint_path: {checkpoint_status.model_status.site_url}")
1386
+ checkpoint_path = checkpoint_status.model_path
1021
1387
 
1022
1388
  # Load the pipeline from a single file checkpoint
1023
- return load_pipeline_from_single_file(
1389
+ pipeline = load_pipeline_from_single_file(
1024
1390
  pretrained_model_or_path=checkpoint_path,
1025
1391
  pipeline_mapping=SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING,
1026
1392
  **kwargs,
1027
1393
  )
1394
+ return add_methods(pipeline)
1028
1395
 
1029
1396
 
1030
1397
  class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1031
1398
  r"""
1032
1399
 
1033
- [`AutoPipelineForImage2Image`] is a generic pipeline class that instantiates an image-to-image pipeline class. The
1400
+ [`EasyPipelineForImage2Image`] is a generic pipeline class that instantiates an image-to-image pipeline class. The
1034
1401
  specific underlying pipeline class is automatically selected from either the
1035
- [`~AutoPipelineForImage2Image.from_pretrained`] or [`~AutoPipelineForImage2Image.from_pipe`] methods.
1402
+ [`~EasyPipelineForImage2Image.from_pretrained`], [`~EasyPipelineForImage2Image.from_pipe`], [`~EasyPipelineForImage2Image.from_huggingface`] or [`~EasyPipelineForImage2Image.from_civitai`] methods.
1036
1403
 
1037
1404
  This class cannot be instantiated using `__init__()` (throws an error).
1038
1405
 
@@ -1147,10 +1514,10 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1147
1514
  Examples:
1148
1515
 
1149
1516
  ```py
1150
- >>> from diffusers import AutoPipelineForText2Image
1517
+ >>> from auto_diffusers import EasyPipelineForImage2Image
1151
1518
 
1152
- >>> pipeline = AutoPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
1153
- >>> image = pipeline(prompt).images[0]
1519
+ >>> pipeline = EasyPipelineForImage2Image.from_huggingface("stable-diffusion-v1-5")
1520
+ >>> image = pipeline(prompt, image).images[0]
1154
1521
  ```
1155
1522
  """
1156
1523
  # Update kwargs to ensure the model is downloaded and parameters are included
@@ -1163,20 +1530,22 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1163
1530
  kwargs.update(_parmas)
1164
1531
 
1165
1532
  # Search for the model on Hugging Face and get the model status
1166
- model_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
1167
- logger.warning(f"checkpoint_path: {model_status.model_status.download_url}")
1168
- checkpoint_path = model_status.model_path
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}")
1535
+ checkpoint_path = hf_checkpoint_status.model_path
1169
1536
 
1170
1537
  # Check the format of the model checkpoint
1171
- if model_status.checkpoint_format == "single_file":
1538
+ if hf_checkpoint_status.loading_method == "from_single_file":
1172
1539
  # Load the pipeline from a single file checkpoint
1173
- return load_pipeline_from_single_file(
1540
+ pipeline = load_pipeline_from_single_file(
1174
1541
  pretrained_model_or_path=checkpoint_path,
1175
1542
  pipeline_mapping=SINGLE_FILE_CHECKPOINT_IMAGE2IMAGE_PIPELINE_MAPPING,
1176
1543
  **kwargs,
1177
1544
  )
1178
1545
  else:
1179
- return cls.from_pretrained(checkpoint_path, **kwargs)
1546
+ pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
1547
+
1548
+ return add_methods(pipeline)
1180
1549
 
1181
1550
  @classmethod
1182
1551
  def from_civitai(cls, pretrained_model_link_or_path, **kwargs):
@@ -1255,10 +1624,10 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1255
1624
  Examples:
1256
1625
 
1257
1626
  ```py
1258
- >>> from diffusers import AutoPipelineForText2Image
1627
+ >>> from auto_diffusers import EasyPipelineForImage2Image
1259
1628
 
1260
- >>> pipeline = AutoPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
1261
- >>> image = pipeline(prompt).images[0]
1629
+ >>> pipeline = EasyPipelineForImage2Image.from_huggingface("stable-diffusion-v1-5")
1630
+ >>> image = pipeline(prompt, image).images[0]
1262
1631
  ```
1263
1632
  """
1264
1633
  # Update kwargs to ensure the model is downloaded and parameters are included
@@ -1271,24 +1640,25 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
1271
1640
  kwargs.update(_status)
1272
1641
 
1273
1642
  # Search for the model on Civitai and get the model status
1274
- model_status = search_civitai(pretrained_model_link_or_path, **kwargs)
1275
- logger.warning(f"checkpoint_path: {model_status.model_status.download_url}")
1276
- checkpoint_path = model_status.model_path
1643
+ checkpoint_status = search_civitai(pretrained_model_link_or_path, **kwargs)
1644
+ logger.warning(f"checkpoint_path: {checkpoint_status.model_status.site_url}")
1645
+ checkpoint_path = checkpoint_status.model_path
1277
1646
 
1278
1647
  # Load the pipeline from a single file checkpoint
1279
- return load_pipeline_from_single_file(
1648
+ pipeline = load_pipeline_from_single_file(
1280
1649
  pretrained_model_or_path=checkpoint_path,
1281
1650
  pipeline_mapping=SINGLE_FILE_CHECKPOINT_IMAGE2IMAGE_PIPELINE_MAPPING,
1282
1651
  **kwargs,
1283
1652
  )
1653
+ return add_methods(pipeline)
1284
1654
 
1285
1655
 
1286
1656
  class EasyPipelineForInpainting(AutoPipelineForInpainting):
1287
1657
  r"""
1288
1658
 
1289
- [`AutoPipelineForInpainting`] is a generic pipeline class that instantiates an inpainting pipeline class. The
1659
+ [`EasyPipelineForInpainting`] is a generic pipeline class that instantiates an inpainting pipeline class. The
1290
1660
  specific underlying pipeline class is automatically selected from either the
1291
- [`~AutoPipelineForInpainting.from_pretrained`] or [`~AutoPipelineForInpainting.from_pipe`] methods.
1661
+ [`~EasyPipelineForInpainting.from_pretrained`], [`~EasyPipelineForInpainting.from_pipe`], [`~EasyPipelineForInpainting.from_huggingface`] or [`~EasyPipelineForInpainting.from_civitai`] methods.
1292
1662
 
1293
1663
  This class cannot be instantiated using `__init__()` (throws an error).
1294
1664
 
@@ -1403,10 +1773,10 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
1403
1773
  Examples:
1404
1774
 
1405
1775
  ```py
1406
- >>> from diffusers import AutoPipelineForText2Image
1776
+ >>> from auto_diffusers import EasyPipelineForInpainting
1407
1777
 
1408
- >>> pipeline = AutoPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
1409
- >>> image = pipeline(prompt).images[0]
1778
+ >>> pipeline = EasyPipelineForInpainting.from_huggingface("stable-diffusion-2-inpainting")
1779
+ >>> image = pipeline(prompt, image=init_image, mask_image=mask_image).images[0]
1410
1780
  ```
1411
1781
  """
1412
1782
  # Update kwargs to ensure the model is downloaded and parameters are included
@@ -1419,20 +1789,21 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
1419
1789
  kwargs.update(_status)
1420
1790
 
1421
1791
  # Search for the model on Hugging Face and get the model status
1422
- model_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
1423
- logger.warning(f"checkpoint_path: {model_status.model_status.download_url}")
1424
- checkpoint_path = model_status.model_path
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}")
1794
+ checkpoint_path = hf_checkpoint_status.model_path
1425
1795
 
1426
1796
  # Check the format of the model checkpoint
1427
- if model_status.checkpoint_format == "single_file":
1797
+ if hf_checkpoint_status.loading_method == "from_single_file":
1428
1798
  # Load the pipeline from a single file checkpoint
1429
- return load_pipeline_from_single_file(
1799
+ pipeline = load_pipeline_from_single_file(
1430
1800
  pretrained_model_or_path=checkpoint_path,
1431
1801
  pipeline_mapping=SINGLE_FILE_CHECKPOINT_INPAINT_PIPELINE_MAPPING,
1432
1802
  **kwargs,
1433
1803
  )
1434
1804
  else:
1435
- return cls.from_pretrained(checkpoint_path, **kwargs)
1805
+ pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
1806
+ return add_methods(pipeline)
1436
1807
 
1437
1808
  @classmethod
1438
1809
  def from_civitai(cls, pretrained_model_link_or_path, **kwargs):
@@ -1511,10 +1882,10 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
1511
1882
  Examples:
1512
1883
 
1513
1884
  ```py
1514
- >>> from diffusers import AutoPipelineForText2Image
1885
+ >>> from auto_diffusers import EasyPipelineForInpainting
1515
1886
 
1516
- >>> pipeline = AutoPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
1517
- >>> image = pipeline(prompt).images[0]
1887
+ >>> pipeline = EasyPipelineForInpainting.from_huggingface("stable-diffusion-2-inpainting")
1888
+ >>> image = pipeline(prompt, image=init_image, mask_image=mask_image).images[0]
1518
1889
  ```
1519
1890
  """
1520
1891
  # Update kwargs to ensure the model is downloaded and parameters are included
@@ -1527,13 +1898,14 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
1527
1898
  kwargs.update(_status)
1528
1899
 
1529
1900
  # Search for the model on Civitai and get the model status
1530
- model_status = search_civitai(pretrained_model_link_or_path, **kwargs)
1531
- logger.warning(f"checkpoint_path: {model_status.model_status.download_url}")
1532
- checkpoint_path = model_status.model_path
1901
+ checkpoint_status = search_civitai(pretrained_model_link_or_path, **kwargs)
1902
+ logger.warning(f"checkpoint_path: {checkpoint_status.model_status.site_url}")
1903
+ checkpoint_path = checkpoint_status.model_path
1533
1904
 
1534
1905
  # Load the pipeline from a single file checkpoint
1535
- return load_pipeline_from_single_file(
1906
+ pipeline = load_pipeline_from_single_file(
1536
1907
  pretrained_model_or_path=checkpoint_path,
1537
1908
  pipeline_mapping=SINGLE_FILE_CHECKPOINT_INPAINT_PIPELINE_MAPPING,
1538
1909
  **kwargs,
1539
1910
  )
1911
+ return add_methods(pipeline)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: auto_diffusers
3
- Version: 2.0.14
3
+ Version: 2.0.20
4
4
  Summary: Customized diffusers with model search and other functions.
5
5
  Home-page: https://github.com/suzukimain/auto_diffusers
6
6
  Author: suzukimain
@@ -11,6 +11,7 @@ Classifier: Development Status :: 5 - Production/Stable
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: Intended Audience :: Education
13
13
  Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: Apache Software License
14
15
  Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
16
  Classifier: Programming Language :: Python :: 3
16
17
  Classifier: Programming Language :: Python :: 3.8
@@ -22,7 +23,18 @@ Description-Content-Type: text/markdown
22
23
  License-File: LICENSE
23
24
  Requires-Dist: torch
24
25
  Requires-Dist: diffusers
26
+ Requires-Dist: transformers
25
27
  Requires-Dist: huggingface-hub>=0.26.2
28
+ Dynamic: author
29
+ Dynamic: author-email
30
+ Dynamic: classifier
31
+ Dynamic: description
32
+ Dynamic: description-content-type
33
+ Dynamic: home-page
34
+ Dynamic: keywords
35
+ Dynamic: license
36
+ Dynamic: requires-dist
37
+ Dynamic: summary
26
38
 
27
39
  # auto_diffusers
28
40
 
@@ -61,46 +73,26 @@ pip install --quiet auto_diffusers
61
73
  from auto_diffusers import EasyPipelineForText2Image
62
74
 
63
75
  # Search for Huggingface
64
- pipe = EasyPipelineForText2Image.from_huggingface("any").to("cuda")
76
+ pipe = EasyPipelineForText2Image.from_huggingface("search_word").to("cuda")
65
77
  img = pipe("cat").images[0]
66
78
  img.save("cat.png")
67
79
 
68
80
 
69
81
  # Search for Civitai
70
- pipe = EasyPipelineForText2Image.from_civitai("any").to("cuda")
82
+ pipe = EasyPipelineForText2Image.from_civitai("search_word").to("cuda")
71
83
  image = pipe("cat").images[0]
72
84
  image.save("cat.png")
73
85
 
74
86
  ```
75
87
 
76
- ## Search Civitai and Huggingfacee<a name = "Search_Civitai_and_Huggingfacee"></a>
88
+ ## Search Civitai and Huggingfacee<a name = "Search_Civitai_and_Huggingface"></a>
77
89
 
78
90
  ```python
79
- from pipeline_easy import (
80
- search_huggingface,
81
- search_civitai,
82
- )
83
-
84
- # Search Lora
85
- Lora = search_civitai(
86
- "Keyword_to_search_Lora",
87
- model_type="LORA",
88
- base_model = "SD 1.5",
89
- download=True,
90
- )
91
91
  # Load Lora into the pipeline.
92
- pipeline.load_lora_weights(Lora)
92
+ pipe.auto_load_lora_weights("Detail Tweaker")
93
93
 
94
-
95
- # Search TextualInversion
96
- TextualInversion = search_civitai(
97
- "EasyNegative",
98
- model_type="TextualInversion",
99
- base_model = "SD 1.5",
100
- download=True
101
- )
102
94
  # Load TextualInversion into the pipeline.
103
- pipeline.load_textual_inversion(TextualInversion, token="EasyNegative")
95
+ pipe.auto_load_textual_inversion("EasyNegative", token="EasyNegative")
104
96
  ```
105
97
 
106
98
  ### Search Civitai<a name = "Search_Civitai"></a>
@@ -1,7 +1,6 @@
1
1
  LICENSE
2
2
  MANIFEST.in
3
3
  README.md
4
- Version.txt
5
4
  setup.py
6
5
  src/auto_diffusers/__init__.py
7
6
  src/auto_diffusers/pipeline_easy.py
@@ -1,3 +1,4 @@
1
1
  torch
2
2
  diffusers
3
+ transformers
3
4
  huggingface-hub>=0.26.2
@@ -1 +0,0 @@
1
- 2.0.14
File without changes