auto-diffusers 1.5.0__tar.gz → 1.6.0__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.
Files changed (39) hide show
  1. {auto_diffusers-1.5.0/src/auto_diffusers.egg-info → auto_diffusers-1.6.0}/PKG-INFO +1 -1
  2. auto_diffusers-1.6.0/Version.txt +1 -0
  3. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/model_path/perform_path_search.py +116 -114
  4. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/model_path/search_civitai.py +82 -38
  5. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/model_path/search_hugface.py +2 -3
  6. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/setup/base_config.py +0 -39
  7. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/setup/data_class.py +21 -1
  8. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0/src/auto_diffusers.egg-info}/PKG-INFO +1 -1
  9. auto_diffusers-1.5.0/Version.txt +0 -1
  10. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/LICENSE +0 -0
  11. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/MANIFEST.in +0 -0
  12. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/README.md +0 -0
  13. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/setup.cfg +0 -0
  14. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/setup.py +0 -0
  15. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/__init__.py +0 -0
  16. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/auto_pipe/__init__.py +0 -0
  17. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/auto_pipe/auto_pipe_cls.py +0 -0
  18. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/checker/__init__.py +0 -0
  19. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/checker/checkpoint_type.py +0 -0
  20. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/checker/get_checkpoint_type.py +0 -0
  21. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/checker/memorize_config.py +0 -0
  22. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/model_path/__init__.py +0 -0
  23. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/model_path/create_pipeline.py +0 -0
  24. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/model_path/flax_config.py +0 -0
  25. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/model_path/mix_class.py +0 -0
  26. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/py.typed +0 -0
  27. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/setup/__init__.py +0 -0
  28. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/setup/device_config.py +0 -0
  29. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/setup/runtime_config.py +0 -0
  30. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/utils/__init__.py +0 -0
  31. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/utils/device_config.py +0 -0
  32. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/utils/get_custom_logger.py +0 -0
  33. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/utils/hide_warning.py +0 -0
  34. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/utils/process_bar.py +0 -0
  35. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers/utils/run_download.py +0 -0
  36. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers.egg-info/SOURCES.txt +0 -0
  37. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers.egg-info/dependency_links.txt +0 -0
  38. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers.egg-info/requires.txt +0 -0
  39. {auto_diffusers-1.5.0 → auto_diffusers-1.6.0}/src/auto_diffusers.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: auto_diffusers
3
- Version: 1.5.0
3
+ Version: 1.6.0
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
@@ -0,0 +1 @@
1
+ 1.6.0
@@ -7,13 +7,6 @@ from .mix_class import Config_Mix
7
7
  class Search_cls(Config_Mix):
8
8
  def __init__(self):
9
9
  super().__init__()
10
- self.return_dict = {
11
- "search_word" : "",
12
- "url_or_path" : "",
13
- "load_type" : "",# "" or "from_single_file" or "from_pretrained"
14
- "single_file" : False,
15
- "local" : False,
16
- }
17
10
 
18
11
 
19
12
  def __call__(
@@ -26,7 +19,8 @@ class Search_cls(Config_Mix):
26
19
  branch = "main",
27
20
  priority = "hugface",
28
21
  local_file_only = False,
29
- return_path = True
22
+ return_path = True,
23
+ exclude_untested_model = False
30
24
  ):
31
25
  self.seach_word = seach_word
32
26
  self.auto = auto
@@ -36,16 +30,21 @@ class Search_cls(Config_Mix):
36
30
  self.local_file_only=local_file_only
37
31
  self.model_format =model_format
38
32
  self.return_path = return_path
33
+ self.exclude_untested_model = exclude_untested_model
34
+
35
+ self.return_dict["model_status"]["search_word"] = seach_word
36
+ self.return_dict["model_status"]["local"] = True if download or local_file_only else False
37
+
39
38
  result = self.model_set(
40
- model_select = self.seach_word,
41
- auto = self.auto,
42
- download = self.download,
43
- model_format=model_format,
44
- model_type = self.model_type,
45
- branch = self.branch,
39
+ model_select = seach_word,
40
+ auto = auto,
41
+ download = download,
42
+ model_format = model_format,
43
+ model_type = model_type,
44
+ branch = branch,
46
45
  priority = priority,
47
- local_file_only = self.local_file_only,
48
- return_path = self.return_path
46
+ local_file_only = local_file_only,
47
+ return_path = return_path
49
48
  )
