Skip to content

Commit

Permalink
Merge pull request #78 from kohya-ss/dev
Browse files Browse the repository at this point in the history
merge dev to main
  • Loading branch information
kohya-ss authored Jan 30, 2023
2 parents eb26730 + fe653ba commit 2d0bcdb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ __Stable Diffusion web UI now seems to support LoRA trained by ``sd-scripts``.__

Note: Currently the models models for SD 2.x does not seem to be supported in Web UI. The models trained by the scripts 0.4.0 seem to be supported.

- 30 Jan. 2023, 2023/1/30
- Fix to allow folder names containing commas in ``Extra paths to scan for LoRA models``. Enclose in ``"``. Thanks to shirayu!
- ``Extra paths to scan for LoRA models`` でのモデルディレクトリの指定時にカンマを含むフォルダ名が使用できるようになりました。``"`` で囲んでください。shirayu氏に感謝します。
- 29 Jan. 2023, 2023/1/29
- Support multiple LoRA model directories. You can set a comma-separated list in ``Extra paths to scan for LoRA models`` at ``Settings`` tab. Thanks to space-nuko!

Expand Down
2 changes: 1 addition & 1 deletion preload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


def preload(parser):
parser.add_argument("--addnet-max-model-count", type=int, help="The maximum number of additinal network model can be used.", default=5)
parser.add_argument("--addnet-max-model-count", type=int, help="The maximum number of additional network model can be used.", default=5)
17 changes: 14 additions & 3 deletions scripts/additional_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ def apply_weight_tenc(p, x, xs, i):
update_script_args(p, True, 0)
update_script_args(p, x, 5 + 4 * i) # enabled, separate_weights, (module, model, weight_unet, {weight_tenc}), ...

def split_path_list(path_list: str) -> list[str]:
import csv
from io import StringIO

pl = []
with StringIO() as f:
f.write(path_list)
f.seek(0)
for r in csv.reader(f):
pl += r
return pl

def format_lora_model(p, opt, x):
model = find_closest_lora_model_name(x)
Expand All @@ -169,7 +180,7 @@ def format_lora_model(p, opt, x):
if not metadata:
return value

metadata_names = shared.opts.data.get("additional_networks_xy_grid_model_metadata", "").split(",")
metadata_names = split_path_list(shared.opts.data.get("additional_networks_xy_grid_model_metadata", ""))
if not metadata_names:
return value

Expand Down Expand Up @@ -384,7 +395,7 @@ def find_closest_lora_model_name(search: str):
def update_lora_models():
global lora_models, lora_model_names, legacy_model_names
paths = [lora_models_dir]
extra_lora_paths = shared.opts.data.get("additional_networks_extra_lora_path", "").split(",")
extra_lora_paths = split_path_list(shared.opts.data.get("additional_networks_extra_lora_path", ""))
for path in extra_lora_paths:
if os.path.isdir(path):
paths.append(path)
Expand Down Expand Up @@ -637,7 +648,7 @@ def update_metadata(module, model):
def on_ui_settings():
section = ('additional_networks', "Additional Networks")
shared.opts.add_option("additional_networks_extra_lora_path", shared.OptionInfo(
"", "Extra paths to scan for LoRA models, comma-separated", section=section))
"", """Extra paths to scan for LoRA models, comma-separated. Paths containing commas must be enclosed in double quotes. In the path, " (one quote) must be replaced by "" (two quotes).""", section=section))
shared.opts.add_option("additional_networks_sort_models_by", shared.OptionInfo(
"name", "Sort LoRA models by", gr.Radio, {"choices": ["name", "date", "path name", "rating", "has user metadata"]}, section=section))
shared.opts.add_option("additional_networks_model_name_filter", shared.OptionInfo("", "LoRA model name filter", section=section))
Expand Down

0 comments on commit 2d0bcdb

Please sign in to comment.