Compare commits

...

1 Commits

Author SHA1 Message Date
Ean Garvey
7b8655b715 (Studio) Update gradio and multicontrolnet UI. 2023-12-02 01:09:32 -06:00
10 changed files with 221 additions and 63 deletions

View File

@@ -159,6 +159,7 @@ class Image2ImagePipeline(StableDiffusionPipeline):
cpu_scheduling,
max_embeddings_multiples,
resample_type,
control_mode,
):
# prompts and negative prompts must be a list.
if isinstance(prompts, str):

View File

@@ -34,6 +34,7 @@ from apps.stable_diffusion.src.utils import (
from apps.stable_diffusion.src.utils.stencils import (
CannyDetector,
OpenposeDetector,
ZoeDetector,
)
from apps.stable_diffusion.web.utils.common_label_calc import status_label
import numpy as np
@@ -99,6 +100,8 @@ def img2img_inf(
if images[i] is None and stencil is not None:
return None, "A stencil must have an Image input"
if images[i] is not None:
if isinstance(images[i], dict):
images[i] = images[i]["layers"][0]
images[i] = images[i].convert("RGB")
if image_dict is None:
@@ -363,71 +366,187 @@ with gr.Blocks(title="Image-to-Image") as img2img_web:
# TODO: make this import image prompt info if it exists
img2img_init_image = gr.Image(
label="Input Image",
source="upload",
tool="sketch",
type="pil",
height=300,
height=512,
interactive=True,
)
with gr.Accordion(label="Multistencil Options", open=False):
choices = ["None", "canny", "openpose", "scribble"]
choices = [
"None",
"canny",
"openpose",
"scribble",
"zoedepth",
]
def cnet_preview(
checked, model, input_image, index, stencils, images
model, input_image, index, stencils, images
):
if not checked:
stencils[index] = None
images[index] = None
return (None, stencils, images)
images[index] = input_image
stencils[index] = model
match model:
case "canny":
canny = CannyDetector()
result = canny(np.array(input_image), 100, 200)
result = canny(
np.array(input_image["composite"]),
100,
200,
)
return (
[Image.fromarray(result), result],
Image.fromarray(result),
stencils,
images,
)
case "openpose":
openpose = OpenposeDetector()
result = openpose(np.array(input_image))
result = openpose(
np.array(input_image["composite"])
)
# TODO: This is just an empty canvas, need to draw the candidates (which are in result[1])
return (
[Image.fromarray(result[0]), result],
Image.fromarray(result[0]),
stencils,
images,
)
case "zoedepth":
zoedepth = ZoeDetector()
result = zoedepth(
np.array(input_image["composite"])
)
return (
Image.fromarray(result[0]),
stencils,
images,
)
case "scribble":
result = input_image["composite"].convert("L")
return (result, stencils, images)
case _:
return (None, stencils, images)
def create_canvas(width, height):
return {
"background": None,
"layers": [
Image.fromarray(
np.zeros(
shape=(height, width, 3),
dtype=np.uint8,
)
+ 255
)
],
"composite": None,
}
def update_cn_input(model, width, height):
if model == "scribble":
return [
gr.ImageEditor(
visible=True,
image_mode="RGB",
interactive=True,
show_label=False,
type="pil",
value=create_canvas(width, height),
crop_size=(width, height),
),
gr.Image(
visible=True,
show_label=False,
interactive=False,
),
gr.Slider(visible=True),
gr.Slider(visible=True),
gr.Button(visible=True),
]
else:
return [
gr.ImageEditor(
visible=True,
image_mode="RGB",
type="pil",
interactive=True,
value=None,
),
gr.Image(
visible=True,
show_label=False,
interactive=True,
),
gr.Slider(visible=False),
gr.Slider(visible=False),
gr.Button(visible=False),
]
with gr.Row():
cnet_1 = gr.Checkbox(show_label=False)
cnet_1_model = gr.Dropdown(
label="Controlnet 1",
value="None",
choices=choices,
)
cnet_1_image = gr.Image(
source="upload",
tool=None,
with gr.Column():
cnet_1 = gr.Button(
value="Generate controlnet input"
)
cnet_1_model = gr.Dropdown(
label="Controlnet 1",
value="None",
choices=choices,
)
canvas_width = gr.Slider(
label="Canvas Width",
minimum=256,
maximum=1024,
value=512,
step=1,
visible=False,
)
canvas_height = gr.Slider(
label="Canvas Height",
minimum=256,
maximum=1024,
value=512,
step=1,
visible=False,
)
make_canvas = gr.Button(
value="Make Canvas!",
visible=False,
)
cnet_1_image = gr.ImageEditor(
visible=False,
image_mode="RGB",
interactive=True,
show_label=False,
type="pil",
)
cnet_1_output = gr.Gallery(
show_label=False,
object_fit="scale-down",
rows=1,
columns=1,
cnet_1_output = gr.Image(
visible=True, show_label=False
)
cnet_1.change(
cnet_1_model.input(
update_cn_input,
[cnet_1_model, canvas_width, canvas_height],
[
cnet_1_image,
cnet_1_output,
canvas_width,
canvas_height,
make_canvas,
],
)
make_canvas.click(
update_cn_input,
[cnet_1_model, canvas_width, canvas_height],
[
cnet_1_image,
cnet_1_output,
canvas_width,
canvas_height,
make_canvas,
],
)
cnet_1.click(
fn=(
lambda a, b, c, s, i: cnet_preview(
a, b, c, 0, s, i
)
lambda a, b, s, i: cnet_preview(a, b, 0, s, i)
),
inputs=[
cnet_1,
cnet_1_model,
cnet_1_image,
stencils,
@@ -436,31 +555,72 @@ with gr.Blocks(title="Image-to-Image") as img2img_web:
outputs=[cnet_1_output, stencils, images],
)
with gr.Row():
cnet_2 = gr.Checkbox(show_label=False)
cnet_2_model = gr.Dropdown(
label="Controlnet 2",
value="None",
choices=choices,
)
cnet_2_image = gr.Image(
source="upload",
tool=None,
with gr.Column():
cnet_2 = gr.Button(
value="Generate controlnet input"
)
cnet_2_model = gr.Dropdown(
label="Controlnet 2",
value="None",
choices=choices,
)
canvas_width = gr.Slider(
label="Canvas Width",
minimum=256,
maximum=1024,
value=512,
step=1,
visible=False,
)
canvas_height = gr.Slider(
label="Canvas Height",
minimum=256,
maximum=1024,
value=512,
step=1,
visible=False,
)
make_canvas = gr.Button(
value="Make Canvas!",
visible=False,
)
cnet_2_image = gr.ImageEditor(
visible=False,
image_mode="RGB",
interactive=True,
show_label=False,
type="pil",
)
cnet_2_output = gr.Gallery(
show_label=False,
object_fit="scale-down",
rows=1,
columns=1,
cnet_2_output = gr.Image(
visible=True, show_label=False
)
cnet_2.change(
cnet_2_model.select(
update_cn_input,
[cnet_2_model, canvas_width, canvas_height],
[
cnet_2_image,
cnet_2_output,
canvas_width,
canvas_height,
make_canvas,
],
)
make_canvas.click(
update_cn_input,
[cnet_2_model, canvas_width, canvas_height],
[
cnet_2_image,
cnet_2_output,
canvas_width,
canvas_height,
make_canvas,
],
)
cnet_2.click(
fn=(
lambda a, b, c, s, i: cnet_preview(
a, b, c, 1, s, i
)
lambda a, b, s, i: cnet_preview(a, b, 1, s, i)
),
inputs=[
cnet_2,
cnet_2_model,
cnet_2_image,
stencils,

View File

@@ -288,10 +288,9 @@ with gr.Blocks(title="Inpainting") as inpaint_web:
elem_id="negative_prompt_box",
)
inpaint_init_image = gr.Image(
inpaint_init_image = gr.ImageEditor(
label="Masked Image",
source="upload",
tool="sketch",
sources="upload",
type="pil",
height=350,
)

View File

@@ -104,7 +104,6 @@ with gr.Blocks() as model_web:
civit_models = gr.Gallery(
label="Civitai Model Gallery",
value=None,
interactive=True,
visible=False,
)

View File

@@ -291,7 +291,7 @@ with gr.Blocks(title="Outpainting") as outpaint_web:
elem_id="negative_prompt_box",
)
outpaint_init_image = gr.Image(
outpaint_init_image = gr.ImageEditor(
label="Input Image",
type="pil",
height=300,

View File

@@ -95,7 +95,7 @@ with gr.Blocks() as outputgallery_web:
)
with gr.Column(scale=4):
with gr.Box():
with gr.Group():
with gr.Row():
with gr.Column(
scale=15,
@@ -254,7 +254,7 @@ with gr.Blocks() as outputgallery_web:
)
return [
gr.Dropdown.update(
gr.Dropdown(
choices=refreshed_subdirs,
value=new_subdir,
),

View File

@@ -431,8 +431,8 @@ with gr.Blocks(title="Chatbot") as stablelm_chat:
config_file = gr.File(
label="Upload sharding configuration", visible=False
)
json_view_button = gr.Button(label="View as JSON", visible=False)
json_view = gr.JSON(interactive=True, visible=False)
json_view_button = gr.Button(value="View as JSON", visible=False)
json_view = gr.JSON(visible=False)
json_view_button.click(
fn=view_json_file, inputs=[config_file], outputs=[json_view]
)

View File

@@ -356,7 +356,6 @@ with gr.Blocks(title="Text-to-Image") as txt2img_web:
label="Import PNG info",
elem_id="txt2img_prompt_image",
type="pil",
tool="None",
visible=True,
)

View File

@@ -311,7 +311,7 @@ with gr.Blocks(title="Upscaler") as upscaler_web:
elem_id="negative_prompt_box",
)
upscaler_init_image = gr.Image(
upscaler_init_image = gr.ImageEditor(
label="Input Image",
type="pil",
height=300,

View File

@@ -26,7 +26,7 @@ diffusers
accelerate
scipy
ftfy
gradio==3.44.3
gradio==4.7.1
altair
omegaconf
# 0.3.2 doesn't have binaries for arm64