50
49
  return result
51
50
 
@@ -86,6 +85,75 @@ class Search_cls(Config_Mix):
86
85
  search_list = paths
87
86
  )
88
87
  return search_path
88
+
89
+ def hf_model_set(
90
+ self,
91
+ model_select,
92
+ auto,
93
+ model_format,
94
+ model_type,
95
+ download
96
+ ):
97
+ model_path = ""
98
+ model_name = self.model_name_search(
99
+ model_name=model_select,
100
+ auto_set=auto,
101
+ model_format=model_format)
102
+ #hf->civit
103
+ if not model_name == "_hf_no_model":
104
+ file_path = self.file_name_set(
105
+ model_select=model_name,
106
+ auto=auto,
107
+ model_format=model_format,
108
+ model_type=model_type)
109
+ if file_path == "_DFmodel":
110
+ if download:
111
+ model_path = self.run_hf_download(model_name,branch=self.branch)
112
+ else:
113
+ model_path = model_name
114
+ self.return_dict["model_path"] = model_path
115
+ self.return_dict["model_status"]["single_file"] = False
116
+ self.return_dict["load_type"] = "from_pretrained"
117
+
118
+ else:
119
+ hf_model_path = f"https://huggingface.co/{model_name}/blob/{self.branch}/{file_path}"
120
+ if download:
121
+ model_path = self.run_hf_download(hf_model_path)
122
+ else:
123
+ model_path = hf_model_path
124
+ self.return_dict["model_status"]["single_file"] = True
125
+ self.return_dict["load_type"] = "from_single_file"
126
+ self.return_dict["model_status"]["filename"] = file_path
127
+
128
+ return model_path
129
+ else:
130
+ return "_hf_no_model"
131
+
132
+
133
+ def civitai_model_set(
134
+ self,
135
+ model_select,
136
+ auto,
137
+ model_type,
138
+ download,
139
+ skip_error=True
140
+ ):
141
+
142
+ model_path = self.civitai_download(
143
+ model_select,
144
+ auto,
145
+ model_type,
146
+ download=download)
147
+
148
+
149
+ self.return_dict["model_status"]["single_file"] = True
150
+ if (not skip_error) and (not model_path):
151
+ raise ValueError("No models were found in civitai.")
152
+ elif download:
153
+ self.return_dict["load_type"] = "from_single_file"
154
+ else:
155
+ self.return_dict["load_type"] = ""
156
+ return model_path
89
157
 
90
158
 
91
159
  def model_set(
@@ -115,13 +183,7 @@ class Search_cls(Config_Mix):
115
183
  if not model_format in ["all","diffusers","single_file"]:
116
184
  raise TypeError('The model_format is valid only for one of the following: "all","diffusers","single_file"')
117
185
 
118
- self.return_dict = {
119
- "search_word":model_select,
120
- "url_or_path":"",
121
- "load_type":"",# "" or "from_single_file" or "from_pretrained"
122
- "single_file":False,
123
- "local":True if download or local_file_only else False,
124
- }
186
+
125
187
 
126
188
  model_path = model_select
127
189
  file_path = ""
@@ -130,7 +192,7 @@ class Search_cls(Config_Mix):
130
192
  _check_url = f"https://huggingface.co/{model_path_to_check}"
131
193
  if self.is_url_valid(_check_url):
132
194
  model_select = model_path_to_check
133
- self.return_dict["url_or_path"] = _check_url
195
+ self.return_dict["model_path"] = _check_url
134
196
 
135
197
 
136
198
  if local_file_only:
@@ -138,8 +200,8 @@ class Search_cls(Config_Mix):
138
200
  search_word = model_select,
139
201
  auto = auto
140
202
  )
141
- self.return_dict["single_file"] = True
142
- self.return_dict["url_or_path"] = model_path
203
+ self.return_dict["model_status"]["single_file"] = True
204
+ self.return_dict["model_path"] = model_path
143
205
  self.return_dict["load_type"] = "from_single_file"
144
206
 
145
207
  elif model_select.startswith("https://huggingface.co/"):
@@ -151,14 +213,15 @@ class Search_cls(Config_Mix):
151
213
  else:
152
214
  model_path = model_select
153
215
 
