Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[community] Load Models from Sources like Civitai into Existing Pipelines #9986

Merged
merged 38 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8924b57
Added example of model search.
suzukimain Nov 21, 2024
3e158b3
Combine processing into one file
suzukimain Nov 21, 2024
ca50857
Add parameters for base model
suzukimain Nov 21, 2024
28352b0
Bug Fixes
suzukimain Nov 21, 2024
76b32da
bug fix
suzukimain Nov 21, 2024
17e38b0
Create README.md
suzukimain Nov 21, 2024
aac8073
Update search_for_civitai_and_HF.py
suzukimain Nov 21, 2024
6c3c259
Create requirements.txt
suzukimain Nov 21, 2024
61aa2aa
Merge branch 'huggingface:main' into ModelSearch
suzukimain Nov 21, 2024
5202bb1
bug fix
suzukimain Nov 21, 2024
13a66bb
Update README.md
suzukimain Nov 21, 2024
920876d
bug fix
suzukimain Nov 21, 2024
d953d7f
Correction of typos
suzukimain Nov 21, 2024
36d34a6
Merge branch 'main' into ModelSearch
suzukimain Nov 22, 2024
4b02904
Update examples/model_search/README.md
suzukimain Dec 3, 2024
994fe95
Update examples/model_search/README.md
suzukimain Dec 3, 2024
65372d4
Update examples/model_search/README.md
suzukimain Dec 3, 2024
ab76aa4
Update examples/model_search/README.md
suzukimain Dec 3, 2024
341f3a3
Update examples/model_search/README.md
suzukimain Dec 3, 2024
05594cc
Update examples/model_search/README.md
suzukimain Dec 3, 2024
241c943
apply the changes
suzukimain Dec 4, 2024
43d936a
Replace search_for_civitai_and_HF.py with pipeline_easy.py
suzukimain Dec 4, 2024
745d4d0
Merge branch 'main' into ModelSearch
suzukimain Dec 4, 2024
4f3d4b0
Update examples/model_search/README.md
suzukimain Dec 4, 2024
8b2e3e6
Update examples/model_search/README.md
suzukimain Dec 4, 2024
2e32020
Update examples/model_search/README.md
suzukimain Dec 4, 2024
68000fa
Update README.md
suzukimain Dec 4, 2024
cd70647
Organize the table of parameters
suzukimain Dec 4, 2024
c9e87b8
Update README.md
suzukimain Dec 4, 2024
b10a55a
Update README.md
suzukimain Dec 4, 2024
c3e51e6
Merge branch 'main' into ModelSearch
suzukimain Dec 4, 2024
026202c
Update README.md
suzukimain Dec 5, 2024
ac1c3e1
Merge branch 'huggingface:main' into ModelSearch
suzukimain Dec 6, 2024
efe5fba
make style
suzukimain Dec 6, 2024
5df8f99
Fixing the style of pipeline
suzukimain Dec 6, 2024
4ff6e38
Fix pipeline style
suzukimain Dec 6, 2024
5e92b8e
fix
suzukimain Dec 6, 2024
54fd90e
Merge branch 'main' into ModelSearch
suzukimain Dec 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions examples/model_search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Search models on Civitai and Hugging Face

