Skip to content

Commit

Permalink
add lycoris support
Browse files Browse the repository at this point in the history
  • Loading branch information
stdkoehler committed May 3, 2023
1 parent d0e83e7 commit 5c6c0d6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions civitai/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ def get_lora_dir():
if not lora_dir: lora_dir = shared.cmd_opts.lora_dir
return lora_dir

def get_lyco_dir():
try:
lyco_dir = shared.opts.data.get('civitai_folder_lyco', shared.cmd_opts.lyco_dir).strip()
if not lyco_dir: lyco_dir = shared.cmd_opts.lyco_dir
return lyco_dir
except:
print("LyCORIS not installed")
return None


def get_automatic_type(type: str):
if type == 'Hypernetwork': return 'hypernet'
return type.lower()
Expand Down Expand Up @@ -186,21 +196,26 @@ def get_resources_in_folder(type, folder, exts=[], exts_exclude=[]):
return resources

resources = []
def load_resource_list(types=['LORA', 'LoCon', 'Hypernetwork', 'TextualInversion', 'Checkpoint', 'VAE', 'Controlnet']):
def load_resource_list(types=['LORA', 'LoCon', 'LyCORIS', 'Hypernetwork', 'TextualInversion', 'Checkpoint', 'VAE', 'Controlnet']):
global resources

# If resources is empty and types is empty, load all types
# This is a helper to be able to get the resource list without
# having to worry about initialization. On subsequent calls, no work will be done
if len(resources) == 0 and len(types) == 0:
types = ['LORA', 'LoCon', 'Hypernetwork', 'TextualInversion', 'Checkpoint', 'VAE', 'Controlnet']
types = ['LORA', 'LoCon', 'LyCORIS', 'Hypernetwork', 'TextualInversion', 'Checkpoint', 'VAE', 'Controlnet']

if 'LORA' in types:
resources = [r for r in resources if r['type'] != 'LORA']
resources += get_resources_in_folder('LORA', get_lora_dir(), ['pt', 'safetensors', 'ckpt'])
if 'LoCon' in types:
resources = [r for r in resources if r['type'] != 'LoCon']
resources += get_resources_in_folder('LoCon', get_lora_dir(), ['pt', 'safetensors', 'ckpt'])
if 'LyCORIS' in types:
resources = [r for r in resources if r['type'] != 'LyCORIS']
lyco_dir = get_lyco_dir()
if lyco_dir is not None:
resources += get_resources_in_folder('LyCORIS', get_lyco_dir(), ['pt', 'safetensors', 'ckpt'])
if 'Hypernetwork' in types:
resources = [r for r in resources if r['type'] != 'Hypernetwork']
resources += get_resources_in_folder('Hypernetwork', shared.cmd_opts.hypernetwork_dir, ['pt', 'safetensors', 'ckpt'])
Expand Down
2 changes: 1 addition & 1 deletion scripts/previews.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from modules import script_callbacks, shared

previewable_types = ['LORA', 'Hypernetwork', 'TextualInversion', 'Checkpoint']
previewable_types = ['LORA', 'LyCORIS', 'Hypernetwork', 'TextualInversion', 'Checkpoint']
def load_previews():
download_missing_previews = shared.opts.data.get('civitai_download_previews', True)
if not download_missing_previews: return
Expand Down
1 change: 1 addition & 0 deletions scripts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def on_ui_settings():
shared.opts.add_option("civitai_download_missing_models", shared.OptionInfo(True, "Download missing models upon reading generation parameters from prompt", section=section))
shared.opts.add_option("civitai_hashify_resources", shared.OptionInfo(True, "Include resource hashes in image metadata (for resource auto-detection on Civitai)", section=section))
shared.opts.add_option("civitai_folder_lora", shared.OptionInfo("", "LoRA directory (if not default)", section=section))
shared.opts.add_option("civitai_folder_lyco", shared.OptionInfo("", "LyCo directory (if not default)", section=section))


script_callbacks.on_ui_settings(on_ui_settings)

0 comments on commit 5c6c0d6

Please sign in to comment.