Commit
·
bc83ad3
1
Parent(s):
3155170
28. Sept. 2024, 10:16
Browse files
app.py
CHANGED
@@ -154,7 +154,10 @@ model_lineart_anime = None
|
|
154 |
model_lineart = None
|
155 |
|
156 |
|
157 |
-
def lineart(img, res, preprocessor_name="Lineart", invert=True):
|
|
|
|
|
|
|
158 |
img = resize_image(HWC3(img), res)
|
159 |
["Lineart", "Lineart Coarse", "Lineart Anime"]
|
160 |
if preprocessor_name in ["Lineart", "Lineart Coarse"]:
|
@@ -164,24 +167,26 @@ def lineart(img, res, preprocessor_name="Lineart", invert=True):
|
|
164 |
from annotator.lineart import LineartDetector
|
165 |
|
166 |
model_lineart = LineartDetector()
|
167 |
-
# result = model_lineart(img, coarse)
|
168 |
if invert:
|
169 |
result = cv2.bitwise_not(model_lineart(img, coarse))
|
170 |
else:
|
171 |
result = model_lineart(img, coarse)
|
172 |
-
return [result]
|
173 |
elif preprocessor_name == "Lineart Anime":
|
174 |
global model_lineart_anime
|
175 |
if model_lineart_anime is None:
|
176 |
from annotator.lineart_anime import LineartAnimeDetector
|
177 |
|
178 |
model_lineart_anime = LineartAnimeDetector()
|
179 |
-
# result = model_lineart_anime(img)
|
180 |
if invert:
|
181 |
result = cv2.bitwise_not(model_lineart_anime(img))
|
182 |
else:
|
183 |
result = model_lineart_anime(img)
|
184 |
-
|
|
|
|
|
|
|
|
|
185 |
|
186 |
|
187 |
model_oneformer_coco = None
|
@@ -262,45 +267,6 @@ theme = gr.themes.Soft(
|
|
262 |
neutral_hue=gr.themes.Color(c100="#a6adc8", c200="#9399b2", c300="#7f849c", c400="#6c7086", c50="#cdd6f4", c500="#585b70", c600="#45475a", c700="#313244", c800="#1e1e2e", c900="#181825", c950="#11111b"),
|
263 |
)
|
264 |
|
265 |
-
css = """
|
266 |
-
body > gradio-app {
|
267 |
-
background: var(--primary-950);
|
268 |
-
background: linear-gradient(180deg, color-mix(in srgb, var(--primary-950), transparent 50%) 0%, color-mix(in srgb, var(--primary-950), transparent 50%) 28%, var(--neutral-950) 28%, var(--neutral-950) 100%) !important;
|
269 |
-
padding-top: 120px;
|
270 |
-
}
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
div.tabs > div.tab-nav {
|
275 |
-
border-bottom: none; !important;
|
276 |
-
padding: 0 0.25rem 0 0.25rem !important;
|
277 |
-
flex-wrap: nowrap;
|
278 |
-
overflow-x: scroll;
|
279 |
-
overflow-y:hidden;
|
280 |
-
}
|
281 |
-
|
282 |
-
div.tabs > div.tab-nav > button.selected {
|
283 |
-
border-width: 0 !important;
|
284 |
-
background: var(--primary-600) !important;
|
285 |
-
color: var(--neutral-950);
|
286 |
-
font-weight: 600;
|
287 |
-
}
|
288 |
-
|
289 |
-
div.tabs > div.tab-nav > button {
|
290 |
-
min-width: 140px !important;
|
291 |
-
}
|
292 |
-
|
293 |
-
div.tabs div.tabitem {
|
294 |
-
background-color: var(--neutral-900) !important;
|
295 |
-
border-top: 8px solid var(--primary-600) !important;
|
296 |
-
border-radius: var(--container-radius) !important;
|
297 |
-
}
|
298 |
-
|
299 |
-
.top-description h1 {
|
300 |
-
color: var(--neutral-400);
|
301 |
-
font-size: 2rem;
|
302 |
-
}
|
303 |
-
"""
|
304 |
|
305 |
with gr.Blocks(theme=theme, css="custom.css", js="javascript.js") as demo:
|
306 |
gr.Markdown(DESCRIPTION, elem_classes="top-description")
|
@@ -450,24 +416,15 @@ with gr.Blocks(theme=theme, css="custom.css", js="javascript.js") as demo:
|
|
450 |
gr.Markdown("## Lineart \n<p>Check Invert to use with Mochi Diffusion. Inverted image can also be created here for use with ControlNet Scribble.")
|
451 |
with gr.Row():
|
452 |
with gr.Column():
|
453 |
-
preprocessor_name = gr.Radio(label="Preprocessor", choices=["Lineart", "Lineart Coarse", "Lineart Anime"], type="value", value="Lineart")
|
454 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
|
|
455 |
invert = gr.Checkbox(label="Invert", value=True)
|
456 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
457 |
-
|
458 |
with gr.Column():
|
459 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
460 |
|
461 |
-
|
462 |
-
if preprocessor_name == "Lineart":
|
463 |
-
return "Lineart"
|
464 |
-
elif preprocessor_name == "Lineart Coarse":
|
465 |
-
return "Lineart Coarse"
|
466 |
-
elif preprocessor_name == "Lineart Anime":
|
467 |
-
return "Lineart Anime"
|
468 |
-
|
469 |
-
preprocessor_name.change(fn=update_button_label, inputs=[preprocessor_name], outputs=[run_button])
|
470 |
-
run_button.click(fn=lineart, inputs=[input_image, resolution, preprocessor_name, invert], outputs=[gallery])
|
471 |
|
472 |
with gr.Tab("InPaint"):
|
473 |
with gr.Row():
|
|
|
154 |
model_lineart = None
|
155 |
|
156 |
|
157 |
+
def lineart(img, res, preprocessor_name="Lineart", invert=True, old_images=None):
|
158 |
+
print("Old Images: ", old_images)
|
159 |
+
result_images = []
|
160 |
+
result = None
|
161 |
img = resize_image(HWC3(img), res)
|
162 |
["Lineart", "Lineart Coarse", "Lineart Anime"]
|
163 |
if preprocessor_name in ["Lineart", "Lineart Coarse"]:
|
|
|
167 |
from annotator.lineart import LineartDetector
|
168 |
|
169 |
model_lineart = LineartDetector()
|
|
|
170 |
if invert:
|
171 |
result = cv2.bitwise_not(model_lineart(img, coarse))
|
172 |
else:
|
173 |
result = model_lineart(img, coarse)
|
174 |
+
# return [result]
|
175 |
elif preprocessor_name == "Lineart Anime":
|
176 |
global model_lineart_anime
|
177 |
if model_lineart_anime is None:
|
178 |
from annotator.lineart_anime import LineartAnimeDetector
|
179 |
|
180 |
model_lineart_anime = LineartAnimeDetector()
|
|
|
181 |
if invert:
|
182 |
result = cv2.bitwise_not(model_lineart_anime(img))
|
183 |
else:
|
184 |
result = model_lineart_anime(img)
|
185 |
+
|
186 |
+
result_images.append(result)
|
187 |
+
if old_images is not None:
|
188 |
+
result_images.extend(old_images)
|
189 |
+
return result_images
|
190 |
|
191 |
|
192 |
model_oneformer_coco = None
|
|
|
267 |
neutral_hue=gr.themes.Color(c100="#a6adc8", c200="#9399b2", c300="#7f849c", c400="#6c7086", c50="#cdd6f4", c500="#585b70", c600="#45475a", c700="#313244", c800="#1e1e2e", c900="#181825", c950="#11111b"),
|
268 |
)
|
269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
|
271 |
with gr.Blocks(theme=theme, css="custom.css", js="javascript.js") as demo:
|
272 |
gr.Markdown(DESCRIPTION, elem_classes="top-description")
|
|
|
416 |
gr.Markdown("## Lineart \n<p>Check Invert to use with Mochi Diffusion. Inverted image can also be created here for use with ControlNet Scribble.")
|
417 |
with gr.Row():
|
418 |
with gr.Column():
|
|
|
419 |
input_image = gr.Image(label="Input Image", type="numpy", height=512)
|
420 |
+
preprocessor_name = gr.Radio(label="Preprocessor", show_label=False, choices=["Lineart", "Lineart Coarse", "Lineart Anime"], type="value", value="Lineart")
|
421 |
invert = gr.Checkbox(label="Invert", value=True)
|
422 |
resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
|
423 |
+
run_btn_lineart = gr.Button("Run")
|
424 |
with gr.Column():
|
425 |
gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
|
426 |
|
427 |
+
run_btn_lineart.click(fn=lineart, inputs=[input_image, resolution, preprocessor_name, invert, gallery], outputs=[gallery])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
428 |
|
429 |
with gr.Tab("InPaint"):
|
430 |
with gr.Row():
|