dvir-bria commited on
Commit
3638fca
1 Parent(s): 6852b3e

Update app.py

Browse files

resize to 1024x1024
conditioning scale to 1.0

Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -5,13 +5,14 @@ import torch
5
  import numpy as np
6
  import cv2
7
  import gradio as gr
 
8
  # from huggingface_hub import login
9
  # login()
10
 
11
- controlnet_conditioning_scale = 0.5 # recommended for good generalization
12
 
13
  controlnet = ControlNetModel.from_pretrained(
14
- "briaai/ControlNet-Canny", # "diffusers/controlnet-canny-sdxl-1.0", #
15
  torch_dtype=torch.float16
16
  )
17
 
@@ -25,6 +26,15 @@ pipe.enable_model_cpu_offload()
25
  low_threshold = 100
26
  high_threshold = 200
27
 
 
 
 
 
 
 
 
 
 
28
  def get_canny_filter(image):
29
 
30
  if not isinstance(image, np.ndarray):
@@ -37,6 +47,9 @@ def get_canny_filter(image):
37
  return canny_image
38
 
39
  def process(input_image, prompt):
 
 
 
40
  canny_image = get_canny_filter(input_image)
41
  images = pipe(
42
  prompt,image=canny_image, controlnet_conditioning_scale=controlnet_conditioning_scale,
 
5
  import numpy as np
6
  import cv2
7
  import gradio as gr
8
+ from torchvision import transforms
9
  # from huggingface_hub import login
10
  # login()
11
 
12
+ controlnet_conditioning_scale = 1.0
13
 
14
  controlnet = ControlNetModel.from_pretrained(
15
+ "briaai/ControlNet-Canny",
16
  torch_dtype=torch.float16
17
  )
18
 
 
26
  low_threshold = 100
27
  high_threshold = 200
28
 
29
+ def resize_image(image):
30
+ current_size = image.size
31
+ if current_size[0] > current_size[1]:
32
+ center_cropped_image = transforms.functional.center_crop(image, (current_size[1], current_size[1]))
33
+ else:
34
+ center_cropped_image = transforms.functional.center_crop(image, (current_size[0], current_size[0]))
35
+ resized_image = transforms.functional.resize(center_cropped_image, (1024, 1024))
36
+ return resized_image
37
+
38
  def get_canny_filter(image):
39
 
40
  if not isinstance(image, np.ndarray):
 
47
  return canny_image
48
 
49
  def process(input_image, prompt):
50
+ # resize input_image to 1024x1024
51
+ input_image = resize_image(input_image)
52
+
53
  canny_image = get_canny_filter(input_image)
54
  images = pipe(
55
  prompt,image=canny_image, controlnet_conditioning_scale=controlnet_conditioning_scale,