allow users to choose path of models (#446)

* allow users to choose path of models

* allow users to choose path of models

* allow users to choose path of models

* allow users to choose path of models

* allow users to choose path of models
This commit is contained in:
lllyasviel 2023-09-19 19:02:02 -07:00 committed by GitHub
parent 098d08cd22
commit b89192162d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 9 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ __pycache__
lena.png
lena_result.png
lena_test.py
user_path_config.txt
/modules/*.png
/repositories
/venv

View File

@ -1 +1 @@
version = '2.0.71'
version = '2.0.72'

View File

@ -1,16 +1,46 @@
import os
import json
from modules.model_loader import load_file_from_url
modelfile_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../models/checkpoints/'))
lorafile_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../models/loras/'))
vae_approx_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../models/vae_approx/'))
upscale_models_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../models/upscale_models/'))
inpaint_models_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../models/inpaint/'))
temp_outputs_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../outputs/'))
config_path = "user_path_config.txt"
config_dict = {}
try:
if os.path.exists(config_path):
with open(config_path, "r", encoding="utf-8") as json_file:
config_dict = json.load(json_file)
except Exception as e:
print('Load path config failed')
print(e)
def get_config_or_set_default(key, default):
global config_dict
v = config_dict.get(key, None)
if isinstance(v, str) and os.path.exists(v) and os.path.isdir(v):
return v
else:
dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default))
os.makedirs(dp, exist_ok=True)
config_dict[key] = dp
return dp
modelfile_path = get_config_or_set_default('modelfile_path', '../models/checkpoints/')
lorafile_path = get_config_or_set_default('lorafile_path', '../models/loras/')
vae_approx_path = get_config_or_set_default('vae_approx_path', '../models/vae_approx/')
upscale_models_path = get_config_or_set_default('upscale_models_path', '../models/upscale_models/')
inpaint_models_path = get_config_or_set_default('inpaint_models_path', '../models/inpaint/')
fooocus_expansion_path = get_config_or_set_default('fooocus_expansion_path',
'../models/prompt_expansion/fooocus_expansion')
temp_outputs_path = get_config_or_set_default('temp_outputs_path', '../outputs/')
with open(config_path, "w", encoding="utf-8") as json_file:
json.dump(config_dict, json_file, indent=4)
fooocus_expansion_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
'../models/prompt_expansion/fooocus_expansion'))
os.makedirs(temp_outputs_path, exist_ok=True)

View File

@ -1,3 +1,7 @@
### 2.0.72
* Allow users to choose path of models.
### 2.0.65
* Inpaint model released.