mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-15 20:35:26 -05:00
This commit makes InvokeAI 3.0 to be installable via PyPi.org and the installer script. Main changes. 1. Move static web pages into `invokeai/frontend/web` and modify the API to look for them there. This allows pip to copy the files into the distribution directory so that user no longer has to be in repo root to launch. 2. Update invoke.sh and invoke.bat to launch the new web application properly. This also changes the wording for launching the CLI from "generate images" to "explore the InvokeAI node system," since I would not recommend using the CLI to generate images routinely. 3. Fix a bug in the checkpoint converter script that was identified during testing. 4. Better error reporting when checkpoint converter fails. 5. Rebuild front end.
87 lines
2.9 KiB
Python
87 lines
2.9 KiB
Python
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
|
|
|
|
import os
|
|
|
|
import invokeai.backend.util.logging as logger
|
|
from typing import types
|
|
|
|
from ..services.default_graphs import create_system_graphs
|
|
from ..services.latent_storage import DiskLatentsStorage, ForwardCacheLatentsStorage
|
|
from ..services.model_manager_initializer import get_model_manager
|
|
from ..services.restoration_services import RestorationServices
|
|
from ..services.graph import GraphExecutionState, LibraryGraph
|
|
from ..services.image_storage import DiskImageStorage
|
|
from ..services.invocation_queue import MemoryInvocationQueue
|
|
from ..services.invocation_services import InvocationServices
|
|
from ..services.invoker import Invoker
|
|
from ..services.processor import DefaultInvocationProcessor
|
|
from ..services.sqlite import SqliteItemStorage
|
|
from ..services.metadata import PngMetadataService
|
|
from .events import FastAPIEventService
|
|
|
|
|
|
# TODO: is there a better way to achieve this?
|
|
def check_internet() -> bool:
|
|
"""
|
|
Return true if the internet is reachable.
|
|
It does this by pinging huggingface.co.
|
|
"""
|
|
import urllib.request
|
|
|
|
host = "http://huggingface.co"
|
|
try:
|
|
urllib.request.urlopen(host, timeout=1)
|
|
return True
|
|
except:
|
|
return False
|
|
|
|
|
|
class ApiDependencies:
|
|
"""Contains and initializes all dependencies for the API"""
|
|
|
|
invoker: Invoker = None
|
|
|
|
def initialize(config, event_handler_id: int, logger: types.ModuleType=logger):
|
|
logger.info(f"Internet connectivity is {config.internet_available}")
|
|
|
|
events = FastAPIEventService(event_handler_id)
|
|
|
|
output_folder = config.output_path
|
|
|
|
latents = ForwardCacheLatentsStorage(DiskLatentsStorage(f'{output_folder}/latents'))
|
|
|
|
metadata = PngMetadataService()
|
|
|
|
images = DiskImageStorage(f'{output_folder}/images', metadata_service=metadata)
|
|
|
|
# TODO: build a file/path manager?
|
|
db_location = os.path.join(output_folder, "invokeai.db")
|
|
|
|
services = InvocationServices(
|
|
model_manager=get_model_manager(config,logger),
|
|
events=events,
|
|
latents=latents,
|
|
images=images,
|
|
metadata=metadata,
|
|
queue=MemoryInvocationQueue(),
|
|
graph_library=SqliteItemStorage[LibraryGraph](
|
|
filename=db_location, table_name="graphs"
|
|
),
|
|
graph_execution_manager=SqliteItemStorage[GraphExecutionState](
|
|
filename=db_location, table_name="graph_executions"
|
|
),
|
|
processor=DefaultInvocationProcessor(),
|
|
restoration=RestorationServices(config,logger),
|
|
configuration=config,
|
|
logger=logger,
|
|
)
|
|
|
|
create_system_graphs(services.graph_library)
|
|
|
|
ApiDependencies.invoker = Invoker(services)
|
|
|
|
@staticmethod
|
|
def shutdown():
|
|
if ApiDependencies.invoker:
|
|
ApiDependencies.invoker.stop()
|