Back to Diffusers

Search models on Civitai and Hugging Face

examples/model_search/README.md

0.37.18.8 KB
Original Source

Search models on Civitai and Hugging Face

The auto_diffusers library provides additional functionalities to Diffusers such as searching for models on Civitai and the Hugging Face Hub. Please refer to the original library here

Installation

Before running the scripts, make sure to install the library's training dependencies:

[!IMPORTANT] To make sure you can successfully run the latest versions of the example scripts, we highly recommend installing from source and keeping the installation up to date as we update the example scripts frequently and install some example-specific requirements. To do this, execute the following steps in a new virtual environment.

bash
git clone https://github.com/huggingface/diffusers
cd diffusers
pip install .

Set up the pipeline. You can also cd to this folder and run it.

bash
!wget https://raw.githubusercontent.com/suzukimain/auto_diffusers/refs/heads/master/src/auto_diffusers/pipeline_easy.py

Load from Civitai

python
from pipeline_easy import (
    EasyPipelineForText2Image,
    EasyPipelineForImage2Image,
    EasyPipelineForInpainting,
)

# Text-to-Image
pipeline = EasyPipelineForText2Image.from_civitai(
    "search_word",
    base_model="SD 1.5",
).to("cuda")


# Image-to-Image
pipeline = EasyPipelineForImage2Image.from_civitai(
    "search_word",
    base_model="SD 1.5",
).to("cuda")


# Inpainting
pipeline = EasyPipelineForInpainting.from_civitai(
    "search_word",
    base_model="SD 1.5",
).to("cuda")

Load from Hugging Face

python
from pipeline_easy import (
    EasyPipelineForText2Image,
    EasyPipelineForImage2Image,
    EasyPipelineForInpainting,
)

# Text-to-Image
pipeline = EasyPipelineForText2Image.from_huggingface(
    "search_word",
    checkpoint_format="diffusers",
).to("cuda")


# Image-to-Image
pipeline = EasyPipelineForImage2Image.from_huggingface(
    "search_word",
    checkpoint_format="diffusers",
).to("cuda")


# Inpainting
pipeline = EasyPipelineForInpainting.from_huggingface(
    "search_word",
    checkpoint_format="diffusers",
).to("cuda")

Search Civitai and Huggingface

python
# Load Lora into the pipeline.
pipeline.auto_load_lora_weights("Detail Tweaker")

# Load TextualInversion into the pipeline.
pipeline.auto_load_textual_inversion("EasyNegative", token="EasyNegative")

Search Civitai

[!TIP] If an error occurs, insert the token and run again.

EasyPipeline.from_civitai parameters

NameTypeDefaultDescription
search_wordstring, PathThe search query string. Can be a keyword, Civitai URL, local directory or file path.
model_typestringCheckpointThe type of model to search for.
(for example Checkpoint, TextualInversion, Controlnet, LORA, Hypernetwork, AestheticGradient, Poses)
base_modelstringNoneTrained model tag (for example SD 1.5, SD 3.5, SDXL 1.0)
torch_dtypestring, torch.dtypeNoneOverride the default torch.dtype and load the model with another dtype.
force_downloadboolFalseWhether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
cache_dirstring, PathNonePath to the folder where cached files are stored.
resumeboolFalseWhether to resume an incomplete download.
tokenstringNoneAPI token for Civitai authentication.

search_civitai parameters

NameTypeDefaultDescription
search_wordstring, PathThe search query string. Can be a keyword, Civitai URL, local directory or file path.
model_typestringCheckpointThe type of model to search for.
(for example Checkpoint, TextualInversion, Controlnet, LORA, Hypernetwork, AestheticGradient, Poses)
base_modelstringNoneTrained model tag (for example SD 1.5, SD 3.5, SDXL 1.0)
downloadboolFalseWhether to download the model.
force_downloadboolFalseWhether to force the download if the model already exists.
cache_dirstring, PathNonePath to the folder where cached files are stored.
resumeboolFalseWhether to resume an incomplete download.
tokenstringNoneAPI token for Civitai authentication.
include_paramsboolFalseWhether to include parameters in the returned data.
skip_errorboolFalseWhether to skip errors and return None.

Search Huggingface

[!TIP] If an error occurs, insert the token and run again.

EasyPipeline.from_huggingface parameters

NameTypeDefaultDescription
search_wordstring, PathThe search query string. Can be a keyword, Hugging Face URL, local directory or file path, or a Hugging Face path (<creator>/<repo>).
checkpoint_formatstringsingle_fileThe format of the model checkpoint.
single_file to search for single file checkpoint
diffusers to search for multifolder diffusers format checkpoint
torch_dtypestring, torch.dtypeNoneOverride the default torch.dtype and load the model with another dtype.
force_downloadboolFalseWhether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
cache_dirstring, PathNonePath to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used.
tokenstring, boolNoneThe token to use as HTTP bearer authorization for remote files.

search_huggingface parameters

NameTypeDefaultDescription
search_wordstring, PathThe search query string. Can be a keyword, Hugging Face URL, local directory or file path, or a Hugging Face path (<creator>/<repo>).
checkpoint_formatstringsingle_fileThe format of the model checkpoint.
single_file to search for single file checkpoint
diffusers to search for multifolder diffusers format checkpoint
pipeline_tagstringNoneTag to filter models by pipeline.
downloadboolFalseWhether to download the model.
force_downloadboolFalseWhether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
cache_dirstring, PathNonePath to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used.
tokenstring, boolNoneThe token to use as HTTP bearer authorization for remote files.
include_paramsboolFalseWhether to include parameters in the returned data.
skip_errorboolFalseWhether to skip errors and return None.