154
- self.return_dict["single_file"] = True
155
- self.return_dict["url_or_path"] = model_path
216
+ self.return_dict["model_status"]["single_file"] = True
217
+ self.return_dict["model_path"] = model_path
156
218
  repo,file_name = self.repo_name_or_path(model_select)
157
219
  if file_name:
158
- self.return_dict["single_file"] = True
220
+ self.return_dict["model_status"]["filename"] = file_name
221
+ self.return_dict["model_status"]["single_file"] = True
159
222
  self.return_dict["load_type"] = "from_single_file"
160
223
  else:
161
- self.return_dict["single_file"] = False
224
+ self.return_dict["model_status"]["single_file"] = False
162
225
  self.return_dict["load_type"] = "from_pretrained"
163
226
 
164
227
 
@@ -167,35 +230,38 @@ class Search_cls(Config_Mix):
167
230
  model_select=model_select,
168
231
  auto=auto,
169
232
  model_type=model_type,
170
- download=download
233
+ download=download,
234
+ skip_error=False
171
235
  )
172
236
 
173
237
  elif os.path.isfile(model_select):
174
238
  model_path = model_select
175
- self.return_dict["url_or_path"] = model_select
176
- self.return_dict["single_file"] = True
239
+ self.return_dict["model_path"] = model_select
240
+ self.return_dict["model_status"]["single_file"] = True
177
241
  self.return_dict["load_type"] = "from_single_file"
178
- self.return_dict["local"] = True
242
+ self.return_dict["model_status"]["local"] = True
179
243
 
180
244
 
181
245
  elif os.path.isdir(model_select):
182
246
  if os.path.exists(os.path.join(model_select,self.Config_file)):
183
247
  model_path = model_select
184
- self.return_dict["url_or_path"] = model_select
185
- self.return_dict["single_file"] = False
248
+ self.return_dict["model_path"] = model_select
249
+ self.return_dict["model_status"]["single_file"] = False
186
250
  self.return_dict["load_type"] = "from_pretrained"
187
- self.return_dict["local"] = True
251
+ self.return_dict["model_status"]["local"] = True
188
252
  else:
189
253
  raise FileNotFoundError(f"model_index.json not found in {model_select}")
190
254
 
191
255
  elif model_select.count("/") == 1:
256
+ creator_name, repo_name = model_select.split("/")
257
+
192
258
  if auto and self.diffusers_model_check(model_select):
193
259
  if download:
194
260
  model_path = self.run_hf_download(model_select)
195
- self.return_dict["single_file"] = False
261
+ self.return_dict["model_status"]["single_file"] = False
196
262
  else:
197
263
  model_path = model_select
198
- self.return_dict["single_file"] = False
264
+ self.return_dict["model_status"]["single_file"] = False
199
265
  self.return_dict["load_type"] = "from_pretrained"
200
266
 
201
267
  elif auto and (not self.hf_model_check(model_select)):
@@ -210,8 +276,7 @@ class Search_cls(Config_Mix):
210
276
  else:
211
277
  model_path = model_select
212
278
 
213
- self.return_dict["url_or_path"] = model_path
214
- self.return_dict["single_file"] = False
279
+ self.return_dict["model_status"]["single_file"] = False
215
280
  self.return_dict["load_type"] = "from_pretrained"
216
281
 
217
282
  else:
@@ -221,10 +286,13 @@ class Search_cls(Config_Mix):
221
286
  model_path = self.run_hf_download(hf_model_path)
222
287
  else:
223
288
  model_path = hf_model_path
224
- self.return_dict["single_file"] = True
225
- self.return_dict["url_or_path"] = model_path
289
+
290
+ self.return_dict["model_status"]["filename"] = file_path
291
+ self.return_dict["model_status"]["single_file"] = True
226
292
  self.return_dict["load_type"] = "from_single_file"
227
-
293
+
294
+ self.return_dict["repo_status"]["repo_name"] = repo_name
295
+
228
296
  else:
229
297
  if priority == "hugface":
230
298
  model_path = self.hf_model_set(
@@ -241,7 +309,7 @@ class Search_cls(Config_Mix):
241
309
  model_type=model_type,
242
310
  download=download
243
311
  )
244
- if model_path == "_civitai_no_model":
312
+ if not model_path:
245
313
  raise ValueError("No models matching the criteria were found.")
246
314
 
247
315
  else:
@@ -251,7 +319,7 @@ class Search_cls(Config_Mix):
251
319
  model_type=model_type,
