mirror of
https://github.com/invoke-ai/InvokeAI
synced 2026-04-04 22:15:08 +02:00
* Implements rudimentary api * Fixes blocking in API * Adds UI to monorepo > src/frontend/ * Updates frontend/README * Reverts conda env name to `ldm` * Fixes environment yamls * CORS config for testing * Fixes LogViewer position * API WID * Adds actions to image viewer * Increases vite chunkSizeWarningLimit to 1500 * Implements init image * Implements state persistence in localStorage * Improve progress data handling * Final build * Fixes mimetypes error on windows * Adds error logging * Fixes bugged img2img strength component * Adds sourcemaps to dev build * Fixes missing key * Changes connection status indicator to text * Adds ability to serve other hosts than localhost * Adding Flask API server * Removes source maps from config * Fixes prop transfer * Add missing packages and add CORS support * Adding API doc * Remove defaults from openapi doc * Adds basic error handling for server config query * Mostly working socket.io implementation. * Fixes bug preventing mask upload * Fixes bug with sampler name not written to metadata * UI Overhaul, numerous fixes Co-authored-by: Kyle Schouviller <kyle0654@hotmail.com> Co-authored-by: Lincoln Stein <lincoln.stein@gmail.com>
100 lines
3.1 KiB
Python
100 lines
3.1 KiB
Python
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
|
|
|
|
"""Views module."""
|
|
import json
|
|
import os
|
|
from queue import Queue
|
|
from flask import current_app, jsonify, request, Response, send_from_directory, stream_with_context, url_for
|
|
from flask.views import MethodView
|
|
from dependency_injector.wiring import inject, Provide
|
|
|
|
from server.models import DreamRequest
|
|
from server.services import GeneratorService, ImageStorageService, JobQueueService
|
|
from server.containers import Container
|
|
|
|
class ApiJobs(MethodView):
|
|
|
|
@inject
|
|
def post(self, job_queue_service: JobQueueService = Provide[Container.generation_queue_service]):
|
|
dreamRequest = DreamRequest.from_json(request.json, newTime = True)
|
|
|
|
#self.canceled.clear()
|
|
print(f">> Request to generate with prompt: {dreamRequest.prompt}")
|
|
|
|
q = Queue()
|
|
|
|
dreamRequest.start_callback = None
|
|
dreamRequest.image_callback = None
|
|
dreamRequest.progress_callback = None
|
|
dreamRequest.cancelled_callback = None
|
|
dreamRequest.done_callback = None
|
|
|
|
# Push the request
|
|
job_queue_service.push(dreamRequest)
|
|
|
|
return { 'dreamId': dreamRequest.id() }
|
|
|
|
|
|
class WebIndex(MethodView):
|
|
init_every_request = False
|
|
__file: str = None
|
|
|
|
def __init__(self, file):
|
|
self.__file = file
|
|
|
|
def get(self):
|
|
return current_app.send_static_file(self.__file)
|
|
|
|
|
|
class WebConfig(MethodView):
|
|
init_every_request = False
|
|
|
|
def get(self):
|
|
# unfortunately this import can't be at the top level, since that would cause a circular import
|
|
from ldm.gfpgan.gfpgan_tools import gfpgan_model_exists
|
|
config = {
|
|
'gfpgan_model_exists': gfpgan_model_exists
|
|
}
|
|
js = f"let config = {json.dumps(config)};\n"
|
|
return Response(js, mimetype="application/javascript")
|
|
|
|
|
|
class ApiCancel(MethodView):
|
|
init_every_request = False
|
|
|
|
@inject
|
|
def get(self, generator_service: GeneratorService = Provide[Container.generator_service]):
|
|
generator_service.cancel()
|
|
return Response(status=204)
|
|
|
|
|
|
class ApiImages(MethodView):
|
|
init_every_request = False
|
|
__pathRoot = None
|
|
__storage: ImageStorageService
|
|
|
|
@inject
|
|
def __init__(self, pathBase, storage: ImageStorageService = Provide[Container.image_storage_service]):
|
|
self.__pathRoot = os.path.abspath(os.path.join(os.path.dirname(__file__), pathBase))
|
|
self.__storage = storage
|
|
|
|
def get(self, dreamId):
|
|
name = self.__storage.path(dreamId)
|
|
fullpath=os.path.join(self.__pathRoot, name)
|
|
return send_from_directory(os.path.dirname(fullpath), os.path.basename(fullpath))
|
|
|
|
class ApiIntermediates(MethodView):
|
|
init_every_request = False
|
|
__pathRoot = None
|
|
__storage: ImageStorageService = Provide[Container.image_intermediates_storage_service]
|
|
|
|
@inject
|
|
def __init__(self, pathBase, storage: ImageStorageService = Provide[Container.image_intermediates_storage_service]):
|
|
self.__pathRoot = os.path.abspath(os.path.join(os.path.dirname(__file__), pathBase))
|
|
self.__storage = storage
|
|
|
|
def get(self, dreamId, step):
|
|
name = self.__storage.path(dreamId, postfix=f'.{step}')
|
|
fullpath=os.path.join(self.__pathRoot, name)
|
|
return send_from_directory(os.path.dirname(fullpath), os.path.basename(fullpath))
|