auto-diffusers 2.0.14__py3-none-any.whl → 2.0.16__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.
- auto_diffusers/pipeline_easy.py +456 -93
- {auto_diffusers-2.0.14.dist-info → auto_diffusers-2.0.16.dist-info}/METADATA +6 -26
- auto_diffusers-2.0.16.dist-info/RECORD +8 -0
- auto_diffusers-2.0.14.dist-info/RECORD +0 -8
- {auto_diffusers-2.0.14.dist-info → auto_diffusers-2.0.16.dist-info}/LICENSE +0 -0
- {auto_diffusers-2.0.14.dist-info → auto_diffusers-2.0.16.dist-info}/WHEEL +0 -0
- {auto_diffusers-2.0.14.dist-info → auto_diffusers-2.0.16.dist-info}/top_level.txt +0 -0
auto_diffusers/pipeline_easy.py
CHANGED
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
|
|
16
16
|
import os
|
|
17
17
|
import re
|
|
18
|
+
import types
|
|
18
19
|
from collections import OrderedDict
|
|
19
20
|
from dataclasses import asdict, dataclass
|
|
20
|
-
from typing import Union
|
|
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
|
-
("
|
|
63
|
-
("
|
|
64
|
-
("
|
|
65
|
-
("
|
|
66
|
-
("
|
|
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
|
-
("
|
|
70
|
-
("
|
|
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
|
-
("
|
|
78
|
-
("
|
|
79
|
-
("
|
|
80
|
-
("
|
|
81
|
-
("
|
|
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
|
-
("
|
|
85
|
-
("
|
|
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
|
-
("
|
|
93
|
-
("
|
|
94
|
-
("
|
|
95
|
-
("
|
|
96
|
-
("
|
|
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
|
-
("
|
|
100
|
-
("
|
|
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 = [
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"
|
|
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
|
|
@@ -193,6 +323,7 @@ class SearchResult:
|
|
|
193
323
|
checkpoint_format: Union[str, None] = None
|
|
194
324
|
repo_status: RepoStatus = RepoStatus()
|
|
195
325
|
model_status: ModelStatus = ModelStatus()
|
|
326
|
+
extra_status: ExtraStatus = 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.
|
|
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
|
|
@@ -523,7 +655,10 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
|
|
|
523
655
|
if hf_security_info["scansDone"]:
|
|
524
656
|
for info in repo_info["siblings"]:
|
|
525
657
|
file_path = info["rfilename"]
|
|
526
|
-
if "model_index.json" == file_path and checkpoint_format in [
|
|
658
|
+
if "model_index.json" == file_path and checkpoint_format in [
|
|
659
|
+
"diffusers",
|
|
660
|
+
"all",
|
|
661
|
+
]:
|
|
527
662
|
diffusers_model_exists = True
|
|
528
663
|
break
|
|
529
664
|
|
|
@@ -586,10 +721,12 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
|
|
|
586
721
|
repo_status=RepoStatus(repo_id=repo_id, repo_hash=hf_repo_info.sha, version=revision),
|
|
587
722
|
model_status=ModelStatus(
|
|
588
723
|
search_word=search_word,
|
|
724
|
+
site_url=download_url,
|
|
589
725
|
download_url=download_url,
|
|
590
726
|
file_name=file_name,
|
|
591
727
|
local=download,
|
|
592
728
|
),
|
|
729
|
+
extra_status=ExtraStatus(trained_words=None),
|
|
593
730
|
)
|
|
594
731
|
|
|
595
732
|
else:
|
|
@@ -605,6 +742,8 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
605
742
|
The search query string.
|
|
606
743
|
model_type (`str`, *optional*, defaults to `Checkpoint`):
|
|
607
744
|
The type of model to search for.
|
|
745
|
+
sort (`str`, *optional*):
|
|
746
|
+
The order in which you wish to sort the results(for example, `Highest Rated`, `Most Downloaded`, `Newest`).
|
|
608
747
|
base_model (`str`, *optional*):
|
|
609
748
|
The base model to filter by.
|
|
610
749
|
download (`bool`, *optional*, defaults to `False`):
|
|
@@ -628,6 +767,7 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
628
767
|
|
|
629
768
|
# Extract additional parameters from kwargs
|
|
630
769
|
model_type = kwargs.pop("model_type", "Checkpoint")
|
|
770
|
+
sort = kwargs.pop("sort", None)
|
|
631
771
|
download = kwargs.pop("download", False)
|
|
632
772
|
base_model = kwargs.pop("base_model", None)
|
|
633
773
|
force_download = kwargs.pop("force_download", False)
|
|
@@ -642,6 +782,7 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
642
782
|
repo_name = ""
|
|
643
783
|
repo_id = ""
|
|
644
784
|
version_id = ""
|
|
785
|
+
trainedWords = ""
|
|
645
786
|
models_list = []
|
|
646
787
|
selected_repo = {}
|
|
647
788
|
selected_model = {}
|
|
@@ -652,12 +793,16 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
652
793
|
params = {
|
|
653
794
|
"query": search_word,
|
|
654
795
|
"types": model_type,
|
|
655
|
-
"sort": "Most Downloaded",
|
|
656
796
|
"limit": 20,
|
|
657
797
|
}
|
|
658
798
|
if base_model is not None:
|
|
799
|
+
if not isinstance(base_model, list):
|
|
800
|
+
base_model = [base_model]
|
|
659
801
|
params["baseModel"] = base_model
|
|
660
802
|
|
|
803
|
+
if sort is not None:
|
|
804
|
+
params["sort"] = sort
|
|
805
|
+
|
|
661
806
|
headers = {}
|
|
662
807
|
if token:
|
|
663
808
|
headers["Authorization"] = f"Bearer {token}"
|
|
@@ -686,25 +831,30 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
686
831
|
|
|
687
832
|
# Sort versions within the selected repo by download count
|
|
688
833
|
sorted_versions = sorted(
|
|
689
|
-
selected_repo["modelVersions"],
|
|
834
|
+
selected_repo["modelVersions"],
|
|
835
|
+
key=lambda x: x["stats"]["downloadCount"],
|
|
836
|
+
reverse=True,
|
|
690
837
|
)
|
|
691
838
|
for selected_version in sorted_versions:
|
|
692
839
|
version_id = selected_version["id"]
|
|
840
|
+
trainedWords = selected_version["trainedWords"]
|
|
693
841
|
models_list = []
|
|
694
|
-
for
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
model_data["
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
842
|
+
# When searching for textual inversion, results other than the values entered for the base model may come up, so check again.
|
|
843
|
+
if base_model is None or selected_version["baseModel"] in base_model:
|
|
844
|
+
for model_data in selected_version["files"]:
|
|
845
|
+
# Check if the file passes security scans and has a valid extension
|
|
846
|
+
file_name = model_data["name"]
|
|
847
|
+
if (
|
|
848
|
+
model_data["pickleScanResult"] == "Success"
|
|
849
|
+
and model_data["virusScanResult"] == "Success"
|
|
850
|
+
and any(file_name.endswith(ext) for ext in EXTENSION)
|
|
851
|
+
and os.path.basename(os.path.dirname(file_name)) not in DIFFUSERS_CONFIG_DIR
|
|
852
|
+
):
|
|
853
|
+
file_status = {
|
|
854
|
+
"filename": file_name,
|
|
855
|
+
"download_url": model_data["downloadUrl"],
|
|
856
|
+
}
|
|
857
|
+
models_list.append(file_status)
|
|
708
858
|
|
|
709
859
|
if models_list:
|
|
710
860
|
# Sort the models list by filename and find the safest model
|
|
@@ -764,19 +914,229 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
|
|
|
764
914
|
repo_status=RepoStatus(repo_id=repo_name, repo_hash=repo_id, version=version_id),
|
|
765
915
|
model_status=ModelStatus(
|
|
766
916
|
search_word=search_word,
|
|
917
|
+
site_url=f"https://civitai.com/models/{repo_id}?modelVersionId={version_id}",
|
|
767
918
|
download_url=download_url,
|
|
768
919
|
file_name=file_name,
|
|
769
920
|
local=output_info["type"]["local"],
|
|
770
921
|
),
|
|
922
|
+
extra_status=ExtraStatus(trained_words=trainedWords or None),
|
|
771
923
|
)
|
|
772
924
|
|
|
773
925
|
|
|
774
|
-
|
|
926
|
+
def add_methods(pipeline):
|
|
775
927
|
r"""
|
|
928
|
+
Add methods from `AutoConfig` to the pipeline.
|
|
929
|
+
|
|
930
|
+
Parameters:
|
|
931
|
+
pipeline (`Pipeline`):
|
|
932
|
+
The pipeline to which the methods will be added.
|
|
933
|
+
"""
|
|
934
|
+
for attr_name in dir(AutoConfig):
|
|
935
|
+
attr_value = getattr(AutoConfig, attr_name)
|
|
936
|
+
if callable(attr_value) and not attr_name.startswith("__"):
|
|
937
|
+
setattr(pipeline, attr_name, types.MethodType(attr_value, pipeline))
|
|
938
|
+
return pipeline
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
class AutoConfig:
|
|
942
|
+
def auto_load_textual_inversion(
|
|
943
|
+
self,
|
|
944
|
+
pretrained_model_name_or_path: Union[str, List[str]],
|
|
945
|
+
token: Optional[Union[str, List[str]]] = None,
|
|
946
|
+
base_model: Optional[Union[str, List[str]]] = None,
|
|
947
|
+
tokenizer=None,
|
|
948
|
+
text_encoder=None,
|
|
949
|
+
**kwargs,
|
|
950
|
+
):
|
|
951
|
+
r"""
|
|
952
|
+
Load Textual Inversion embeddings into the text encoder of [`StableDiffusionPipeline`] (both 🤗 Diffusers and
|
|
953
|
+
Automatic1111 formats are supported).
|
|
954
|
+
|
|
955
|
+
Parameters:
|
|
956
|
+
pretrained_model_name_or_path (`str` or `os.PathLike` or `List[str or os.PathLike]` or `Dict` or `List[Dict]`):
|
|
957
|
+
Can be either one of the following or a list of them:
|
|
958
|
+
|
|
959
|
+
- Search keywords for pretrained model (for example `EasyNegative`).
|
|
960
|
+
- A string, the *model id* (for example `sd-concepts-library/low-poly-hd-logos-icons`) of a
|
|
961
|
+
pretrained model hosted on the Hub.
|
|
962
|
+
- A path to a *directory* (for example `./my_text_inversion_directory/`) containing the textual
|
|
963
|
+
inversion weights.
|
|
964
|
+
- A path to a *file* (for example `./my_text_inversions.pt`) containing textual inversion weights.
|
|
965
|
+
- A [torch state
|
|
966
|
+
dict](https://pytorch.org/tutorials/beginner/saving_loading_models.html#what-is-a-state-dict).
|
|
967
|
+
|
|
968
|
+
token (`str` or `List[str]`, *optional*):
|
|
969
|
+
Override the token to use for the textual inversion weights. If `pretrained_model_name_or_path` is a
|
|
970
|
+
list, then `token` must also be a list of equal length.
|
|
971
|
+
text_encoder ([`~transformers.CLIPTextModel`], *optional*):
|
|
972
|
+
Frozen text-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14)).
|
|
973
|
+
If not specified, function will take self.tokenizer.
|
|
974
|
+
tokenizer ([`~transformers.CLIPTokenizer`], *optional*):
|
|
975
|
+
A `CLIPTokenizer` to tokenize text. If not specified, function will take self.tokenizer.
|
|
976
|
+
weight_name (`str`, *optional*):
|
|
977
|
+
Name of a custom weight file. This should be used when:
|
|
978
|
+
|
|
979
|
+
- The saved textual inversion file is in 🤗 Diffusers format, but was saved under a specific weight
|
|
980
|
+
name such as `text_inv.bin`.
|
|
981
|
+
- The saved textual inversion file is in the Automatic1111 format.
|
|
982
|
+
cache_dir (`Union[str, os.PathLike]`, *optional*):
|
|
983
|
+
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache
|
|
984
|
+
is not used.
|
|
985
|
+
force_download (`bool`, *optional*, defaults to `False`):
|
|
986
|
+
Whether or not to force the (re-)download of the model weights and configuration files, overriding the
|
|
987
|
+
cached versions if they exist.
|
|
988
|
+
|
|
989
|
+
proxies (`Dict[str, str]`, *optional*):
|
|
990
|
+
A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128',
|
|
991
|
+
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
|
|
992
|
+
local_files_only (`bool`, *optional*, defaults to `False`):
|
|
993
|
+
Whether to only load local model weights and configuration files or not. If set to `True`, the model
|
|
994
|
+
won't be downloaded from the Hub.
|
|
995
|
+
token (`str` or *bool*, *optional*):
|
|
996
|
+
The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from
|
|
997
|
+
`diffusers-cli login` (stored in `~/.huggingface`) is used.
|
|
998
|
+
revision (`str`, *optional*, defaults to `"main"`):
|
|
999
|
+
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier
|
|
1000
|
+
allowed by Git.
|
|
1001
|
+
subfolder (`str`, *optional*, defaults to `""`):
|
|
1002
|
+
The subfolder location of a model file within a larger model repository on the Hub or locally.
|
|
1003
|
+
mirror (`str`, *optional*):
|
|
1004
|
+
Mirror source to resolve accessibility issues if you're downloading a model in China. We do not
|
|
1005
|
+
guarantee the timeliness or safety of the source, and you should refer to the mirror site for more
|
|
1006
|
+
information.
|
|
1007
|
+
|
|
1008
|
+
Examples:
|
|
1009
|
+
|
|
1010
|
+
```py
|
|
1011
|
+
>>> from auto_diffusers import EasyPipelineForText2Image
|
|
1012
|
+
|
|
1013
|
+
>>> pipeline = EasyPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
|
|
1014
|
+
|
|
1015
|
+
>>> pipeline.auto_load_textual_inversion("EasyNegative", token="EasyNegative")
|
|
1016
|
+
|
|
1017
|
+
>>> image = pipeline(prompt).images[0]
|
|
1018
|
+
```
|
|
776
1019
|
|
|
777
|
-
|
|
1020
|
+
"""
|
|
1021
|
+
# 1. Set tokenizer and text encoder
|
|
1022
|
+
tokenizer = tokenizer or getattr(self, "tokenizer", None)
|
|
1023
|
+
text_encoder = text_encoder or getattr(self, "text_encoder", None)
|
|
1024
|
+
|
|
1025
|
+
# Check if tokenizer and text encoder are provided
|
|
1026
|
+
if tokenizer is None or text_encoder is None:
|
|
1027
|
+
raise ValueError("Tokenizer and text encoder must be provided.")
|
|
1028
|
+
|
|
1029
|
+
# 2. Normalize inputs
|
|
1030
|
+
pretrained_model_name_or_paths = (
|
|
1031
|
+
[pretrained_model_name_or_path]
|
|
1032
|
+
if not isinstance(pretrained_model_name_or_path, list)
|
|
1033
|
+
else pretrained_model_name_or_path
|
|
1034
|
+
)
|
|
1035
|
+
|
|
1036
|
+
# 2.1 Normalize tokens
|
|
1037
|
+
tokens = [token] if not isinstance(token, list) else token
|
|
1038
|
+
if tokens[0] is None:
|
|
1039
|
+
tokens = tokens * len(pretrained_model_name_or_paths)
|
|
1040
|
+
|
|
1041
|
+
for check_token in tokens:
|
|
1042
|
+
# Check if token is already in tokenizer vocabulary
|
|
1043
|
+
if check_token in tokenizer.get_vocab():
|
|
1044
|
+
raise ValueError(
|
|
1045
|
+
f"Token {token} already in tokenizer vocabulary. Please choose a different token name or remove {token} and embedding from the tokenizer and text encoder."
|
|
1046
|
+
)
|
|
1047
|
+
|
|
1048
|
+
expected_shape = text_encoder.get_input_embeddings().weight.shape[-1] # Expected shape of tokenizer
|
|
1049
|
+
|
|
1050
|
+
for search_word in pretrained_model_name_or_paths:
|
|
1051
|
+
if isinstance(search_word, str):
|
|
1052
|
+
# Update kwargs to ensure the model is downloaded and parameters are included
|
|
1053
|
+
_status = {
|
|
1054
|
+
"download": True,
|
|
1055
|
+
"include_params": True,
|
|
1056
|
+
"skip_error": False,
|
|
1057
|
+
"model_type": "TextualInversion",
|
|
1058
|
+
}
|
|
1059
|
+
# Get tags for the base model of textual inversion compatible with tokenizer.
|
|
1060
|
+
# If the tokenizer is 768-dimensional, set tags for SD 1.x and SDXL.
|
|
1061
|
+
# If the tokenizer is 1024-dimensional, set tags for SD 2.x.
|
|
1062
|
+
if expected_shape in TOKENIZER_SHAPE_MAP:
|
|
1063
|
+
# Retrieve the appropriate tags from the TOKENIZER_SHAPE_MAP based on the expected shape
|
|
1064
|
+
tags = TOKENIZER_SHAPE_MAP[expected_shape]
|
|
1065
|
+
if base_model is not None:
|
|
1066
|
+
if isinstance(base_model, list):
|
|
1067
|
+
tags.extend(base_model)
|
|
1068
|
+
else:
|
|
1069
|
+
tags.append(base_model)
|
|
1070
|
+
_status["base_model"] = tags
|
|
1071
|
+
|
|
1072
|
+
kwargs.update(_status)
|
|
1073
|
+
# Search for the model on Civitai and get the model status
|
|
1074
|
+
textual_inversion_path = search_civitai(search_word, **kwargs)
|
|
1075
|
+
logger.warning(
|
|
1076
|
+
f"textual_inversion_path: {search_word} -> {textual_inversion_path.model_status.site_url}"
|
|
1077
|
+
)
|
|
1078
|
+
|
|
1079
|
+
pretrained_model_name_or_paths[pretrained_model_name_or_paths.index(search_word)] = (
|
|
1080
|
+
textual_inversion_path.model_path
|
|
1081
|
+
)
|
|
1082
|
+
|
|
1083
|
+
self.load_textual_inversion(
|
|
1084
|
+
pretrained_model_name_or_paths, token=tokens, tokenizer=tokenizer, text_encoder=text_encoder, **kwargs
|
|
1085
|
+
)
|
|
1086
|
+
|
|
1087
|
+
def auto_load_lora_weights(
|
|
1088
|
+
self, pretrained_model_name_or_path_or_dict: Union[str, Dict[str, torch.Tensor]], adapter_name=None, **kwargs
|
|
1089
|
+
):
|
|
1090
|
+
r"""
|
|
1091
|
+
Load LoRA weights specified in `pretrained_model_name_or_path_or_dict` into `self.unet` and
|
|
1092
|
+
`self.text_encoder`.
|
|
1093
|
+
|
|
1094
|
+
All kwargs are forwarded to `self.lora_state_dict`.
|
|
1095
|
+
|
|
1096
|
+
See [`~loaders.StableDiffusionLoraLoaderMixin.lora_state_dict`] for more details on how the state dict is
|
|
1097
|
+
loaded.
|
|
1098
|
+
|
|
1099
|
+
See [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_into_unet`] for more details on how the state dict is
|
|
1100
|
+
loaded into `self.unet`.
|
|
1101
|
+
|
|
1102
|
+
See [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_into_text_encoder`] for more details on how the state
|
|
1103
|
+
dict is loaded into `self.text_encoder`.
|
|
1104
|
+
|
|
1105
|
+
Parameters:
|
|
1106
|
+
pretrained_model_name_or_path_or_dict (`str` or `os.PathLike` or `dict`):
|
|
1107
|
+
See [`~loaders.StableDiffusionLoraLoaderMixin.lora_state_dict`].
|
|
1108
|
+
adapter_name (`str`, *optional*):
|
|
1109
|
+
Adapter name to be used for referencing the loaded adapter model. If not specified, it will use
|
|
1110
|
+
`default_{i}` where i is the total number of adapters being loaded.
|
|
1111
|
+
low_cpu_mem_usage (`bool`, *optional*):
|
|
1112
|
+
Speed up model loading by only loading the pretrained LoRA weights and not initializing the random
|
|
1113
|
+
weights.
|
|
1114
|
+
kwargs (`dict`, *optional*):
|
|
1115
|
+
See [`~loaders.StableDiffusionLoraLoaderMixin.lora_state_dict`].
|
|
1116
|
+
"""
|
|
1117
|
+
if isinstance(pretrained_model_name_or_path_or_dict, str):
|
|
1118
|
+
# Update kwargs to ensure the model is downloaded and parameters are included
|
|
1119
|
+
_status = {
|
|
1120
|
+
"download": True,
|
|
1121
|
+
"include_params": True,
|
|
1122
|
+
"skip_error": False,
|
|
1123
|
+
"model_type": "LORA",
|
|
1124
|
+
}
|
|
1125
|
+
kwargs.update(_status)
|
|
1126
|
+
# Search for the model on Civitai and get the model status
|
|
1127
|
+
lora_path = search_civitai(pretrained_model_name_or_path_or_dict, **kwargs)
|
|
1128
|
+
logger.warning(f"lora_path: {lora_path.model_status.site_url}")
|
|
1129
|
+
logger.warning(f"trained_words: {lora_path.extra_status.trained_words}")
|
|
1130
|
+
pretrained_model_name_or_path_or_dict = lora_path.model_path
|
|
1131
|
+
|
|
1132
|
+
self.load_lora_weights(pretrained_model_name_or_path_or_dict, adapter_name=adapter_name, **kwargs)
|
|
1133
|
+
|
|
1134
|
+
|
|
1135
|
+
class EasyPipelineForText2Image(AutoPipelineForText2Image, AutoConfig):
|
|
1136
|
+
r"""
|
|
1137
|
+
[`EasyPipelineForText2Image`] is a generic pipeline class that instantiates a text-to-image pipeline class. The
|
|
778
1138
|
specific underlying pipeline class is automatically selected from either the
|
|
779
|
-
[`~
|
|
1139
|
+
[`~EasyPipelineForText2Image.from_pretrained`], [`~EasyPipelineForText2Image.from_pipe`], [`~EasyPipelineForText2Image.from_huggingface`] or [`~EasyPipelineForText2Image.from_civitai`] methods.
|
|
780
1140
|
|
|
781
1141
|
This class cannot be instantiated using `__init__()` (throws an error).
|
|
782
1142
|
|
|
@@ -891,9 +1251,9 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
891
1251
|
Examples:
|
|
892
1252
|
|
|
893
1253
|
```py
|
|
894
|
-
>>> from
|
|
1254
|
+
>>> from auto_diffusers import EasyPipelineForText2Image
|
|
895
1255
|
|
|
896
|
-
>>> pipeline =
|
|
1256
|
+
>>> pipeline = EasyPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
|
|
897
1257
|
>>> image = pipeline(prompt).images[0]
|
|
898
1258
|
```
|
|
899
1259
|
"""
|
|
@@ -907,12 +1267,12 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
907
1267
|
kwargs.update(_status)
|
|
908
1268
|
|
|
909
1269
|
# Search for the model on Hugging Face and get the model status
|
|
910
|
-
|
|
911
|
-
logger.warning(f"checkpoint_path: {
|
|
912
|
-
checkpoint_path =
|
|
1270
|
+
hf_checkpoint_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
|
|
1271
|
+
logger.warning(f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}")
|
|
1272
|
+
checkpoint_path = hf_checkpoint_status.model_path
|
|
913
1273
|
|
|
914
1274
|
# Check the format of the model checkpoint
|
|
915
|
-
if
|
|
1275
|
+
if hf_checkpoint_status.loading_method == "from_single_file":
|
|
916
1276
|
# Load the pipeline from a single file checkpoint
|
|
917
1277
|
return load_pipeline_from_single_file(
|
|
918
1278
|
pretrained_model_or_path=checkpoint_path,
|
|
@@ -999,9 +1359,9 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
999
1359
|
Examples:
|
|
1000
1360
|
|
|
1001
1361
|
```py
|
|
1002
|
-
>>> from
|
|
1362
|
+
>>> from auto_diffusers import EasyPipelineForText2Image
|
|
1003
1363
|
|
|
1004
|
-
>>> pipeline =
|
|
1364
|
+
>>> pipeline = EasyPipelineForText2Image.from_huggingface("stable-diffusion-v1-5")
|
|
1005
1365
|
>>> image = pipeline(prompt).images[0]
|
|
1006
1366
|
```
|
|
1007
1367
|
"""
|
|
@@ -1015,24 +1375,25 @@ class EasyPipelineForText2Image(AutoPipelineForText2Image):
|
|
|
1015
1375
|
kwargs.update(_status)
|
|
1016
1376
|
|
|
1017
1377
|
# Search for the model on Civitai and get the model status
|
|
1018
|
-
|
|
1019
|
-
logger.warning(f"checkpoint_path: {
|
|
1020
|
-
checkpoint_path =
|
|
1378
|
+
checkpoint_status = search_civitai(pretrained_model_link_or_path, **kwargs)
|
|
1379
|
+
logger.warning(f"checkpoint_path: {checkpoint_status.model_status.site_url}")
|
|
1380
|
+
checkpoint_path = checkpoint_status.model_path
|
|
1021
1381
|
|
|
1022
1382
|
# Load the pipeline from a single file checkpoint
|
|
1023
|
-
|
|
1383
|
+
pipeline = load_pipeline_from_single_file(
|
|
1024
1384
|
pretrained_model_or_path=checkpoint_path,
|
|
1025
1385
|
pipeline_mapping=SINGLE_FILE_CHECKPOINT_TEXT2IMAGE_PIPELINE_MAPPING,
|
|
1026
1386
|
**kwargs,
|
|
1027
1387
|
)
|
|
1388
|
+
return add_methods(pipeline)
|
|
1028
1389
|
|
|
1029
1390
|
|
|
1030
1391
|
class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
1031
1392
|
r"""
|
|
1032
1393
|
|
|
1033
|
-
[`
|
|
1394
|
+
[`EasyPipelineForImage2Image`] is a generic pipeline class that instantiates an image-to-image pipeline class. The
|
|
1034
1395
|
specific underlying pipeline class is automatically selected from either the
|
|
1035
|
-
[`~
|
|
1396
|
+
[`~EasyPipelineForImage2Image.from_pretrained`], [`~EasyPipelineForImage2Image.from_pipe`], [`~EasyPipelineForImage2Image.from_huggingface`] or [`~EasyPipelineForImage2Image.from_civitai`] methods.
|
|
1036
1397
|
|
|
1037
1398
|
This class cannot be instantiated using `__init__()` (throws an error).
|
|
1038
1399
|
|
|
@@ -1147,10 +1508,10 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
1147
1508
|
Examples:
|
|
1148
1509
|
|
|
1149
1510
|
```py
|
|
1150
|
-
>>> from
|
|
1511
|
+
>>> from auto_diffusers import EasyPipelineForImage2Image
|
|
1151
1512
|
|
|
1152
|
-
>>> pipeline =
|
|
1153
|
-
>>> image = pipeline(prompt).images[0]
|
|
1513
|
+
>>> pipeline = EasyPipelineForImage2Image.from_huggingface("stable-diffusion-v1-5")
|
|
1514
|
+
>>> image = pipeline(prompt, image).images[0]
|
|
1154
1515
|
```
|
|
1155
1516
|
"""
|
|
1156
1517
|
# Update kwargs to ensure the model is downloaded and parameters are included
|
|
@@ -1163,20 +1524,22 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
1163
1524
|
kwargs.update(_parmas)
|
|
1164
1525
|
|
|
1165
1526
|
# Search for the model on Hugging Face and get the model status
|
|
1166
|
-
|
|
1167
|
-
logger.warning(f"checkpoint_path: {
|
|
1168
|
-
checkpoint_path =
|
|
1527
|
+
hf_checkpoint_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
|
|
1528
|
+
logger.warning(f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}")
|
|
1529
|
+
checkpoint_path = hf_checkpoint_status.model_path
|
|
1169
1530
|
|
|
1170
1531
|
# Check the format of the model checkpoint
|
|
1171
|
-
if
|
|
1532
|
+
if hf_checkpoint_status.loading_method == "from_single_file":
|
|
1172
1533
|
# Load the pipeline from a single file checkpoint
|
|
1173
|
-
|
|
1534
|
+
pipeline = load_pipeline_from_single_file(
|
|
1174
1535
|
pretrained_model_or_path=checkpoint_path,
|
|
1175
1536
|
pipeline_mapping=SINGLE_FILE_CHECKPOINT_IMAGE2IMAGE_PIPELINE_MAPPING,
|
|
1176
1537
|
**kwargs,
|
|
1177
1538
|
)
|
|
1178
1539
|
else:
|
|
1179
|
-
|
|
1540
|
+
pipeline = cls.from_pretrained(checkpoint_path, **kwargs)
|
|
1541
|
+
|
|
1542
|
+
return add_methods(pipeline)
|
|
1180
1543
|
|
|
1181
1544
|
@classmethod
|
|
1182
1545
|
def from_civitai(cls, pretrained_model_link_or_path, **kwargs):
|
|
@@ -1255,10 +1618,10 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
1255
1618
|
Examples:
|
|
1256
1619
|
|
|
1257
1620
|
```py
|
|
1258
|
-
>>> from
|
|
1621
|
+
>>> from auto_diffusers import EasyPipelineForImage2Image
|
|
1259
1622
|
|
|
1260
|
-
>>> pipeline =
|
|
1261
|
-
>>> image = pipeline(prompt).images[0]
|
|
1623
|
+
>>> pipeline = EasyPipelineForImage2Image.from_huggingface("stable-diffusion-v1-5")
|
|
1624
|
+
>>> image = pipeline(prompt, image).images[0]
|
|
1262
1625
|
```
|
|
1263
1626
|
"""
|
|
1264
1627
|
# Update kwargs to ensure the model is downloaded and parameters are included
|
|
@@ -1271,9 +1634,9 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
1271
1634
|
kwargs.update(_status)
|
|
1272
1635
|
|
|
1273
1636
|
# Search for the model on Civitai and get the model status
|
|
1274
|
-
|
|
1275
|
-
logger.warning(f"checkpoint_path: {
|
|
1276
|
-
checkpoint_path =
|
|
1637
|
+
checkpoint_status = search_civitai(pretrained_model_link_or_path, **kwargs)
|
|
1638
|
+
logger.warning(f"checkpoint_path: {checkpoint_status.model_status.site_url}")
|
|
1639
|
+
checkpoint_path = checkpoint_status.model_path
|
|
1277
1640
|
|
|
1278
1641
|
# Load the pipeline from a single file checkpoint
|
|
1279
1642
|
return load_pipeline_from_single_file(
|
|
@@ -1286,9 +1649,9 @@ class EasyPipelineForImage2Image(AutoPipelineForImage2Image):
|
|
|
1286
1649
|
class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
1287
1650
|
r"""
|
|
1288
1651
|
|
|
1289
|
-
[`
|
|
1652
|
+
[`EasyPipelineForInpainting`] is a generic pipeline class that instantiates an inpainting pipeline class. The
|
|
1290
1653
|
specific underlying pipeline class is automatically selected from either the
|
|
1291
|
-
[`~
|
|
1654
|
+
[`~EasyPipelineForInpainting.from_pretrained`], [`~EasyPipelineForInpainting.from_pipe`], [`~EasyPipelineForInpainting.from_huggingface`] or [`~EasyPipelineForInpainting.from_civitai`] methods.
|
|
1292
1655
|
|
|
1293
1656
|
This class cannot be instantiated using `__init__()` (throws an error).
|
|
1294
1657
|
|
|
@@ -1403,10 +1766,10 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
1403
1766
|
Examples:
|
|
1404
1767
|
|
|
1405
1768
|
```py
|
|
1406
|
-
>>> from
|
|
1769
|
+
>>> from auto_diffusers import EasyPipelineForInpainting
|
|
1407
1770
|
|
|
1408
|
-
>>> pipeline =
|
|
1409
|
-
>>> image = pipeline(prompt).images[0]
|
|
1771
|
+
>>> pipeline = EasyPipelineForInpainting.from_huggingface("stable-diffusion-2-inpainting")
|
|
1772
|
+
>>> image = pipeline(prompt, image=init_image, mask_image=mask_image).images[0]
|
|
1410
1773
|
```
|
|
1411
1774
|
"""
|
|
1412
1775
|
# Update kwargs to ensure the model is downloaded and parameters are included
|
|
@@ -1419,12 +1782,12 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
1419
1782
|
kwargs.update(_status)
|
|
1420
1783
|
|
|
1421
1784
|
# Search for the model on Hugging Face and get the model status
|
|
1422
|
-
|
|
1423
|
-
logger.warning(f"checkpoint_path: {
|
|
1424
|
-
checkpoint_path =
|
|
1785
|
+
hf_checkpoint_status = search_huggingface(pretrained_model_link_or_path, **kwargs)
|
|
1786
|
+
logger.warning(f"checkpoint_path: {hf_checkpoint_status.model_status.download_url}")
|
|
1787
|
+
checkpoint_path = hf_checkpoint_status.model_path
|
|
1425
1788
|
|
|
1426
1789
|
# Check the format of the model checkpoint
|
|
1427
|
-
if
|
|
1790
|
+
if hf_checkpoint_status.loading_method == "from_single_file":
|
|
1428
1791
|
# Load the pipeline from a single file checkpoint
|
|
1429
1792
|
return load_pipeline_from_single_file(
|
|
1430
1793
|
pretrained_model_or_path=checkpoint_path,
|
|
@@ -1511,10 +1874,10 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
1511
1874
|
Examples:
|
|
1512
1875
|
|
|
1513
1876
|
```py
|
|
1514
|
-
>>> from
|
|
1877
|
+
>>> from auto_diffusers import EasyPipelineForInpainting
|
|
1515
1878
|
|
|
1516
|
-
>>> pipeline =
|
|
1517
|
-
>>> image = pipeline(prompt).images[0]
|
|
1879
|
+
>>> pipeline = EasyPipelineForInpainting.from_huggingface("stable-diffusion-2-inpainting")
|
|
1880
|
+
>>> image = pipeline(prompt, image=init_image, mask_image=mask_image).images[0]
|
|
1518
1881
|
```
|
|
1519
1882
|
"""
|
|
1520
1883
|
# Update kwargs to ensure the model is downloaded and parameters are included
|
|
@@ -1527,9 +1890,9 @@ class EasyPipelineForInpainting(AutoPipelineForInpainting):
|
|
|
1527
1890
|
kwargs.update(_status)
|
|
1528
1891
|
|
|
1529
1892
|
# Search for the model on Civitai and get the model status
|
|
1530
|
-
|
|
1531
|
-
logger.warning(f"checkpoint_path: {
|
|
1532
|
-
checkpoint_path =
|
|
1893
|
+
checkpoint_status = search_civitai(pretrained_model_link_or_path, **kwargs)
|
|
1894
|
+
logger.warning(f"checkpoint_path: {checkpoint_status.model_status.site_url}")
|
|
1895
|
+
checkpoint_path = checkpoint_status.model_path
|
|
1533
1896
|
|
|
1534
1897
|
# Load the pipeline from a single file checkpoint
|
|
1535
1898
|
return load_pipeline_from_single_file(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: auto_diffusers
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.16
|
|
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
|
|
@@ -61,46 +61,26 @@ pip install --quiet auto_diffusers
|
|
|
61
61
|
from auto_diffusers import EasyPipelineForText2Image
|
|
62
62
|
|
|
63
63
|
# Search for Huggingface
|
|
64
|
-
pipe = EasyPipelineForText2Image.from_huggingface("
|
|
64
|
+
pipe = EasyPipelineForText2Image.from_huggingface("search_word").to("cuda")
|
|
65
65
|
img = pipe("cat").images[0]
|
|
66
66
|
img.save("cat.png")
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
# Search for Civitai
|
|
70
|
-
pipe = EasyPipelineForText2Image.from_civitai("
|
|
70
|
+
pipe = EasyPipelineForText2Image.from_civitai("search_word").to("cuda")
|
|
71
71
|
image = pipe("cat").images[0]
|
|
72
72
|
image.save("cat.png")
|
|
73
73
|
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
## Search Civitai and Huggingfacee<a name = "
|
|
76
|
+
## Search Civitai and Huggingfacee<a name = "Search_Civitai_and_Huggingface"></a>
|
|
77
77
|
|
|
78
78
|
```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
79
|
# Load Lora into the pipeline.
|
|
92
|
-
|
|
80
|
+
pipe.auto_load_lora_weights("Detail Tweaker")
|
|
93
81
|
|
|
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
82
|
# Load TextualInversion into the pipeline.
|
|
103
|
-
|
|
83
|
+
pipe.auto_load_textual_inversion("EasyNegative", token="EasyNegative")
|
|
104
84
|
```
|
|
105
85
|
|
|
106
86
|
### Search Civitai<a name = "Search_Civitai"></a>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
auto_diffusers/__init__.py,sha256=2VKCeWUc38yM2JVLhR9oqSQMC6513XEWPuBzk2pdRrM,204
|
|
2
|
+
auto_diffusers/pipeline_easy.py,sha256=guFGtEAw14muT1Js2CkM59Din3LC2V0Bwzb8IQcCGpw,92205
|
|
3
|
+
auto_diffusers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
auto_diffusers-2.0.16.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
+
auto_diffusers-2.0.16.dist-info/METADATA,sha256=nFnXEuJ5QMD-f2_kHxI5zb_-39l1EQWOeLooa21bzQo,9912
|
|
6
|
+
auto_diffusers-2.0.16.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
7
|
+
auto_diffusers-2.0.16.dist-info/top_level.txt,sha256=iYkbnc9T-VKVnoCP6AufdXcDUfUaLZ_yMG-USuYf4UQ,15
|
|
8
|
+
auto_diffusers-2.0.16.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
auto_diffusers/__init__.py,sha256=2VKCeWUc38yM2JVLhR9oqSQMC6513XEWPuBzk2pdRrM,204
|
|
2
|
-
auto_diffusers/pipeline_easy.py,sha256=YzPPPy-uoQLa10O6DDK52361e5nAkLLunJ_zg0CDnq0,74664
|
|
3
|
-
auto_diffusers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
auto_diffusers-2.0.14.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
-
auto_diffusers-2.0.14.dist-info/METADATA,sha256=4CltVO87O9PU_bQzfJkCKNYUmQhd_guPxhjP6VH1njA,10267
|
|
6
|
-
auto_diffusers-2.0.14.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
7
|
-
auto_diffusers-2.0.14.dist-info/top_level.txt,sha256=iYkbnc9T-VKVnoCP6AufdXcDUfUaLZ_yMG-USuYf4UQ,15
|
|
8
|
-
auto_diffusers-2.0.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|