252
320
  download=download
253
321
  )
254
- if model_path == "_civitai_no_model":
322
+ if not model_path:
255
323
  model_path = self.hf_model_set(
256
324
  model_select = model_select,
257
325
  auto = auto,
@@ -262,76 +330,10 @@ class Search_cls(Config_Mix):
262
330
  if model_path == "_hf_no_model":
263
331
  raise ValueError("No models matching the criteria were found.")
264
332
 
333
+ self.return_dict["model_path"] = model_path
265
334
  #It is not called, but should not be deleted because it is updating the dictionary.
266
335
  update_model_path = self.check_func_hist(key="model_path",value=model_path)
267
336
  if return_path:
268
337
  return model_path
269
338
  else:
270
- return [model_path, self.return_dict]
271
-
272
-
273
- def hf_model_set(
274
- self,
275
- model_select,
276
- auto,
277
- model_format,
278
- model_type,
279
- download
280
- ):
281
- model_path = ""
282
- model_name = self.model_name_search(
283
- model_name=model_select,
284
- auto_set=auto,
285
- model_format=model_format)
286
- #hf->civit
287
- if not model_name == "_hf_no_model":
288
- file_path = self.file_name_set(
289
- model_select=model_name,
290
- auto=auto,
291
- model_format=model_format,
292
- model_type=model_type)
293
- if file_path == "_DFmodel":
294
- if download:
295
- model_path = self.run_hf_download(model_name,branch=self.branch)
296
- else:
297
- model_path = model_name
298
- self.return_dict["single_file"] = False
299
- self.return_dict["load_type"] = "from_pretrained"
300
-
301
- else:
302
- hf_model_path = f"https://huggingface.co/{model_name}/blob/{self.branch}/{file_path}"
303
- if download:
304
- model_path = self.run_hf_download(hf_model_path)
305
- else:
306
- model_path = hf_model_path
307
- self.return_dict["single_file"] = True
308
- self.return_dict["load_type"] = "from_single_file"
309
-
310
- return model_path
311
- else:
312
- return "_hf_no_model"
313
-
314
-
315
- def civitai_model_set(
316
- self,
317
- model_select,
318
- auto,
319
- model_type,
320
- download
321
- ):
322
-
323
- model_url, model_path = self.civitai_download(
324
- model_select,
325
- auto,
326
- model_type,
327
- download=download)
328
-
329
-
330
- self.return_dict["single_file"] = True
331
- self.return_dict["url_or_path"] = model_url
332
-
333
- if download:
334
- self.return_dict["load_type"] = "from_single_file"
335
- else:
336
- self.return_dict["load_type"] = ""
337
- return model_path
339
+ return self.return_dict
@@ -44,17 +44,12 @@ class Civitai(Basic_config):
44
44
 
45
45
  def __init__(self):
46
46
  super().__init__()
47
- self.path_dict = {
48
- "repo_id":"",
49
- "viersion_id":"",
50
- "filename":""
51
- }
52
47
  self.save_file_name = ""
53
48
 
54
49
 
55
50
  def civitai_download(
56
51
  self,
57
- seach_word,
52
+ search_word,
58
53
  auto,
59
54
  model_type,
60
55
  download=True):
@@ -62,7 +57,7 @@ class Civitai(Basic_config):
62
57
  Function to download models from civitai.
63
58
 
64
59
  Parameters:
65
- - seach_word(str): Search query string.
60
+ - search_word(str): Search query string.
66
61
  - auto(bool): Flag for automatic selection.
67
62
  - model_type(str): Type of model to search for.
68
63
  arg:[Checkpoint,
@@ -84,19 +79,26 @@ class Civitai(Basic_config):
84
79
  ---
85
80
  """
86
81
 
87
- model_url, save_path = self.requests_civitai(
88
- query=seach_word,
82
+ model_state_list = self.requests_civitai(
83
+ query=search_word,
89
84
  auto=auto,
90
85
  model_type=model_type)
91
- if model_url == "_civitai_no_model":
92
- return ("_civitai_no_model","_civitai_no_model")
93
- if download:
86
+ if not model_state_list:
87
+ return ""
88
+
89
+ model_url,model_save_path = model_state_list
90
+ if download:
94
91
  self.download_model(
95
92
  url=model_url,
96
- save_path=save_path)
97
- return (model_url, self.civitai_save_path())
93
+ save_path=model_save_path
94
+ )
95
+
96
+ result = model_save_path
98
97
  else:
99
- return (model_url, model_url)
98
+ result = model_url
99
+
100
+ self.return_dict["model_path"] = result
101
+ return result
100
102
 
101
103
 
102
104
  def download_model(self, url, save_path):
@@ -115,7 +117,7 @@ class Civitai(Basic_config):
115
117
  with tqdm.wrapattr(open(save_path, "wb"), "write",
116
118
  miniters=1, desc="Downloading model",
117
119
  total=int(response.headers.get('content-length', 0))) as fout:
118
- for chunk in response.iter_content(chunk_size=4096):
120
+ for chunk in response.iter_content(chunk_size=8192):
119
121
  fout.write(chunk)
120
122
  self.logger.info(f"Downloaded file saved to {save_path}")
121
123
 
@@ -133,12 +135,14 @@ class Civitai(Basic_config):
133
135
  - dict: Selected repository information.
134
136
  """
135
137
  if not state:
136
- #self.logger.warning("There is no model in Civitai that fits the criteria.")
137
- #return "_civitai_no_model"
138
- raise ValueError("state is empty")
139
-
140
- if auto:
141
- return max(state, key=lambda x: x['downloadCount'])
138
+ self.logger.warning("No models were found in civitai.")
139
+ return {}
140
+
141
+ elif auto:
142
+ repo_dict = max(state, key=lambda x: x['downloadCount'])
143
+ self.return_dict["repo_status"]["repo_name"] = repo_dict["repo_name"]
144
+ self.return_dict["repo_status"]["repo_id"] = repo_dict["repo_id"]
145
+ return repo_dict
142
146
  else:
143
147
  sorted_list = sorted(state, key=lambda x: x['downloadCount'], reverse=True)
144
148
  if recursive and self.max_number_of_choices < len(sorted_list):
@@ -152,6 +156,7 @@ class Civitai(Basic_config):
152
156
  print("\n\n\n")
153
157
 
154
158
  max_number = min(self.max_number_of_choices, len(sorted_list)) if recursive else len(sorted_list)
159
+ print(f"\033[34m0. Search for huggingface")
155
160
  for number, states_dict in enumerate(sorted_list[:max_number]):
156
161
  print(f"\033[34m{number + 1}. Repo_id: {states_dict['CreatorName']} / {states_dict['repo_name']}, download: {states_dict['downloadCount']}")
157
162
 
@@ -168,9 +173,13 @@ class Civitai(Basic_config):
168
173
 
169
174
  if Limit_choice and choice == max_number:
170
175
  return self.repo_select_civitai(state=state, auto=auto, recursive=False)
176
+ elif choice == 0:
177
+ return {}
171
178
  elif 1 <= choice <= max_number:
172
- self.path_dict["repo_id"] = sorted_list[choice - 1]["repo_id"]
173
- return sorted_list[choice - 1]
179
+ repo_dict = sorted_list[choice - 1]
180
+ self.return_dict["repo_status"]["repo_name"] = repo_dict["repo_name"]
181
+ self.return_dict["repo_status"]["repo_id"] = repo_dict["repo_id"]
182
+ return repo_dict
174
183
  else:
175
184
  print(f"\033[33mPlease enter the numbers 1~{max_number}\033[34m")
176
185
 
@@ -200,7 +209,7 @@ class Civitai(Basic_config):
200
209
  if auto:
201
210
  result = max(ver_list, key=lambda x: x['downloadCount'])
202
211
  ver_files_list = self.sort_by_version(result["files"])
203
- self.path_dict["version_id"] = result["id"]
212
+ self.return_dict["repo_status"]["version_id"] = result["id"]
204
213
  return ver_files_list
205
214
  else:
206
215
  if recursive:
@@ -231,7 +240,7 @@ class Civitai(Basic_config):
231
240
  return self.version_select_civitai(state=state, auto=auto, recursive=False)
232
241
  elif 1 <= choice <= max_number:
233
242
  return_dict = ver_list[choice - 1]
234
- self.path_dict["version_id"] = return_dict["id"]
243
+ self.return_dict["repo_status"]["version_id"] = return_dict["id"]
235
244
  return return_dict["files"]
236
245
  else:
237
246
  print(f"\033[33mPlease enter the numbers 1~{max_number}\033[34m")
@@ -248,6 +257,7 @@ class Civitai(Basic_config):
248
257
  Returns:
249
258
  - str: Download URL of the selected file.
250
259
  """
260
+
251
261
  if recursive and self.max_number_of_choices < len(state_list):
252
262
  Limit_choice = True
253
263
  else:
@@ -271,12 +281,15 @@ class Civitai(Basic_config):
271
281
  if Limit_choice and choice == max_number:
272
282
  return self.file_select_civitai(state_list=state_list, auto=auto, recursive=False)
273
283
  elif 1 <= choice <= len(state_list):
274
- self.path_dict["filename"] = state_list[choice - 1]["filename"]
275
- return state_list[choice - 1]
284
+ #self.return_dict.update(state_list[choice - 1])
285
+ file_dict = state_list[choice - 1]
286
+ self.return_dict["model_status"].update(file_dict)
287
+ return file_dict
276
288
  else:
277
289
  print(f"\033[33mPlease enter the numbers 1~{len(state_list)}\033[34m")
278
290
  else:
279
- self.path_dict["filename"] = state_list[0]["filename"]
291
+ file_dict = state_list[0]
292
+ self.return_dict["model_status"].update(file_dict)
280
293
  return state_list[0]
281
294
 
282
295
 
@@ -287,12 +300,35 @@ class Civitai(Basic_config):
287
300
  Returns:
288
301
  - str: Save path.
289
302
  """
290
- repo_level_dir = str(self.path_dict['repo_id'])
291
- file_version_dir = str(self.path_dict['version_id'])
292
- save_file_name = str(self.path_dict['filename'])
303
+ repo_level_dir = str(self.return_dict["repo_status"]["repo_id"])
304
+ file_version_dir = str(self.return_dict["repo_status"]["version_id"])
305
+ save_file_name = str(self.return_dict["model_status"]["filename"])
293
306
  save_path = os.path.join(self.base_civitai_dir, repo_level_dir, file_version_dir, save_file_name)
307
+ self.return_dict["model_path"] = save_path
294
308
  return save_path
309
+
295
310
 
311
+ def model_safety_check(self,value):
312
+ """
313
+ Note:
314
+ The virus scan and pickle scan are used to make the decision.
315
+ True is returned in case of Success,
316
+ and True is returned in case of Pending or Error only if exclude_untested_model is False.
317
+ """
318
+ check_list = [value["pickleScanResult"],value["virusScanResult"]]
319
+
320
+ if "Danger" in check_list:
321
+ return False
322
+
323
+ elif all(status == "Success" for status in check_list):
324
+ return True
325
+
326
+ else:
327
+ if self.exclude_untested_model:
328
+ return False
329
+ else:
330
+ return True
331
+
296
332
 
297
333
  def requests_civitai(self, query, auto, model_type):
298
334
  """
@@ -316,7 +352,6 @@ class Civitai(Basic_config):
316
352
  (url, save_path)
317
353
  """
318
354
  state = []
319
- repo_list = []
320
355
  model_ver_list = []
321
356
  version_dict = {}
322
357
 
@@ -339,10 +374,14 @@ class Civitai(Basic_config):
339
374
  for model_ver in item["modelVersions"]:
340
375
  files_list = []
341
376
  for model_value in model_ver["files"]:
342
- if any(check_word in model_value for check_word in ["downloadUrl", "name"]):
377
+ if (any(check_word in model_value for check_word in ["downloadUrl", "name"]) and
378
+ self.model_safety_check(model_value)
379
+ ):
343
380
  file_status = {
344
381
  "filename": model_value["name"],
345
382
  "file_id": model_value["id"],
383
+ "fp": model_value["metadata"]["fp"],
384
+ "file_format": model_value["metadata"]["format"],
346
385
  "download_url": model_value["downloadUrl"],
347
386
  }
348
387
  files_list.append(file_status)
@@ -372,15 +411,19 @@ class Civitai(Basic_config):
372
411
 
373
412
  if not state:
374
413
  self.logger.warning("There is no model in Civitai that fits the criteria.")
375
- return ("_civitai_no_model","_civitai_no_model")
414
+ return {}
376
415
  #raise ValueError("No matches found for your criteria")
377
416
 
378
- model_dict = self.repo_select_civitai(
417
+ dict_of_civitai_repo = self.repo_select_civitai(
379
418
  state = state,
380
419
  auto = auto
381
420
  )
421
+
422
+ if not dict_of_civitai_repo:
423
+ return []
424
+
382
425
  files_list = self.version_select_civitai(
383
- state = model_dict,
426
+ state = dict_of_civitai_repo,
384
427
  auto = auto
385
428
  )
386
429
 
@@ -389,5 +432,6 @@ class Civitai(Basic_config):
389
432
  auto = auto)
390
433
 
391
434
  save_path = self.civitai_save_path()
435
+
392
436
 
393
- return (file_status_dict["download_url"], save_path)
437
+ return [file_status_dict["download_url"],save_path]
@@ -50,7 +50,7 @@ class Huggingface(Basic_config):
50
50
  model_file_path = ""
51
51
  if any(url_or_path.startswith(checked) for checked in self.VALID_URL_PREFIXES):
52
52
  if not self.is_url_valid(url_or_path):
53
- raise HTTPError("Invalid URL")
53
+ raise HTTPError(f"Invalid URL: {url_or_path}")
54
54
  hf_path, file_name = self.repo_name_or_path(url_or_path)
55
55
  self.logger.debug(f"url_or_path:{url_or_path}")
56
56
  self.logger.debug(f"hf_path: {hf_path} \nfile_name: {file_name}")
@@ -71,8 +71,7 @@ class Huggingface(Basic_config):
71
71
  #single_file = False
72
72
  model_file_path = _hf_repo_download(url_or_path,branch=branch)
73
73
  else:
74
- self.logger.debug(f"url_or_path:{url_or_path}")
75
- raise TypeError("Invalid path_or_url")
74
+ raise TypeError(f"Invalid path_or_url: {url_or_path}")
76
75
  return model_file_path # type: ignore
77
76
 
78
77
 
@@ -95,19 +95,6 @@ class Basic_config(
95
95
  return class_type
96
96
 
97
97
 
98
- def key_check(self,keyword) -> bool:
99
- global key_dict
100
- if "key_dict" not in globals():
101
- key_dict = {}
102
- key = str(keyword)
103
- key_in = False
104
- if key in key_dict:
105
- if keyword == key_dict[key]:
106
- key_in = True
107
- key_dict[key] = keyword
108
- return key_in
109
-
110
-
111
98
  def get_call_method(
112
99
  self,
113
100
  class_name,
@@ -144,32 +131,6 @@ class Basic_config(
144
131
  return False
145
132
 
146
133
 
147
- def pipe_class_type(
148
- self,
149
- class_name
150
- ):
151
- """
152
- Args:
153
- class_name : class
154
-
155
- Returns:
156
- Literal['txt2img','img2img','txt2video']
157
- """
158
- _txt2img_method_list = [] #else
159
- _img2img_method_list = ["image"]
160
- _img2video_method_list = ["video_length","fps"]
161
-
162
- call_method = self.get_call_method(class_name,method_name = '__call__')
163
-
164
- if any(method in call_method for method in _img2video_method_list):
165
- pipeline_type = "txt2video"
166
- elif any(method in call_method for method in _img2img_method_list):
167
- pipeline_type = "img2img"
168
- else:
169
- pipeline_type = "txt2img"
170
- return pipeline_type
171
-
172
-
173
134
  def import_on_str(
174
135
  self,
175
136
  desired_function_or_class,
@@ -127,4 +127,24 @@ class data_config:
127
127
  ]
128
128
 
129
129
  def __init__(self):
130
- self.single_file_only = False
130
+ self.single_file_only = False
131
+ self.exclude_untested_model = True
132
+ self.return_dict = {
133
+ "model_path" : "",
134
+ "load_type" : "",# "" or "from_single_file" or "from_pretrained"
135
+ "repo_status":{
136
+ "repo_name":"",
137
+ "repo_id":"",
138
+ "version_id":""
139
+ },
140
+ "model_status":{
141
+ "search_word" : "",
142
+ "download_url": "",
143
+ "filename":"",
144
+ "file_id": "",
145
+ "fp": "",
146
+ "local" : False,
147
+ "single_file" : False
148
+ },
149
+ }
150
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: auto_diffusers
3
- Version: 1.5.0
3
+ Version: 1.6.0
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
@@ -1 +0,0 @@
1
- 1.5.0
File without changes
File without changes
File without changes
File without changes