tombetthauser commited on
Commit
5f04ab8
Β·
1 Parent(s): a8d9f33

Added ControlNet Canny Edges beta tab

Browse files
Files changed (1) hide show
  1. app.py +56 -1
app.py CHANGED
@@ -412,8 +412,63 @@ canny_interface = gr.Interface(fn=canny_process_image, inputs=[canny_input_image
412
 
413
 
414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  # ----- Launch Tabs -----------------------------------------------------------------
416
 
417
- tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta, canny_interface], ["Artbots", "Advanced", "Beta", "Edges"])
418
  # tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta], ["Artbots", "Advanced", "Beta"])
419
  tabbed_interface.launch()
 
412
 
413
 
414
 
415
+ # ----- ControlNet Canny Edges -----------------------------------------------------------------
416
+
417
+ # import gradio as gr
418
+ # from PIL import Image
419
+ # import numpy as np
420
+ # import cv2
421
+
422
+ from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
423
+ from diffusers import UniPCMultistepScheduler
424
+ import torch
425
+
426
+ def controlnet_edges(canny_input_prompt, input_image, input_low_threshold, input_high_threshold, input_invert):
427
+ np_image = np.array(input_image)
428
+
429
+ output_image = input_image
430
+ numpy_image = np.array(output_image)
431
+
432
+ low_threshold = 80
433
+ high_threshold = 100
434
+ canny_1 = cv2.Canny(numpy_image, input_low_threshold, input_high_threshold)
435
+ canny_1 = canny_1[:, :, None]
436
+ canny_1 = np.concatenate([canny_1, canny_1, canny_1], axis=2)
437
+ if input_invert:
438
+ canny_1 = 255 - canny_1
439
+
440
+ canny_2 = Image.fromarray(canny_1)
441
+
442
+ prompt = canny_input_prompt
443
+ generator = torch.Generator(device="cpu").manual_seed(2)
444
+
445
+ output_image = controlnet_pipe(
446
+ prompt,
447
+ canny_2,
448
+ negative_prompt="monochrome, lowres, bad anatomy, worst quality, low quality",
449
+ generator=generator,
450
+ num_inference_steps=20,
451
+ )
452
+
453
+ return output_image[0][0]
454
+
455
+
456
+ canny_input_prompt = gr.inputs.Textbox(label="Enter a single word or phrase")
457
+ canny_input_image = gr.inputs.Image()
458
+ canny_input_low_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Lower Threshold:", default=100)
459
+ canny_input_high_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Upper Threshold:", default=200)
460
+ canny_input_invert = gr.inputs.Checkbox(label="Invert Image")
461
+ canny_outputs = gr.outputs.Image(type="pil")
462
+
463
+ # make and launch the gradio app...
464
+ controlnet_canny_interface = gr.Interface(fn=controlnet_edges, inputs=[canny_input_prompt, canny_input_image, canny_input_low_threshold, canny_input_high_threshold, canny_input_invert], outputs=canny_outputs, title='Canny Edge Tracing', allow_flagging='never')
465
+ controlnet_canny_interface.launch()
466
+
467
+
468
+
469
+
470
  # ----- Launch Tabs -----------------------------------------------------------------
471
 
472
+ tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta, canny_interface, controlnet_canny_interface], ["Artbots", "Advanced", "Beta", "Edges", "ControlNet"])
473
  # tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta], ["Artbots", "Advanced", "Beta"])
474
  tabbed_interface.launch()