zixaphir / Stable-Diffusion-Webui-Civitai-Helper

Stable Diffusion Webui Extension for Civitai, to manage your model much more easily.
175 stars 24 forks source link

Contributors

Language

中文(ChatGPT) 日本語(ChatGPT) 한국어(ChatGPT)

About Civitai Helper

This extension provides the ability to download models and model metadata from Civitai. Data such as activation keywords, model description, version information, and model previews for models hosted on Civitai can be at your fingertips without having to navigate away from stable diffusion webui.

About This Version of Civitai Helper

This is my personal version of Stable-Diffusion-Webui-Civitai-Helper. I started it entirely because the version I was using broke when SD-webui v1.5 came out and I needed it to work. Since then, I have added functionality that I wanted and have made best-effort attempts to maintain compatibility with older versions of sd-webui, but I do not use older versions and therefore do not test on older versions.

I intend to keep this working for as long as I am able, but this is simply a hobby project and I am nowhere near as skilled as other extension developers with more experience. I am likely to dip out for long periods at a time, possibly forever if I lose interest. I am prone to errors and bugs are to be expected.

If a more interested part decides to pick up development, I will happily cede control of this project and attempt to push my changes to their projects if they are wanted.

Civitai Helper

Stable Diffusion Webui Extension for Civitai, to handle your models much more easily.

Civitai: Civitai Url

Features

Install

Go to SD webui's extension tab, go to Install from url sub-tab. Copy this project's url into it, click install.

Alternatively, download this project as a zip file, and unzip it to Your SD webui folder/extensions.

Everytime you install or update this extension, you need to shutdown SD Webui and Relaunch it. Just "Reload UI" won't work for this extension.

Some functionality from Civitai, like downloading models, requires having an account and adding your API key. See this Wiki Article for more information.

Done.

Branches

Development of this extension happens in three development branches:

Update Your SD Webui

This extension need to get extra network's cards id. Which is added since 2023-02-06. If your SD webui is an earlier version, you need to update it!

Some of the following information may not up-to-date. Most functionality should be the same or similar, but many changes post-v1.6 have not been documented as of yet. Images may not match 1:1 with the current state of the extension.

Scanning Models

Go to extension tab "Civitai Helper". There is a button called "Scan model".

Click it and the extension will scan all your models to generate SHA256 hashes, using them to retreive model information and preview images from Civitai.

Scanning takes time, just wait until it finish

For each model, it will create two files to save all model info from Civitai. These model info files will be [model_name].civitai.info and [model_name].json in your model folder.

If a model info file already exists, by default it will be skipped. If a model cannot be found in Civitai, a minimal model info file will be created with any information that can be extracted from the model. By default, a model with model pre-existing model info files will not be scanned.

Adding New Models

When you want to grab some new models, you can either download them to the appropriate directory yourself or you can use the built-in model downloader. If you use the Model Downloader, the model information and preview will also be downloaded, along providing the option to download other files, like the model config or VAE.

If you just want to download the models into the appropriate directories yourself, you can simply run a scan again to get new model's information and preview images, although other files like the model config or VAE may be missing. Only new models will be scanned with default options.

Update Image Generation Information

In the same place you can scan a model, you can also scan the model info and the extension will attempt to fill in any missing information from the images themselves. This is a very hit-or-miss process, but if you are trying to get the prompt from an image the "preview image prompt" button and it fails to work, performing this scan may retrieve the information necessary to fix it.

Model Card

The following section is outdated!

The following text block and image only applies to Stable Diffution Webui versions before v1.5.0. While the added buttons are still up-to-date, the "Extra Networks" tab button has been removed and is now always active by default.


(Use this only after scanning finished) Open SD webui's build-in "Extra Network" tab, to show model cards.

Move your mouse on to the bottom of a model card. It will show 4 icon buttons:

Webui Metadata Editor

As of v1.7.0, this extension also downloads data for Webui's Metadata Editor by default. This data includes information you'd previously have to read unruly JSON files or navigate to Civitai to read.

This data can be accessed by clicking the metadata button on the model card.

Download

To download a model by Civitai Model Page's Url, you need 3 steps:

Detail will be displayed on console log, with a progress bar. Downloading can be resumed on failure, so no fear of having to restart large files.

Checking Model's New Version

You can checking your local model's new version from civitai by model types. You can select multiple model types.

The checking process has a small delay after each model's new version checking request. So it is a little slow.

This is to protect Civitai from issue like DDos from this extension. There is no good for us if it is down.

After checking process done, it will display all new version's information on UI.

There are 3 urls for each new version.

Get Model Info By Url

This is used to force a local model links to a Civitai model. For example, you converted a model's format or pruned it. Then it can not be found on civitai when scanning.

In that case, if you still want to link it to a civitai model. You can use this funcion.

Choose this model from list, then offer a civitai model page's url.

