tombetthauser commited on
Commit
3fdba19
Β·
1 Parent(s): 9f8acba

Add image rotation to controlnet

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -463,7 +463,7 @@ controlnet_pipe.scheduler = UniPCMultistepScheduler.from_config(controlnet_pipe.
463
  controlnet_pipe.enable_model_cpu_offload()
464
 
465
 
466
- def controlnet_edges(canny_input_prompt, input_image, input_low_threshold, input_high_threshold, input_invert, canny_input_seed):
467
  np_image = np.array(input_image)
468
 
469
  output_image = input_image
@@ -480,6 +480,11 @@ def controlnet_edges(canny_input_prompt, input_image, input_low_threshold, input
480
  canny_2 = Image.fromarray(canny_1)
481
  canny_1 = Image.fromarray(canny_1)
482
 
 
 
 
 
 
483
  input_width, input_height = canny_2.size
484
 
485
  limit_size = 768
@@ -533,6 +538,7 @@ with gr.Blocks() as canny_blocks_interface:
533
  canny_input_high_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Upper Threshold:", default=120)
534
  canny_input_seed = gr.Slider(0, 99999999999999, label="seed", dtype=int, value=random_seed, interactive=True, step=1)
535
  canny_input_invert = gr.inputs.Checkbox(label="Invert Image")
 
536
  with gr.Column():
537
  canny_input_image = gr.inputs.Image(label="input image")
538
  go_button = gr.Button('generate image')
@@ -541,7 +547,7 @@ with gr.Blocks() as canny_blocks_interface:
541
  canny_output_1 = gr.outputs.Image(type="pil", label="traced edges")
542
  with gr.Row():
543
  canny_output_2 = gr.outputs.Image(type="pil", label="final image")
544
- go_button.click(fn=controlnet_edges, inputs=[canny_input_prompt, canny_input_image, canny_input_low_threshold, canny_input_high_threshold, canny_input_invert, canny_input_seed], outputs=[canny_output_1, canny_output_2])
545
 
546
 
547
  # canny_blocks_interface.launch(debug=False)
@@ -605,15 +611,15 @@ with gr.Blocks() as canny_blocks_interface:
605
  # return output_image[0][0]
606
 
607
 
608
- canny_input_prompt = gr.inputs.Textbox(label="Enter a single word or phrase")
609
- canny_input_image = gr.inputs.Image()
610
- canny_input_low_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Lower Threshold:", default=100)
611
- canny_input_high_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Upper Threshold:", default=200)
612
- canny_input_invert = gr.inputs.Checkbox(label="Invert Image")
613
- canny_outputs = gr.outputs.Image(type="pil")
614
 
615
  # make and launch the gradio app...
616
- 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')
617
  # controlnet_canny_interface.launch()
618
 
619
 
 
463
  controlnet_pipe.enable_model_cpu_offload()
464
 
465
 
466
+ def controlnet_edges(canny_input_prompt, input_image, input_low_threshold, input_high_threshold, input_invert, canny_input_seed, canny_input_rotate):
467
  np_image = np.array(input_image)
468
 
469
  output_image = input_image
 
480
  canny_2 = Image.fromarray(canny_1)
481
  canny_1 = Image.fromarray(canny_1)
482
 
483
+ if int(canny_input_rotate) > 0:
484
+ canny_rotation = 360 - int(canny_input_rotate)
485
+ canny_2 = canny_2.rotate(canny_rotation, resample=Image.BICUBIC)
486
+ canny_1 = canny_1.rotate(canny_rotation, resample=Image.BICUBIC)
487
+
488
  input_width, input_height = canny_2.size
489
 
490
  limit_size = 768
 
538
  canny_input_high_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Upper Threshold:", default=120)
539
  canny_input_seed = gr.Slider(0, 99999999999999, label="seed", dtype=int, value=random_seed, interactive=True, step=1)
540
  canny_input_invert = gr.inputs.Checkbox(label="Invert Image")
541
+ canny_input_rotate = gr.Dropdown([0, 90, 180, 270], label="rotate image (for smartphones)")
542
  with gr.Column():
543
  canny_input_image = gr.inputs.Image(label="input image")
544
  go_button = gr.Button('generate image')
 
547
  canny_output_1 = gr.outputs.Image(type="pil", label="traced edges")
548
  with gr.Row():
549
  canny_output_2 = gr.outputs.Image(type="pil", label="final image")
550
+ go_button.click(fn=controlnet_edges, inputs=[canny_input_prompt, canny_input_image, canny_input_low_threshold, canny_input_high_threshold, canny_input_invert, canny_input_seed, canny_input_rotate], outputs=[canny_output_1, canny_output_2])
551
 
552
 
553
  # canny_blocks_interface.launch(debug=False)
 
611
  # return output_image[0][0]
612
 
613
 
614
+ # canny_input_prompt = gr.inputs.Textbox(label="Enter a single word or phrase")
615
+ # canny_input_image = gr.inputs.Image()
616
+ # canny_input_low_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Lower Threshold:", default=100)
617
+ # canny_input_high_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Upper Threshold:", default=200)
618
+ # canny_input_invert = gr.inputs.Checkbox(label="Invert Image")
619
+ # canny_outputs = gr.outputs.Image(type="pil")
620
 
621
  # make and launch the gradio app...
622
+ # 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')
623
  # controlnet_canny_interface.launch()
624
 
625