Update app.py
Browse files
app.py
CHANGED
|
@@ -139,39 +139,37 @@ model_uniformer = None
|
|
| 139 |
# return [result]
|
| 140 |
|
| 141 |
|
| 142 |
-
model_lineart_anime = None
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
def lineart_anime(img, res, invert=True):
|
| 146 |
-
img = resize_image(HWC3(img), res)
|
| 147 |
-
global model_lineart_anime
|
| 148 |
-
if model_lineart_anime is None:
|
| 149 |
-
from annotator.lineart_anime import LineartAnimeDetector
|
| 150 |
-
model_lineart_anime = LineartAnimeDetector()
|
| 151 |
-
# result = model_lineart_anime(img)
|
| 152 |
-
if (invert):
|
| 153 |
-
result = cv2.bitwise_not(model_lineart_anime(img))
|
| 154 |
-
else:
|
| 155 |
-
result = model_lineart_anime(img)
|
| 156 |
-
return [result]
|
| 157 |
-
|
| 158 |
|
|
|
|
| 159 |
model_lineart = None
|
| 160 |
|
| 161 |
|
| 162 |
-
def lineart(img, res,
|
| 163 |
img = resize_image(HWC3(img), res)
|
| 164 |
-
|
| 165 |
-
if
|
| 166 |
-
|
| 167 |
-
model_lineart
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
model_oneformer_coco = None
|
| 177 |
|
|
@@ -387,39 +385,22 @@ with gr.Blocks(theme=theme) as demo:
|
|
| 387 |
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
| 388 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
| 389 |
run_button.click(fn=openpose, inputs=[input_image, resolution, hand_and_face], outputs=[gallery])
|
| 390 |
-
|
| 391 |
-
with gr.Tab("Lineart Anime"):
|
| 392 |
-
with gr.Row():
|
| 393 |
-
gr.Markdown("## Lineart Anime \n<p>Check Invert to use with Mochi Diffusion.")
|
| 394 |
-
with gr.Row():
|
| 395 |
-
with gr.Column():
|
| 396 |
-
# input_image = gr.Image(source='upload', type="numpy")
|
| 397 |
-
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
| 398 |
-
invert = gr.Checkbox(label='Invert', value=True)
|
| 399 |
-
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 400 |
-
run_button = gr.Button("Run")
|
| 401 |
-
# run_button = gr.Button(label="Run")
|
| 402 |
-
with gr.Column():
|
| 403 |
-
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
| 404 |
-
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
| 405 |
-
run_button.click(fn=lineart_anime, inputs=[input_image, resolution, invert], outputs=[gallery])
|
| 406 |
|
| 407 |
with gr.Tab("Lineart"):
|
| 408 |
with gr.Row():
|
| 409 |
gr.Markdown("## Lineart \n<p>Check Invert to use with Mochi Diffusion. Inverted image can also be created here for use with ControlNet Scribble.")
|
| 410 |
with gr.Row():
|
| 411 |
with gr.Column():
|
| 412 |
-
|
| 413 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
| 414 |
-
coarse = gr.Checkbox(label='Using coarse model', value=False)
|
| 415 |
invert = gr.Checkbox(label='Invert', value=True)
|
| 416 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 417 |
run_button = gr.Button("Run")
|
| 418 |
# run_button = gr.Button(label="Run")
|
| 419 |
with gr.Column():
|
| 420 |
-
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
| 421 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
| 422 |
-
run_button.click(fn=lineart, inputs=[input_image, resolution,
|
| 423 |
|
| 424 |
|
| 425 |
with gr.Tab("InPaint"):
|
|
@@ -511,4 +492,4 @@ with gr.Blocks(theme=theme) as demo:
|
|
| 511 |
run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])
|
| 512 |
|
| 513 |
|
| 514 |
-
demo.launch()
|
|
|
|
| 139 |
# return [result]
|
| 140 |
|
| 141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
+
model_lineart_anime = None
|
| 144 |
model_lineart = None
|
| 145 |
|
| 146 |
|
| 147 |
+
def lineart(img, res, preprocessor_name=Lineart, invert=True):
|
| 148 |
img = resize_image(HWC3(img), res)
|
| 149 |
+
["Lineart", "Lineart Coarse", "Lineart Anime"]
|
| 150 |
+
if preprocessor_name in ["Lineart", "Lineart Coarse"]:
|
| 151 |
+
coarse = "Coarse" in preprocessor_name
|
| 152 |
+
global model_lineart
|
| 153 |
+
if model_lineart is None:
|
| 154 |
+
from annotator.lineart import LineartDetector
|
| 155 |
+
model_lineart = LineartDetector()
|
| 156 |
+
# result = model_lineart(img, coarse)
|
| 157 |
+
if (invert):
|
| 158 |
+
result = cv2.bitwise_not(model_lineart(img, coarse))
|
| 159 |
+
else:
|
| 160 |
+
result = model_lineart(img, coarse)
|
| 161 |
+
return [result]
|
| 162 |
+
elif preprocessor_name == "Lineart Anime":
|
| 163 |
+
global model_lineart_anime
|
| 164 |
+
if model_lineart_anime is None:
|
| 165 |
+
from annotator.lineart_anime import LineartAnimeDetector
|
| 166 |
+
model_lineart_anime = LineartAnimeDetector()
|
| 167 |
+
# result = model_lineart_anime(img)
|
| 168 |
+
if (invert):
|
| 169 |
+
result = cv2.bitwise_not(model_lineart_anime(img))
|
| 170 |
+
else:
|
| 171 |
+
result = model_lineart_anime(img)
|
| 172 |
+
return [result]
|
| 173 |
|
| 174 |
model_oneformer_coco = None
|
| 175 |
|
|
|
|
| 385 |
# gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
|
| 386 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
| 387 |
run_button.click(fn=openpose, inputs=[input_image, resolution, hand_and_face], outputs=[gallery])
|
| 388 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
|
| 390 |
with gr.Tab("Lineart"):
|
| 391 |
with gr.Row():
|
| 392 |
gr.Markdown("## Lineart \n<p>Check Invert to use with Mochi Diffusion. Inverted image can also be created here for use with ControlNet Scribble.")
|
| 393 |
with gr.Row():
|
| 394 |
with gr.Column():
|
| 395 |
+
preprocessor_name = gr.Radio(label="Preprocessor", choices=["Lineart", "Lineart Coarse", "Lineart Anime"], type="value", value="Lineart")
|
| 396 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
|
|
|
| 397 |
invert = gr.Checkbox(label='Invert', value=True)
|
| 398 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
| 399 |
run_button = gr.Button("Run")
|
| 400 |
# run_button = gr.Button(label="Run")
|
| 401 |
with gr.Column():
|
|
|
|
| 402 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
| 403 |
+
run_button.click(fn=lineart, inputs=[input_image, resolution, preprocessor_name, invert], outputs=[gallery])
|
| 404 |
|
| 405 |
|
| 406 |
with gr.Tab("InPaint"):
|
|
|
|
| 492 |
run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])
|
| 493 |
|
| 494 |
|
| 495 |
+
demo.launch()
|