install frontend/dist into package directory (#1554)

- When invokeai installed with `pip install .`, the frontend will be in
the venv directory under invokeai.
- When invokeai installed with `pip install -e .`, the frontend will be
in the source repo. -invoke_ai_web_sever.py will look in both places
using relative
  addressing.
This commit is contained in:
Lincoln Stein 2022-11-26 16:21:00 -05:00 committed by GitHub
commit a50f4da9d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 17 deletions

View File

@ -81,10 +81,9 @@ class InvokeAIWebServer:
if opt.cors:
socketio_args["cors_allowed_origins"] = opt.cors
frontend_path = self.find_frontend()
self.app = Flask(
__name__,
static_url_path="",
static_folder=os.path.join(args.root_dir, "frontend/dist"),
__name__, static_url_path="", static_folder=frontend_path
)
self.socketio = SocketIO(self.app, **socketio_args)
@ -242,6 +241,16 @@ class InvokeAIWebServer:
keyfile=args.keyfile,
)
def find_frontend(self):
my_dir = os.path.dirname(__file__)
for candidate in (os.path.join(my_dir,'..','frontend','dist'), # pip install -e .
os.path.join(my_dir,'../../../../frontend','dist') # pip install .
):
if os.path.exists(candidate):
return candidate
assert "Frontend files cannot be found. Cannot continue"
def setup_app(self):
self.result_url = "outputs/"
self.init_image_url = "outputs/init-images/"

View File

@ -592,7 +592,7 @@ def initialize_rootdir(root:str,yes_to_all:bool=False):
print(f'InvokeAI models and configuration files will be placed into {root} and image outputs will be placed into {outputs}.')
print(f'\nYou may change these values at any time by editing the --root and --output_dir options in "{Globals.initfile}",')
print(f'You may also change the runtime directory by setting the environment variable INVOKEAI_ROOT.\n')
for name in ('models','configs','scripts','frontend/dist'):
for name in ('models','configs'):
os.makedirs(os.path.join(root,name), exist_ok=True)
for src in ['configs']:
dest = os.path.join(root,src)

View File

@ -3,14 +3,8 @@ import re
from setuptools import setup, find_packages
def frontend_files(directory):
paths = []
for (path, _, filenames) in os.walk(directory):
for filename in filenames:
paths.append(os.path.join(path, filename))
return paths
def list_files(directory):
return [os.path.join(directory,x) for x in os.listdir(directory) if os.path.isfile(os.path.join(directory,x))]
def _get_requirements(path):
try:
@ -25,9 +19,6 @@ def _get_requirements(path):
return packages
frontend_files = frontend_files('frontend/dist')
print(f'DEBUG: {frontend_files}')
VERSION = '2.1.4'
DESCRIPTION = ('An implementation of Stable Diffusion which provides various new features'
' and options to aid the image generation process')
@ -72,6 +63,10 @@ setup(
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Scientific/Engineering :: Image Processing',
],
scripts = ['scripts/invoke.py','scripts/configure_invokeai.py', 'scripts/preload_models.py', 'scripts/sd-metadata.py'],
data_files=[('frontend',frontend_files)],
scripts = ['scripts/invoke.py','scripts/configure_invokeai.py', 'scripts/sd-metadata.py',
'scripts/preload_models.py', 'scripts/images2prompt.py','scripts/merge_embeddings.py'
],
data_files=[('frontend/dist',list_files('frontend/dist')),
('frontend/dist/assets',list_files('frontend/dist/assets'))
],
)