ensure web server works with legacy runtime directory

This commit is contained in:
Lincoln Stein 2022-11-18 06:48:14 +00:00
parent 561721aef7
commit e9d319bfde
2 changed files with 10 additions and 4 deletions

View File

@ -20,11 +20,12 @@ from ldm.invoke.prompt_parser import split_weighted_subprompts
from backend.modules.parameters import parameters_to_command from backend.modules.parameters import parameters_to_command
# Loading Arguments # Loading Arguments
opt = Args() opt = Args()
args = opt.parse_args() args = opt.parse_args()
# Set the root directory for static files and relative paths
args.root_dir = os.path.expanduser(args.root_dir or '..')
if not os.path.isabs(args.outdir): if not os.path.isabs(args.outdir):
args.outdir=os.path.join(args.root_dir,args.outdir) args.outdir=os.path.join(args.root_dir,args.outdir)
@ -64,6 +65,7 @@ class InvokeAIWebServer:
if opt.cors: if opt.cors:
socketio_args["cors_allowed_origins"] = opt.cors socketio_args["cors_allowed_origins"] = opt.cors
print(f'DEBUG: static_folder should be at {os.path.join(args.root_dir,"frontend/dist")}')
self.app = Flask( self.app = Flask(
__name__, static_url_path="", static_folder=os.path.join(args.root_dir,"frontend/dist") __name__, static_url_path="", static_folder=os.path.join(args.root_dir,"frontend/dist")
) )

View File

@ -590,11 +590,13 @@ def get_root(root:str=None)->str:
with open(init_file, 'r') as infile: with open(init_file, 'r') as infile:
lines = infile.readlines() lines = infile.readlines()
for l in lines: for l in lines:
if re.search('\s*#',l): # ignore comments
continue
match = re.search('--root\s*=?\s*"?([^"]+)"?',l) match = re.search('--root\s*=?\s*"?([^"]+)"?',l)
if match: if match:
root = match.groups()[0] root = match.groups()[0]
root = root or '.'
return root.strip() or '.' return root.strip()
#------------------------------------- #-------------------------------------
def initialize_rootdir(root:str): def initialize_rootdir(root:str):
@ -675,7 +677,9 @@ def main():
try: try:
introduction() introduction()
# We check for this specific file, without which we are toast... # We check for two files to see if the runtime directory is correctly initialized.
# 1. a key stable diffusion config file
# 2. the web front end static files
if not os.path.exists(os.path.join(Globals.root,'configs/stable-diffusion/v1-inference.yaml')) \ if not os.path.exists(os.path.join(Globals.root,'configs/stable-diffusion/v1-inference.yaml')) \
or not os.path.exists(os.path.join(Globals.root,'frontend/dist')): or not os.path.exists(os.path.join(Globals.root,'frontend/dist')):
initialize_rootdir(Globals.root) initialize_rootdir(Globals.root)