install frontend/dist into package directory

- 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-25 06:42:00 +00:00
parent b23c471cf0
commit d079445943
3 changed files with 21 additions and 14 deletions

View File

@ -65,8 +65,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)
@ -129,6 +130,16 @@ class InvokeAIWebServer:
print(f">> Point your browser at http://{self.host}:{self.port}")
self.socketio.run(app=self.app, host=self.host, port=self.port)
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,13 +3,8 @@ import re
from setuptools import setup, find_packages
def frontend_files(directory):
paths = []
for (path, directories, 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:
@ -24,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')
@ -70,7 +62,11 @@ setup(
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Scientific/Engineering :: Image Processing',
],
scripts = ['scripts/invoke.py','scripts/configure_invokeai.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'))
],
)