save and restore selected model on startup/exit

This commit is contained in:
Lincoln Stein
2023-03-28 10:39:19 -04:00
parent e3d992d5d7
commit f23cc54e1b
2 changed files with 25 additions and 2 deletions

View File

@@ -126,11 +126,13 @@ def main():
print(f"{e}. Aborting.")
sys.exit(-1)
model = retrieve_last_used_model() or opt.model
# creating a Generate object:
try:
gen = Generate(
conf=opt.conf,
model=opt.model,
model=model,
sampler_name=opt.sampler_name,
embedding_path=embedding_path,
full_precision=opt.full_precision,
@@ -179,6 +181,7 @@ def main():
# web server loops forever
if opt.web or opt.gui:
invoke_ai_web_server_loop(gen, gfpgan, codeformer, esrgan)
save_last_used_model(gen.model_name)
sys.exit(0)
if not infile:
@@ -499,6 +502,7 @@ def main_loop(gen, opt, completer):
print(
f'\nGoodbye!\nYou can start InvokeAI again by running the "invoke.bat" (or "invoke.sh") script from {Globals.root}'
)
save_last_used_model(gen.model_name)
# TO DO: remove repetitive code and the awkward command.replace() trope
@@ -1287,6 +1291,25 @@ def check_internet() -> bool:
except:
return False
def retrieve_last_used_model()->str:
"""
Return name of the last model used.
"""
model_file_path = Path(Globals.root,'.last_model')
if not model_file_path.exists():
return None
with open(model_file_path,'r') as f:
return f.readline()
def save_last_used_model(model_name:str):
"""
Save name of the last model used.
"""
model_file_path = Path(Globals.root,'.last_model')
with open(model_file_path,'w') as f:
f.write(model_name)
# This routine performs any patch-ups needed after installation
def run_patches():
install_missing_config_files()

View File

@@ -1,2 +1,2 @@
__version__='2.3.3-rc2'
__version__='2.3.3-rc4'