diff --git a/README.md b/README.md index 31f3100f..5d7a96d3 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,7 @@ Optionally, you can use the following command-line flags: | `--lora LORA` | Name of the LoRA to apply to the model by default. | | `--model-dir MODEL_DIR` | Path to directory with all the models. | | `--lora-dir LORA_DIR` | Path to directory with all the loras. | +| `--model-menu` | Show a model menu in the terminal when the web UI is first launched. | | `--no-stream` | Don't stream the text output in real time. | | `--settings SETTINGS_FILE` | Load the default interface settings from this json file. See `settings-template.json` for an example. If you create a file called `settings.json`, this file will be loaded by default without the need to use the `--settings` flag. | | `--extensions EXTENSIONS [EXTENSIONS ...]` | The list of extensions to load. If you want to load more than one extension, write the names separated by spaces. | diff --git a/modules/shared.py b/modules/shared.py index eb4035a2..429c076d 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -90,6 +90,7 @@ parser.add_argument('--model', type=str, help='Name of the model to load by defa parser.add_argument('--lora', type=str, help='Name of the LoRA to apply to the model by default.') parser.add_argument("--model-dir", type=str, default='models/', help="Path to directory with all the models") parser.add_argument("--lora-dir", type=str, default='loras/', help="Path to directory with all the loras") +parser.add_argument('--model-menu', action='store_true', help='Show a model menu in the terminal when the web UI is first launched.') parser.add_argument('--no-stream', action='store_true', help='Don\'t stream the text output in real time.') parser.add_argument('--settings', type=str, help='Load the default interface settings from this json file. See settings-template.json for an example. If you create a file called settings.json, this file will be loaded by default without the need to use the --settings flag.') parser.add_argument('--extensions', type=str, nargs="+", help='The list of extensions to load. If you want to load more than one extension, write the names separated by spaces.') diff --git a/server.py b/server.py index 680bcb35..004627e9 100644 --- a/server.py +++ b/server.py @@ -8,6 +8,7 @@ import json import math import os import re +import sys import time import traceback import zipfile @@ -453,8 +454,24 @@ else: if shared.args.model is not None: shared.model_name = shared.args.model shared.model, shared.tokenizer = load_model(shared.model_name) - if shared.args.lora: - add_lora_to_model(shared.args.lora) +elif shared.args.model_menu: + if len(available_models) == 0: + print('No models are available! Please download at least one.') + sys.exit(0) + elif len(available_models) == 1: + i = 0 + else: + print('The following models are available:\n') + for i, model in enumerate(available_models): + print(f'{i+1}. {model}') + print(f'\nWhich one do you want to load? 1-{len(available_models)}\n') + i = int(input()) - 1 + print() + shared.model_name = available_models[i] + shared.model, shared.tokenizer = load_model(shared.model_name) + +if shared.args.model is not None and shared.args.lora: + add_lora_to_model(shared.args.lora) # Default UI settings default_preset = shared.settings['presets'][next((k for k in shared.settings['presets'] if re.match(k.lower(), shared.model_name.lower())), 'default')]