The [auto_diffusers](https://github.com/suzukimain/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](https://pypi.org/project/auto-diffusers/)

## 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 .
suzukimain marked this conversation as resolved.
Show resolved Hide resolved
```bash
!wget https://raw.githubusercontent.com/suzukimain/auto_diffusers/refs/heads/master/src/auto_diffusers/pipeline_easy.py
```

### Search for Civitai
suzukimain marked this conversation as resolved.
Show resolved Hide resolved
```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")
```

### Search for Hugging Face
suzukimain marked this conversation as resolved.
Show resolved Hide resolved
```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")
```


### Application Examples
suzukimain marked this conversation as resolved.
Show resolved Hide resolved
suzukimain marked this conversation as resolved.
Show resolved Hide resolved

```python
from pipeline_easy import (
search_huggingface,
search_civitai,
)

# Search Lora
Lora = search_civitai(
"Keyword_to_search_Lora",
model_type="LORA",
base_model = "SD 1.5",
download=True,
)
# Load Lora into the pipeline.
pipeline.load_lora_weights(Lora)


# Search TextualInversion
TextualInversion = search_civitai(
"EasyNegative",
model_type="TextualInversion",
base_model = "SD 1.5",
download=True
)
# Load TextualInversion into the pipeline.
pipeline.load_textual_inversion(TextualInversion, token="EasyNegative")
```

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

### `EasyPipeline.from_civitai` parameters

| Name | Type | Default | Description |
|:---------------:|:----------------------:|:-------------:|:-----------------------------------------------------------------------------------:|
| search_word | string, Path | ー | The search query string. Can be a keyword, Civitai URL, local directory or file path. |
| model_type | string | `Checkpoint` | The type of model to search for. <br>(for example `Checkpoint`, `TextualInversion`, `Controlnet`, `LORA`, `Hypernetwork`, `AestheticGradient`, `Poses`) |
| base_model | string | None | Trained model tag (for example `SD 1.5`, `SD 3.5`, `SDXL 1.0`) |
| torch_dtype | string, torch.dtype | None | Override the default `torch.dtype` and load the model with another dtype. |
| force_download | bool | False | Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. |
| cache_dir | string, Path | None | Path to the folder where cached files are stored. |
| resume | bool | False | Whether to resume an incomplete download. |
| token | string | None | API token for Civitai authentication. |
suzukimain marked this conversation as resolved.
Show resolved Hide resolved


### `search_civitai` parameters
suzukimain marked this conversation as resolved.
Show resolved Hide resolved

| Name | Type | Default | Description |
|:---------------:|:--------------:|:-------------:|:-----------------------------------------------------------------------------------:|
| search_word | string, Path | ー | The search query string. Can be a keyword, Civitai URL, local directory or file path. |
| model_type | string | `Checkpoint` | The type of model to search for. <br>(for example `Checkpoint`, `TextualInversion`, `Controlnet`, `LORA`, `Hypernetwork`, `AestheticGradient`, `Poses`) |
| base_model | string | None | Trained model tag (for example `SD 1.5`, `SD 3.5`, `SDXL 1.0`) |
| download | bool | False | Whether to download the model. |
| force_download | bool | False | Whether to force the download if the model already exists. |
| cache_dir | string, Path | None | Path to the folder where cached files are stored. |
| resume | bool | False | Whether to resume an incomplete download. |
| token | string | None | API token for Civitai authentication. |
| include_params | bool | False | Whether to include parameters in the returned data. |
| skip_error | bool | False | Whether to skip errors and return None. |


### `EasyPipeline.from_huggingface` parameters

| Name | Type | Default | Description |
|:---------------------:|:-------------------:|:--------------:|:----------------------------------------------------------------:|
| search_word | string, Path | ー | The search query string. Can be a keyword, Hugging Face URL, local directory or file path, or a Hugging Face path (`<creator>/<repo>`). |
| checkpoint_format | string | `single_file` | The format of the model checkpoint.<br>● `single_file` to search for `single file checkpoint` <br>●`diffusers` to search for `multifolder diffusers format checkpoint` |
| torch_dtype | string, torch.dtype | None | Override the default `torch.dtype` and load the model with another dtype. |
| force_download | bool | False | Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. |
| cache_dir | string, Path | None | Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used. |
| token | string, bool | None | The token to use as HTTP bearer authorization for remote files. |
suzukimain marked this conversation as resolved.
Show resolved Hide resolved


### `search_huggingface` parameters
suzukimain marked this conversation as resolved.
Show resolved Hide resolved

| Name | Type | Default | Description |
|:---------------------:|:-------------------:|:--------------:|:----------------------------------------------------------------:|
| search_word | string, Path | ー | The search query string. Can be a keyword, Hugging Face URL, local directory or file path, or a Hugging Face path (`<creator>/<repo>`). |
| checkpoint_format | string | `single_file` | The format of the model checkpoint. <br>● `single_file` to search for `single file checkpoint` <br>●`diffusers` to search for `multifolder diffusers format checkpoint` |
| pipeline_tag | string | None | Tag to filter models by pipeline. |
| download | bool | False | Whether to download the model. |
| force_download | bool | False | Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. |
| cache_dir | string, Path | None | Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used. |
| token | string, bool | None | The token to use as HTTP bearer authorization for remote files. |
| include_params | bool | False | Whether to include parameters in the returned data. |
| skip_error | bool | False | Whether to skip errors and return None. |
Loading