atatakun commited on
Commit
b1cc251
1 Parent(s): aaa6de6

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -1,10 +1,11 @@
1
  import gradio as gr
2
  import cv2
 
3
 
4
  from annotator.util import resize_image, HWC3
5
 
6
  DESCRIPTION = '# ControlNet v1.1 Annotators (that runs on cpu only)'
7
- DESCRIPTION += '\n<p>This app generates Control Image for Mochi Diffusion&apos;s ControlNet.</p>'
8
  DESCRIPTION += '\n<p>HEIC image is not converted. Please use PNG or JPG image.</p>'
9
 
10
 
@@ -210,6 +211,17 @@ def color_shuffler(img, res):
210
  result = model_color_shuffler(img)
211
  return [result]
212
 
 
 
 
 
 
 
 
 
 
 
 
213
 
214
  block = gr.Blocks().queue()
215
  with block:
@@ -342,6 +354,18 @@ with block:
342
  gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
343
  run_button.click(fn=lineart, inputs=[input_image, resolution, coarse, invert], outputs=[gallery])
344
 
 
 
 
 
 
 
 
 
 
 
 
 
345
  # with gr.Row():
346
  # gr.Markdown("## Uniformer Segmentation")
347
  # with gr.Row():
 
1
  import gradio as gr
2
  import cv2
3
+ import numpy as np
4
 
5
  from annotator.util import resize_image, HWC3
6
 
7
  DESCRIPTION = '# ControlNet v1.1 Annotators (that runs on cpu only)'
8
+ DESCRIPTION += '\n<p>This app generates Control Image for CoreML apps such as Mochi Diffusion.</p>'
9
  DESCRIPTION += '\n<p>HEIC image is not converted. Please use PNG or JPG image.</p>'
10
 
11
 
 
211
  result = model_color_shuffler(img)
212
  return [result]
213
 
214
+ model_inpaint = None
215
+
216
+
217
+ def inpaint(image, invert):
218
+ color = HWC3(image["image"])
219
+ if(invert):
220
+ alpha = image["mask"][:, :, 0:1]
221
+ else:
222
+ alpha = 255 - image["mask"][:, :, 0:1]
223
+ result = np.concatenate([color, alpha], axis=2)
224
+ return [result]
225
 
226
  block = gr.Blocks().queue()
227
  with block:
 
354
  gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
355
  run_button.click(fn=lineart, inputs=[input_image, resolution, coarse, invert], outputs=[gallery])
356
 
357
+ gr.Markdown("<hr>")
358
+ with gr.Row():
359
+ gr.Markdown("## InPaint")
360
+ with gr.Row():
361
+ with gr.Column():
362
+ input_image = gr.Image(source='upload', type="numpy", tool="sketch", height=512)
363
+ invert = gr.Checkbox(label='Invert Mask', value=False)
364
+ run_button = gr.Button(label="Run")
365
+ with gr.Column():
366
+ gallery = gr.Gallery(label="Generated images", show_label=False).style(height="auto")
367
+ run_button.click(fn=inpaint, inputs=[input_image, invert], outputs=[gallery])
368
+
369
  # with gr.Row():
370
  # gr.Markdown("## Uniformer Segmentation")
371
  # with gr.Row():