mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
34e3aa1f88
author Kyle Schouviller <kyle0654@hotmail.com> 1669872800 -0800 committer Kyle Schouviller <kyle0654@hotmail.com> 1676240900 -0800 Adding base node architecture Fix type annotation errors Runs and generates, but breaks in saving session Fix default model value setting. Fix deprecation warning. Fixed node api Adding markdown docs Simplifying Generate construction in apps [nodes] A few minor changes (#2510) * Pin api-related requirements * Remove confusing extra CORS origins list * Adds response models for HTTP 200 [nodes] Adding graph_execution_state to soon replace session. Adding tests with pytest. Minor typing fixes [nodes] Fix some small output query hookups [node] Fixing some additional typing issues [nodes] Move and expand graph code. Add base item storage and sqlite implementation. Update startup to match new code [nodes] Add callbacks to item storage [nodes] Adding an InvocationContext object to use for invocations to provide easier extensibility [nodes] New execution model that handles iteration [nodes] Fixing the CLI [nodes] Adding a note to the CLI [nodes] Split processing thread into separate service [node] Add error message on node processing failure Removing old files and duplicated packages Adding python-multipart
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
|
|
|
|
from argparse import Namespace
|
|
import os
|
|
|
|
from ..services.processor import DefaultInvocationProcessor
|
|
|
|
from ..services.graph import GraphExecutionState
|
|
from ..services.sqlite import SqliteItemStorage
|
|
|
|
from ...globals import Globals
|
|
|
|
from ..services.image_storage import DiskImageStorage
|
|
from ..services.invocation_queue import MemoryInvocationQueue
|
|
from ..services.invocation_services import InvocationServices
|
|
from ..services.invoker import Invoker, InvokerServices
|
|
from ..services.generate_initializer import get_generate
|
|
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
|
|
|
|
@staticmethod
|
|
def initialize(
|
|
args,
|
|
config,
|
|
event_handler_id: int
|
|
):
|
|
Globals.try_patchmatch = args.patchmatch
|
|
Globals.always_use_cpu = args.always_use_cpu
|
|
Globals.internet_available = args.internet_available and check_internet()
|
|
Globals.disable_xformers = not args.xformers
|
|
Globals.ckpt_convert = args.ckpt_convert
|
|
|
|
# TODO: Use a logger
|
|
print(f'>> Internet connectivity is {Globals.internet_available}')
|
|
|
|
generate = get_generate(args, config)
|
|
|
|
events = FastAPIEventService(event_handler_id)
|
|
|
|
output_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../../outputs'))
|
|
|
|
images = DiskImageStorage(output_folder)
|
|
|
|
services = InvocationServices(
|
|
generate = generate,
|
|
events = events,
|
|
images = images
|
|
)
|
|
|
|
# TODO: build a file/path manager?
|
|
db_location = os.path.join(output_folder, 'invokeai.db')
|
|
|
|
invoker_services = InvokerServices(
|
|
queue = MemoryInvocationQueue(),
|
|
graph_execution_manager = SqliteItemStorage[GraphExecutionState](filename = db_location, table_name = 'graph_executions'),
|
|
processor = DefaultInvocationProcessor()
|
|
)
|
|
|
|
ApiDependencies.invoker = Invoker(services, invoker_services)
|
|
|
|
@staticmethod
|
|
def shutdown():
|
|
if ApiDependencies.invoker:
|
|
ApiDependencies.invoker.stop()
|