mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Merge branch 'main' into dev/docker/separate-req-inst
This commit is contained in:
commit
243f9e8377
@ -7,13 +7,15 @@ import mimetypes
|
||||
import os
|
||||
import shutil
|
||||
import traceback
|
||||
from pathlib import Path
|
||||
from threading import Event
|
||||
from uuid import uuid4
|
||||
|
||||
import eventlet
|
||||
from pathlib import Path
|
||||
import invokeai.frontend.dist as frontend
|
||||
from PIL import Image
|
||||
from PIL.Image import Image as ImageType
|
||||
from compel.prompt_parser import Blend
|
||||
from flask import Flask, redirect, send_from_directory, request, make_response
|
||||
from flask_socketio import SocketIO
|
||||
from werkzeug.utils import secure_filename
|
||||
@ -22,18 +24,15 @@ from invokeai.backend.modules.get_canvas_generation_mode import (
|
||||
get_canvas_generation_mode,
|
||||
)
|
||||
from invokeai.backend.modules.parameters import parameters_to_command
|
||||
import invokeai.frontend.dist as frontend
|
||||
from ldm.generate import Generate
|
||||
from ldm.invoke.args import Args, APP_ID, APP_VERSION, calculate_init_img_hash
|
||||
from ldm.invoke.conditioning import get_tokens_for_prompt_object, get_prompt_structure, split_weighted_subprompts, \
|
||||
get_tokenizer
|
||||
from ldm.invoke.conditioning import get_tokens_for_prompt_object, get_prompt_structure, get_tokenizer
|
||||
from ldm.invoke.generator.diffusers_pipeline import PipelineIntermediateState
|
||||
from ldm.invoke.generator.inpaint import infill_methods
|
||||
from ldm.invoke.globals import Globals, global_converted_ckpts_dir
|
||||
from ldm.invoke.pngwriter import PngWriter, retrieve_metadata
|
||||
from compel.prompt_parser import Blend
|
||||
from ldm.invoke.globals import global_models_dir
|
||||
from ldm.invoke.merge_diffusers import merge_diffusion_models
|
||||
from ldm.invoke.pngwriter import PngWriter, retrieve_metadata
|
||||
|
||||
# Loading Arguments
|
||||
opt = Args()
|
||||
@ -1063,7 +1062,7 @@ class InvokeAIWebServer:
|
||||
(width, height) = image.size
|
||||
width *= 8
|
||||
height *= 8
|
||||
img_base64 = image_to_dataURL(image)
|
||||
img_base64 = image_to_dataURL(image, image_format="JPEG")
|
||||
self.socketio.emit(
|
||||
"intermediateResult",
|
||||
{
|
||||
@ -1685,27 +1684,23 @@ class CanceledException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
Returns a copy an image, cropped to a bounding box.
|
||||
"""
|
||||
|
||||
|
||||
def copy_image_from_bounding_box(
|
||||
image: ImageType, x: int, y: int, width: int, height: int
|
||||
) -> ImageType:
|
||||
"""
|
||||
Returns a copy an image, cropped to a bounding box.
|
||||
"""
|
||||
with image as im:
|
||||
bounds = (x, y, x + width, y + height)
|
||||
im_cropped = im.crop(bounds)
|
||||
return im_cropped
|
||||
|
||||
|
||||
"""
|
||||
Converts a base64 image dataURL into an image.
|
||||
The dataURL is split on the first commma.
|
||||
"""
|
||||
|
||||
|
||||
def dataURL_to_image(dataURL: str) -> ImageType:
|
||||
"""
|
||||
Converts a base64 image dataURL into an image.
|
||||
The dataURL is split on the first comma.
|
||||
"""
|
||||
image = Image.open(
|
||||
io.BytesIO(
|
||||
base64.decodebytes(
|
||||
@ -1719,27 +1714,24 @@ def dataURL_to_image(dataURL: str) -> ImageType:
|
||||
return image
|
||||
|
||||
|
||||
"""
|
||||
Converts an image into a base64 image dataURL.
|
||||
"""
|
||||
|
||||
|
||||
def image_to_dataURL(image: ImageType) -> str:
|
||||
def image_to_dataURL(image: ImageType, image_format:str="PNG") -> str:
|
||||
"""
|
||||
Converts an image into a base64 image dataURL.
|
||||
"""
|
||||
buffered = io.BytesIO()
|
||||
image.save(buffered, format="PNG")
|
||||
image_base64 = "data:image/png;base64," + base64.b64encode(
|
||||
image.save(buffered, format=image_format)
|
||||
mime_type = Image.MIME.get(image_format.upper(), "image/" + image_format.lower())
|
||||
image_base64 = f"data:{mime_type};base64," + base64.b64encode(
|
||||
buffered.getvalue()
|
||||
).decode("UTF-8")
|
||||
return image_base64
|
||||
|
||||
|
||||
"""
|
||||
Converts a base64 image dataURL into bytes.
|
||||
The dataURL is split on the first commma.
|
||||
"""
|
||||
|
||||
|
||||
def dataURL_to_bytes(dataURL: str) -> bytes:
|
||||
"""
|
||||
Converts a base64 image dataURL into bytes.
|
||||
The dataURL is split on the first comma.
|
||||
"""
|
||||
return base64.decodebytes(
|
||||
bytes(
|
||||
dataURL.split(",", 1)[1],
|
||||
@ -1748,11 +1740,6 @@ def dataURL_to_bytes(dataURL: str) -> bytes:
|
||||
)
|
||||
|
||||
|
||||
"""
|
||||
Pastes an image onto another with a bounding box.
|
||||
"""
|
||||
|
||||
|
||||
def paste_image_into_bounding_box(
|
||||
recipient_image: ImageType,
|
||||
donor_image: ImageType,
|
||||
@ -1761,23 +1748,24 @@ def paste_image_into_bounding_box(
|
||||
width: int,
|
||||
height: int,
|
||||
) -> ImageType:
|
||||
"""
|
||||
Pastes an image onto another with a bounding box.
|
||||
"""
|
||||
with recipient_image as im:
|
||||
bounds = (x, y, x + width, y + height)
|
||||
im.paste(donor_image, bounds)
|
||||
return recipient_image
|
||||
|
||||
|
||||
"""
|
||||
Saves a thumbnail of an image, returning its path.
|
||||
"""
|
||||
|
||||
|
||||
def save_thumbnail(
|
||||
image: ImageType,
|
||||
filename: str,
|
||||
path: str,
|
||||
size: int = 256,
|
||||
) -> str:
|
||||
"""
|
||||
Saves a thumbnail of an image, returning its path.
|
||||
"""
|
||||
base_filename = os.path.splitext(filename)[0]
|
||||
thumbnail_path = os.path.join(path, base_filename + ".webp")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user