Sebastiankay commited on
Commit
00ac23b
·
1 Parent(s): 258b300

28. Sept. 2024, 11:00

Browse files
Files changed (1) hide show
  1. app.py +39 -8
app.py CHANGED
@@ -4,9 +4,7 @@ import numpy as np
4
 
5
  from annotator.util import resize_image, HWC3
6
 
7
- DESCRIPTION = "# "
8
- DESCRIPTION += "# ControlNet v1.1 Preprocessors Standalone"
9
- DESCRIPTION += "\n<p>Generate Control Images for Stable Diffusion and other apps that uses ControlNet.</p>"
10
 
11
 
12
  model_canny = None
@@ -168,9 +166,9 @@ def lineart(img, res, preprocessor_name="Lineart", invert=True, old_images=None)
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
@@ -179,9 +177,9 @@ def lineart(img, res, preprocessor_name="Lineart", invert=True, old_images=None)
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:
@@ -267,7 +265,40 @@ theme = gr.themes.Soft(
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")
273
  with gr.Tab("Canny Edge", elem_id="tab_wrapper", elem_classes="tab_wrapper"):
@@ -509,6 +540,6 @@ with gr.Blocks(theme=theme, css="custom.css", js="javascript.js") as demo:
509
  gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
510
 
511
  run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])
512
-
513
 
514
  demo.launch()
 
4
 
5
  from annotator.util import resize_image, HWC3
6
 
7
+ title = "ControlNet v1.1 Preprocessors Standalone"
 
 
8
 
9
 
10
  model_canny = None
 
166
 
167
  model_lineart = LineartDetector()
168
  if invert:
169
+ result = (cv2.bitwise_not(model_lineart(img, coarse)), preprocessor_name)
170
  else:
171
+ result = (model_lineart(img, coarse), preprocessor_name)
172
  # return [result]
173
  elif preprocessor_name == "Lineart Anime":
174
  global model_lineart_anime
 
177
 
178
  model_lineart_anime = LineartAnimeDetector()
179
  if invert:
180
+ result = (cv2.bitwise_not(model_lineart_anime(img)), preprocessor_name)
181
  else:
182
+ result = (model_lineart_anime(img), preprocessor_name)
183
 
184
  result_images.append(result)
185
  if old_images is not None:
 
265
  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"),
266
  )
267
 
268
+ with gr.Blocks(theme=theme, css="custom.css", js="javascript.js") as demo:
269
+ with gr.Row(elem_classes="row-header"):
270
+ gr.Markdown(
271
+ f"""
272
+ <h1>{title}</h1>
273
+ <p>Erstelle "Control Images" für Stable Diffusion und andere Tools die ControlNet verwenden.<br/>
274
+ Diese Demo läuft nur auf CPU, eine Inference wird daher sehr lange dauern.<br/>
275
+ Du kannst diesen Space clonen und lokal auf deinem Computer verwenden.</p>
276
+ <p>👋 Sebastian, gib dem Space gerne ein ❤️</p>
277
+ """,
278
+ elem_classes="md-header",
279
+ )
280
+ with gr.Row(elem_classes="row-main"):
281
+ with gr.Column(scale=1):
282
+ input_image = gr.Image(label="Input Image", type="numpy", height=512)
283
+
284
+ ## TAB LINEART
285
+ with gr.Tab("Lineart"):
286
+ with gr.Row():
287
+ gr.Markdown("## Lineart \n<p>Check Invert to use with Mochi Diffusion. Inverted image can also be created here for use with ControlNet Scribble.")
288
+ with gr.Row():
289
+ with gr.Column():
290
+ preprocessor_name = gr.Radio(label="Preprocessor", show_label=False, choices=["Lineart", "Lineart Coarse", "Lineart Anime"], type="value", value="Lineart")
291
+ invert = gr.Checkbox(label="Invert", value=True)
292
+ resolution = gr.Slider(label="resolution", minimum=256, maximum=1024, value=512, step=64)
293
+ run_btn_lineart = gr.Button("Run")
294
+
295
+ with gr.Column(scale=2):
296
+ gallery = gr.Gallery(label="Generated images", show_label=False, interactive=False, format="png", elem_id="output_gallery", elem_classes="output-gallery", columns=[3], rows=[2], object_fit="contain", height="auto", type="filepath")
297
+
298
+ run_btn_lineart.click(fn=lineart, inputs=[input_image, resolution, preprocessor_name, invert, gallery], outputs=[gallery])
299
 
300
+
301
+ """
302
  with gr.Blocks(theme=theme, css="custom.css", js="javascript.js") as demo:
303
  gr.Markdown(DESCRIPTION, elem_classes="top-description")
304
  with gr.Tab("Canny Edge", elem_id="tab_wrapper", elem_classes="tab_wrapper"):
 
540
  gallery = gr.Gallery(label="Generated images", show_label=False, height="auto")
541
 
542
  run_button.click(fn=color_shuffler, inputs=[input_image, resolution], outputs=[gallery])
543
+ """
544
 
545
  demo.launch()