mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
chore: remove old web server code and python deps
This commit is contained in:
parent
d3d8b71c67
commit
549d2e0485
@ -1,4 +0,0 @@
|
|||||||
"""
|
|
||||||
Initialization file for the web backend.
|
|
||||||
"""
|
|
||||||
from .invoke_ai_web_server import InvokeAIWebServer
|
|
File diff suppressed because it is too large
Load Diff
@ -1,56 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import os
|
|
||||||
|
|
||||||
from ...args import PRECISION_CHOICES
|
|
||||||
|
|
||||||
|
|
||||||
def create_cmd_parser():
|
|
||||||
parser = argparse.ArgumentParser(description="InvokeAI web UI")
|
|
||||||
parser.add_argument(
|
|
||||||
"--host",
|
|
||||||
type=str,
|
|
||||||
help="The host to serve on",
|
|
||||||
default="localhost",
|
|
||||||
)
|
|
||||||
parser.add_argument("--port", type=int, help="The port to serve on", default=9090)
|
|
||||||
parser.add_argument(
|
|
||||||
"--cors",
|
|
||||||
nargs="*",
|
|
||||||
type=str,
|
|
||||||
help="Additional allowed origins, comma-separated",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--embedding_path",
|
|
||||||
type=str,
|
|
||||||
help="Path to a pre-trained embedding manager checkpoint - can only be set on command line",
|
|
||||||
)
|
|
||||||
# TODO: Can't get flask to serve images from any dir (saving to the dir does work when specified)
|
|
||||||
# parser.add_argument(
|
|
||||||
# "--output_dir",
|
|
||||||
# default="outputs/",
|
|
||||||
# type=str,
|
|
||||||
# help="Directory for output images",
|
|
||||||
# )
|
|
||||||
parser.add_argument(
|
|
||||||
"-v",
|
|
||||||
"--verbose",
|
|
||||||
action="store_true",
|
|
||||||
help="Enables verbose logging",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--precision",
|
|
||||||
dest="precision",
|
|
||||||
type=str,
|
|
||||||
choices=PRECISION_CHOICES,
|
|
||||||
metavar="PRECISION",
|
|
||||||
help=f'Set model precision. Defaults to auto selected based on device. Options: {", ".join(PRECISION_CHOICES)}',
|
|
||||||
default="auto",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
|
||||||
"--free_gpu_mem",
|
|
||||||
dest="free_gpu_mem",
|
|
||||||
action="store_true",
|
|
||||||
help="Force free gpu memory before final decoding",
|
|
||||||
)
|
|
||||||
|
|
||||||
return parser
|
|
@ -1,113 +0,0 @@
|
|||||||
from typing import Literal, Union
|
|
||||||
|
|
||||||
from PIL import Image, ImageChops
|
|
||||||
from PIL.Image import Image as ImageType
|
|
||||||
|
|
||||||
|
|
||||||
# https://stackoverflow.com/questions/43864101/python-pil-check-if-image-is-transparent
|
|
||||||
def check_for_any_transparency(img: Union[ImageType, str]) -> bool:
|
|
||||||
if type(img) is str:
|
|
||||||
img = Image.open(str)
|
|
||||||
|
|
||||||
if img.info.get("transparency", None) is not None:
|
|
||||||
return True
|
|
||||||
if img.mode == "P":
|
|
||||||
transparent = img.info.get("transparency", -1)
|
|
||||||
for _, index in img.getcolors():
|
|
||||||
if index == transparent:
|
|
||||||
return True
|
|
||||||
elif img.mode == "RGBA":
|
|
||||||
extrema = img.getextrema()
|
|
||||||
if extrema[3][0] < 255:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def get_canvas_generation_mode(
|
|
||||||
init_img: Union[ImageType, str], init_mask: Union[ImageType, str]
|
|
||||||
) -> Literal["txt2img", "outpainting", "inpainting", "img2img",]:
|
|
||||||
if type(init_img) is str:
|
|
||||||
init_img = Image.open(init_img)
|
|
||||||
|
|
||||||
if type(init_mask) is str:
|
|
||||||
init_mask = Image.open(init_mask)
|
|
||||||
|
|
||||||
init_img = init_img.convert("RGBA")
|
|
||||||
|
|
||||||
# Get alpha from init_img
|
|
||||||
init_img_alpha = init_img.split()[-1]
|
|
||||||
init_img_alpha_mask = init_img_alpha.convert("L")
|
|
||||||
init_img_has_transparency = check_for_any_transparency(init_img)
|
|
||||||
|
|
||||||
if init_img_has_transparency:
|
|
||||||
init_img_is_fully_transparent = True if init_img_alpha_mask.getbbox() is None else False
|
|
||||||
|
|
||||||
"""
|
|
||||||
Mask images are white in areas where no change should be made, black where changes
|
|
||||||
should be made.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Fit the mask to init_img's size and convert it to greyscale
|
|
||||||
init_mask = init_mask.resize(init_img.size).convert("L")
|
|
||||||
|
|
||||||
"""
|
|
||||||
PIL.Image.getbbox() returns the bounding box of non-zero areas of the image, so we first
|
|
||||||
invert the mask image so that masked areas are white and other areas black == zero.
|
|
||||||
getbbox() now tells us if the are any masked areas.
|
|
||||||
"""
|
|
||||||
init_mask_bbox = ImageChops.invert(init_mask).getbbox()
|
|
||||||
init_mask_exists = False if init_mask_bbox is None else True
|
|
||||||
|
|
||||||
if init_img_has_transparency:
|
|
||||||
if init_img_is_fully_transparent:
|
|
||||||
return "txt2img"
|
|
||||||
else:
|
|
||||||
return "outpainting"
|
|
||||||
else:
|
|
||||||
if init_mask_exists:
|
|
||||||
return "inpainting"
|
|
||||||
else:
|
|
||||||
return "img2img"
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# Testing
|
|
||||||
init_img_opaque = "test_images/init-img_opaque.png"
|
|
||||||
init_img_partial_transparency = "test_images/init-img_partial_transparency.png"
|
|
||||||
init_img_full_transparency = "test_images/init-img_full_transparency.png"
|
|
||||||
init_mask_no_mask = "test_images/init-mask_no_mask.png"
|
|
||||||
init_mask_has_mask = "test_images/init-mask_has_mask.png"
|
|
||||||
|
|
||||||
print(
|
|
||||||
"OPAQUE IMAGE, NO MASK, expect img2img, got ",
|
|
||||||
get_canvas_generation_mode(init_img_opaque, init_mask_no_mask),
|
|
||||||
)
|
|
||||||
|
|
||||||
print(
|
|
||||||
"IMAGE WITH TRANSPARENCY, NO MASK, expect outpainting, got ",
|
|
||||||
get_canvas_generation_mode(init_img_partial_transparency, init_mask_no_mask),
|
|
||||||
)
|
|
||||||
|
|
||||||
print(
|
|
||||||
"FULLY TRANSPARENT IMAGE NO MASK, expect txt2img, got ",
|
|
||||||
get_canvas_generation_mode(init_img_full_transparency, init_mask_no_mask),
|
|
||||||
)
|
|
||||||
|
|
||||||
print(
|
|
||||||
"OPAQUE IMAGE, WITH MASK, expect inpainting, got ",
|
|
||||||
get_canvas_generation_mode(init_img_opaque, init_mask_has_mask),
|
|
||||||
)
|
|
||||||
|
|
||||||
print(
|
|
||||||
"IMAGE WITH TRANSPARENCY, WITH MASK, expect outpainting, got ",
|
|
||||||
get_canvas_generation_mode(init_img_partial_transparency, init_mask_has_mask),
|
|
||||||
)
|
|
||||||
|
|
||||||
print(
|
|
||||||
"FULLY TRANSPARENT IMAGE WITH MASK, expect txt2img, got ",
|
|
||||||
get_canvas_generation_mode(init_img_full_transparency, init_mask_has_mask),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
@ -1,82 +0,0 @@
|
|||||||
import argparse
|
|
||||||
|
|
||||||
from .parse_seed_weights import parse_seed_weights
|
|
||||||
|
|
||||||
SAMPLER_CHOICES = [
|
|
||||||
"ddim",
|
|
||||||
"ddpm",
|
|
||||||
"deis",
|
|
||||||
"lms",
|
|
||||||
"lms_k",
|
|
||||||
"pndm",
|
|
||||||
"heun",
|
|
||||||
"heun_k",
|
|
||||||
"euler",
|
|
||||||
"euler_k",
|
|
||||||
"euler_a",
|
|
||||||
"kdpm_2",
|
|
||||||
"kdpm_2_a",
|
|
||||||
"dpmpp_2s",
|
|
||||||
"dpmpp_2s_k",
|
|
||||||
"dpmpp_2m",
|
|
||||||
"dpmpp_2m_k",
|
|
||||||
"dpmpp_2m_sde",
|
|
||||||
"dpmpp_2m_sde_k",
|
|
||||||
"dpmpp_sde",
|
|
||||||
"dpmpp_sde_k",
|
|
||||||
"unipc",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def parameters_to_command(params):
|
|
||||||
"""
|
|
||||||
Converts dict of parameters into a `invoke.py` REPL command.
|
|
||||||
"""
|
|
||||||
|
|
||||||
switches = list()
|
|
||||||
|
|
||||||
if "prompt" in params:
|
|
||||||
switches.append(f'"{params["prompt"]}"')
|
|
||||||
if "steps" in params:
|
|
||||||
switches.append(f'-s {params["steps"]}')
|
|
||||||
if "seed" in params:
|
|
||||||
switches.append(f'-S {params["seed"]}')
|
|
||||||
if "width" in params:
|
|
||||||
switches.append(f'-W {params["width"]}')
|
|
||||||
if "height" in params:
|
|
||||||
switches.append(f'-H {params["height"]}')
|
|
||||||
if "cfg_scale" in params:
|
|
||||||
switches.append(f'-C {params["cfg_scale"]}')
|
|
||||||
if "sampler_name" in params:
|
|
||||||
switches.append(f'-A {params["sampler_name"]}')
|
|
||||||
if "seamless" in params and params["seamless"] == True:
|
|
||||||
switches.append(f"--seamless")
|
|
||||||
if "hires_fix" in params and params["hires_fix"] == True:
|
|
||||||
switches.append(f"--hires")
|
|
||||||
if "init_img" in params and len(params["init_img"]) > 0:
|
|
||||||
switches.append(f'-I {params["init_img"]}')
|
|
||||||
if "init_mask" in params and len(params["init_mask"]) > 0:
|
|
||||||
switches.append(f'-M {params["init_mask"]}')
|
|
||||||
if "init_color" in params and len(params["init_color"]) > 0:
|
|
||||||
switches.append(f'--init_color {params["init_color"]}')
|
|
||||||
if "strength" in params and "init_img" in params:
|
|
||||||
switches.append(f'-f {params["strength"]}')
|
|
||||||
if "fit" in params and params["fit"] == True:
|
|
||||||
switches.append(f"--fit")
|
|
||||||
if "facetool" in params:
|
|
||||||
switches.append(f'-ft {params["facetool"]}')
|
|
||||||
if "facetool_strength" in params and params["facetool_strength"]:
|
|
||||||
switches.append(f'-G {params["facetool_strength"]}')
|
|
||||||
elif "gfpgan_strength" in params and params["gfpgan_strength"]:
|
|
||||||
switches.append(f'-G {params["gfpgan_strength"]}')
|
|
||||||
if "codeformer_fidelity" in params:
|
|
||||||
switches.append(f'-cf {params["codeformer_fidelity"]}')
|
|
||||||
if "upscale" in params and params["upscale"]:
|
|
||||||
switches.append(f'-U {params["upscale"][0]} {params["upscale"][1]}')
|
|
||||||
if "variation_amount" in params and params["variation_amount"] > 0:
|
|
||||||
switches.append(f'-v {params["variation_amount"]}')
|
|
||||||
if "with_variations" in params:
|
|
||||||
seed_weight_pairs = ",".join(f"{seed}:{weight}" for seed, weight in params["with_variations"])
|
|
||||||
switches.append(f"-V {seed_weight_pairs}")
|
|
||||||
|
|
||||||
return " ".join(switches)
|
|
@ -1,47 +0,0 @@
|
|||||||
def parse_seed_weights(seed_weights):
|
|
||||||
"""
|
|
||||||
Accepts seed weights as string in "12345:0.1,23456:0.2,3456:0.3" format
|
|
||||||
Validates them
|
|
||||||
If valid: returns as [[12345, 0.1], [23456, 0.2], [3456, 0.3]]
|
|
||||||
If invalid: returns False
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Must be a string
|
|
||||||
if not isinstance(seed_weights, str):
|
|
||||||
return False
|
|
||||||
# String must not be empty
|
|
||||||
if len(seed_weights) == 0:
|
|
||||||
return False
|
|
||||||
|
|
||||||
pairs = []
|
|
||||||
|
|
||||||
for pair in seed_weights.split(","):
|
|
||||||
split_values = pair.split(":")
|
|
||||||
|
|
||||||
# Seed and weight are required
|
|
||||||
if len(split_values) != 2:
|
|
||||||
return False
|
|
||||||
|
|
||||||
if len(split_values[0]) == 0 or len(split_values[1]) == 1:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Try casting the seed to int and weight to float
|
|
||||||
try:
|
|
||||||
seed = int(split_values[0])
|
|
||||||
weight = float(split_values[1])
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Seed must be 0 or above
|
|
||||||
if not seed >= 0:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Weight must be between 0 and 1
|
|
||||||
if not (weight >= 0 and weight <= 1):
|
|
||||||
return False
|
|
||||||
|
|
||||||
# This pair is valid
|
|
||||||
pairs.append([seed, weight])
|
|
||||||
|
|
||||||
# All pairs are valid
|
|
||||||
return pairs
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 292 KiB |
Binary file not shown.
Before Width: | Height: | Size: 164 KiB |
Binary file not shown.
Before Width: | Height: | Size: 9.5 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.4 KiB |
@ -45,15 +45,10 @@ dependencies = [
|
|||||||
"dynamicprompts",
|
"dynamicprompts",
|
||||||
"easing-functions",
|
"easing-functions",
|
||||||
"einops",
|
"einops",
|
||||||
"eventlet",
|
|
||||||
"facexlib",
|
"facexlib",
|
||||||
"fastapi==0.88.0",
|
"fastapi==0.88.0",
|
||||||
"fastapi-events==0.8.0",
|
"fastapi-events==0.8.0",
|
||||||
"fastapi-socketio==0.0.10",
|
"fastapi-socketio==0.0.10",
|
||||||
"flask==2.1.3",
|
|
||||||
"flask_cors==3.0.10",
|
|
||||||
"flask_socketio==5.3.0",
|
|
||||||
"flaskwebgui==1.0.3",
|
|
||||||
"huggingface-hub>=0.11.1",
|
"huggingface-hub>=0.11.1",
|
||||||
"invisible-watermark~=0.2.0", # needed to install SDXL base and refiner using their repo_ids
|
"invisible-watermark~=0.2.0", # needed to install SDXL base and refiner using their repo_ids
|
||||||
"matplotlib", # needed for plotting of Penner easing functions
|
"matplotlib", # needed for plotting of Penner easing functions
|
||||||
|
Loading…
Reference in New Issue
Block a user