After clicking button, extension will download that civitai model's info and preview image for the local file you picked.

Preview Image

Extra networks use both model_file.png and model_file.preview.png as preview image. But model_file.png has higher priority, because it is created by yourself.

When you don't have the higher priority one, it will use the other automatically. SD WebUI also supports other filetypes for previews but .png files will always have priority over every other filetype. For instance, model_file.jpg will supercede model_file.preview.jpg but not model_file.preview.png.

Prompt

When you click the button "Use prompt from preview image", it does not use the prompt from your own preview image. It uses the one from civitai's preview image.

On civitai, a model's preview images may not has prompt. This extension will check this model's all civitai preview images' information and use the first one has prompt in it.

SHA256

To create a file SHA256, it need to read the whole file to generate a hash code. It gonna be slow for large files.

Also, extension uses Memory Optimized SHA256, which won't stuck your system and works with colab.

There are 2 cases this hash code can not find the model on civitai:

In these cases, you can always link a model to civitai by filling its URL in this extension.

Settings

While many options are provided in the Civitai Helper's extension tab, a dedicated settings section can be found in WebUI's Setting's tab. Here you will find a variety of options that are either not available in the Civitai Helper tab or that can be set here so that they do not reset when you reload the page. For example, you can hide buttons added by the extension that you do not use, enable always showing buttons to make functionality more touch-screen friendly, or choose to download the highest resolution versions of preview images available.

The next couple sections explain some of the more advanced option.

API Key

Some models on Civitai require you to be logged in to download them. Unfortunately, it is not currently possible to just enter in your login information with this extension, but with an API Key, you will still be able to download these models. For information on how to generate an API Key for your Civitai account, please see our wiki.

Proxy

You may set a proxy for the extension to use and then all requests to civitai will use the proxy.

For some sock5 proxies, you may need to enter it in the form "socks5h://xxxxx".

Choosing a Hashing function

For the longest time, this extension used its own code for performing Hashng, or fingerprinting, of model files. While this worked fine, and was quite good, this implementation had a finicky history with colabs and lacked some useful features like saving generated hashes so that future scans wouldn't need to re-hash the file. While the old implementation is still available through this setting, currently the default setting is to simply let WebUI handle that functionality and benefit from the exceptional development happening over there.

Lycoris Models

By default, models known as "Lycoris" are saved to their own directory, but you can also choose to instead download them to the Lora directory instead. For most end-user purposes, LyCoris models are functionally the same as Loras, so this may be benefical if you simply want everything in one place. However, some extensions previously required LyCoris models to have their own directory, so the default will continue to be to keep them in separate directories for compatibility reasons.

Other Setting

Feature Request

Feel free to submit feature requests, but pull requests are preferred.

Enjoy!

Pull Requests

All pull requests should target the dev branch. For those who take a stab at the code, I apologize for the lack of consistency in coding style, naming, and other syntactical oddities. At some point, I intend to clean up the code and have everything pass linting, but we're not there yet.

Common Issue

Buttons on card didn't show

Localization

There was a Localization issue if you are not using English version of SD webui. This is fixed in the latest version of this extension. Bilingual localization extension is supported by PR since v1.6.1.1.

Using cloud based localization extension

Turn off cloud based localization extension, use normal localization extension.

Other case

First of all, make sure you clicked "Refresh Civitai Helper" button.

If issue is still there, then only reason is you are not using the latest SD webui. So, Make sure you updated it.

Your update could be failed if you have modified SD webui's file. You need to check git command's console log to make sure it is updated.

In many cases, git will just refuse to update and tell you there are some conflicts need you to handle manually. If you don't check the consloe log, you will think your SD webui is updated, but it is not.

Request, Scan or Get model info failed

Usually the reason for this most likely is the connection to Civitai API service failed. This can be for a number of reasons.

Sometimes Civitai can be down or refuse your API connection. Civitai has a connection pool setting. Basicly, it's a max connection number that civitai can have at the same time. So if there are already too manny connections on civitai, it will refuse your API connection.

In those cases, the only thing you can do is just wait a while then try again. I suggest making a cup of tea!

Get Wrong model info and preview images from civitai

A bad news is, some models are saved with a wrong sha256 in civitai's database. Check here for more detail: https://github.com/civitai/civitai/issues/426

So, for those models, this extension can not get the right model info or preview images.

In this case, you have to remove the model info file and get the right model info by a civitai url on this extension's tab page.

Also, you can report those models with wrong sha256 to civitai at following page: https://discord.com/channels/1037799583784370196/1096271712959615100/1096271712959615100

Please report that model to civitai, so they can fix it.

Scanning fail when using colab

First of, search your error message with google. Most likely, it will be a colab issue.

If you are sure it is a out of memory issue when scanning models, and you are using this extension's latest version, then there is nothing we can do.

Since v1.5.5, we've already optimized the SHA256 function to the top. So the only 2 choices for you are:

Changes