auto-diffusers 2.0.7__py3-none-any.whl → 2.0.13__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.
@@ -24,14 +24,13 @@ from dataclasses import (
24
24
  asdict
25
25
  )
26
26
 
27
-
27
+ from huggingface_hub.file_download import http_get
28
28
  from huggingface_hub.utils import validate_hf_hub_args
29
29
  from huggingface_hub import (
30
30
  hf_api,
31
31
  hf_hub_download,
32
32
  )
33
33
 
34
-
35
34
  from diffusers.utils import logging
36
35
  from diffusers.loaders.single_file_utils import (
37
36
  infer_diffusers_model_type,
@@ -351,6 +350,73 @@ def get_keyword_types(keyword):
351
350
  return status
352
351
 
353
352
 
353
+ def file_downloader(
354
+ url,
355
+ save_path,
356
+ **kwargs,
357
+ ) -> None:
358
+ """
359
+ Downloads a file from a given URL and saves it to the specified path.
360
+
361
+ parameters:
362
+ url (`str`):
363
+ The URL of the file to download.
364
+ save_path (`str`):
365
+ The local path where the file will be saved.
366
+ resume (`bool`, *optional*, defaults to `False`):
367
+ Whether to resume an incomplete download.
368
+ headers (`dict`, *optional*, defaults to `None`):
369
+ Dictionary of HTTP Headers to send with the request.
370
+ proxies (`dict`, *optional*, defaults to `None`):
371
+ Dictionary mapping protocol to the URL of the proxy passed to `requests.request`.
372
+ force_download (`bool`, *optional*, defaults to `False`):
373
+ Whether to force the download even if the file already exists.
374
+ displayed_filename (`str`, *optional*):
375
+ The filename of the file that is being downloaded. Value is used only to display a nice progress bar. If
376
+ not set, the filename is guessed from the URL or the `Content-Disposition` header.
377
+
378
+ returns:
379
+ None
380
+ """
381
+
382
+ # Get optional parameters from kwargs, with their default values
383
+ resume = kwargs.pop("resume", False)
384
+ headers = kwargs.pop("headers", None)
385
+ proxies = kwargs.pop("proxies", None)
386
+ force_download = kwargs.pop("force_download", False)
387
+ displayed_filename = kwargs.pop("displayed_filename", None)
388
+ # Default mode for file writing and initial file size
389
+ mode = "wb"
390
+ file_size = 0
391
+
392
+ # Create directory
393
+ os.makedirs(os.path.dirname(save_path), exist_ok=True)
394
+
395
+ # Check if the file already exists at the save path
396
+ if os.path.exists(save_path):
397
+ if not force_download:
398
+ # If the file exists and force_download is False, skip the download
399
+ logger.warning(f"File already exists: {save_path}, skipping download.")
400
+ return None
401
+ elif resume:
402
+ # If resuming, set mode to append binary and get current file size
403
+ mode = "ab"
404
+ file_size = os.path.getsize(save_path)
405
+
406
+ # Open the file in the appropriate mode (write or append)
407
+ with open(save_path, mode) as model_file:
408
+ # Call the http_get function to perform the file download
409
+ return http_get(
410
+ url=url,
411
+ temp_file=model_file,
412
+ resume_size=file_size,
413
+ displayed_filename=displayed_filename,
414
+ headers=headers,
415
+ proxies=proxies,
416
+ **kwargs,
417
+ )
418
+
419
+
354
420
  def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, None]:
355
421
  r"""
356
422
  Downloads a model from Hugging Face.
@@ -488,7 +554,7 @@ def search_huggingface(search_word: str, **kwargs) -> Union[str, SearchResult, N
488
554
  if diffusers_model_exists:
489
555
  if download:
490
556
  model_path = DiffusionPipeline.download(
491
- repo_id=repo_id,
557
+ repo_id,
492
558
  token=token,
493
559
  **kwargs,
494
560
  )
@@ -671,48 +737,35 @@ def search_civitai(search_word: str, **kwargs) -> Union[str, SearchResult, None]
671
737
  else:
672
738
  continue
673
739
  break
674
-
740
+
741
+ # Exception handling when search candidates are not found
675
742
  if not selected_model:
676
743
  if skip_error:
677
744
  return None
678
745
  else:
679
746
  raise ValueError("No model found. Please try changing the word you are searching for.")
680
-
747
+
748
+ # Define model file status
681
749
  file_name = selected_model["filename"]
682
750
  download_url = selected_model["download_url"]
683
751
 
684
752
  # Handle file download and setting model information
685
753
  if download:
754
+ # The path where the model is to be saved.
686
755
  model_path = os.path.join(
687
756
  str(civitai_cache_dir), str(repo_id), str(version_id), str(file_name)
688
757
  )
689
- os.makedirs(os.path.dirname(model_path), exist_ok=True)
690
- if (not os.path.exists(model_path)) or force_download:
691
- headers = {}
692
- if token:
693
- headers["Authorization"] = f"Bearer {token}"
694
-
695
- mode = "wb"
696
- if resume and os.path.exists(model_path):
697
- mode = "ab"
698
- file_size = os.path.getsize(model_path)
699
- headers["Range"] = f"bytes={file_size}-"
700
-
701
- try:
702
- response = requests.get(download_url, stream=True, headers=headers)
703
- response.raise_for_status()
704
- except requests.HTTPError:
705
- raise requests.HTTPError(f"Invalid URL: {download_url}, {response.status_code}")
706
-
707
- with tqdm.wrapattr(
708
- open(model_path, "wb"),
709
- "write",
710
- miniters=1,
711
- desc=file_name,
712
- total=int(response.headers.get("content-length", 0)) + (file_size if resume and os.path.exists(model_path) else 0),
713
- ) as fetched_model_info:
714
- for chunk in response.iter_content(chunk_size=8192):
715
- fetched_model_info.write(chunk)
758
+ # Download Model File
759
+ file_downloader(
760
+ url=download_url,
761
+ save_path=model_path,
762
+ resume=resume,
763
+ force_download=force_download,
764
+ displayed_filename=file_name,
765
+ headers=headers,
766
+ **kwargs,
767
+ )
768
+
716
769
  else:
717
770
  model_path = download_url
718
771
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: auto_diffusers
3
- Version: 2.0.7
3
+ Version: 2.0.13
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
@@ -20,6 +20,7 @@ Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
21
  Description-Content-Type: text/markdown
22
22
  License-File: LICENSE
23
+ Requires-Dist: torch
23
24
  Requires-Dist: diffusers
24
25
  Requires-Dist: huggingface-hub>=0.26.2
25
26
 
@@ -0,0 +1,8 @@
1
+ auto_diffusers/__init__.py,sha256=2VKCeWUc38yM2JVLhR9oqSQMC6513XEWPuBzk2pdRrM,204
2
+ auto_diffusers/pipeline_easy.py,sha256=9lDZYxp74BVuHryhitJcPG3zHAUpNYxVyyzMsnZoJ0Q,75262
3
+ auto_diffusers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ auto_diffusers-2.0.13.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
+ auto_diffusers-2.0.13.dist-info/METADATA,sha256=xRrieSi7ocd5uwUfknwfBCeM9eod4GUU6xsPLcmOuzw,12695
6
+ auto_diffusers-2.0.13.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
7
+ auto_diffusers-2.0.13.dist-info/top_level.txt,sha256=iYkbnc9T-VKVnoCP6AufdXcDUfUaLZ_yMG-USuYf4UQ,15
8
+ auto_diffusers-2.0.13.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- auto_diffusers/__init__.py,sha256=2VKCeWUc38yM2JVLhR9oqSQMC6513XEWPuBzk2pdRrM,204
2
- auto_diffusers/pipeline_easy.py,sha256=qGFIjTSZ9xZBtuO5hxPsPiq4ZFFvQT9A5QvsMZXoDZ0,73403
3
- auto_diffusers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- auto_diffusers-2.0.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
- auto_diffusers-2.0.7.dist-info/METADATA,sha256=Y3HIzjbga0cAsR0RnQNp2r-u1XvdBv7iDCqDoHduu_w,12673
6
- auto_diffusers-2.0.7.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
7
- auto_diffusers-2.0.7.dist-info/top_level.txt,sha256=iYkbnc9T-VKVnoCP6AufdXcDUfUaLZ_yMG-USuYf4UQ,15
8
- auto_diffusers-2.0.7.dist-info/RECORD,,