TalHach61 commited on
Commit
018a675
1 Parent(s): 2714820

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py CHANGED
@@ -10,6 +10,27 @@ import gradio as gr
10
  from torchvision import transforms
11
  from controlnet_aux import OpenposeDetector
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  openpose = OpenposeDetector.from_pretrained('lllyasviel/ControlNet')
15
 
@@ -37,7 +58,22 @@ pipe.scheduler = EulerAncestralDiscreteScheduler(
37
  # pipe.enable_xformers_memory_efficient_attention()
38
  pipe.force_zeros_for_empty_prompt = False
39
 
 
 
 
 
 
 
 
 
 
40
  def resize_image(image):
 
 
 
 
 
 
41
  image = image.convert('RGB')
42
  current_size = image.size
43
  if current_size[0] > current_size[1]:
 
10
  from torchvision import transforms
11
  from controlnet_aux import OpenposeDetector
12
 
13
+ ratios_map = {
14
+ 0.5:{"width":704,"height":1408},
15
+ 0.57:{"width":768,"height":1344},
16
+ 0.68:{"width":832,"height":1216},
17
+ 0.72:{"width":832,"height":1152},
18
+ 0.78:{"width":896,"height":1152},
19
+ 0.82:{"width":896,"height":1088},
20
+ 0.88:{"width":960,"height":1088},
21
+ 0.94:{"width":960,"height":1024},
22
+ 1.00:{"width":1024,"height":1024},
23
+ 1.13:{"width":1088,"height":960},
24
+ 1.21:{"width":1088,"height":896},
25
+ 1.29:{"width":1152,"height":896},
26
+ 1.38:{"width":1152,"height":832},
27
+ 1.46:{"width":1216,"height":832},
28
+ 1.67:{"width":1280,"height":768},
29
+ 1.75:{"width":1344,"height":768},
30
+ 2.00:{"width":1408,"height":704}
31
+ }
32
+ ratios = np.array(list(ratios_map.keys()))
33
+
34
 
35
  openpose = OpenposeDetector.from_pretrained('lllyasviel/ControlNet')
36
 
 
58
  # pipe.enable_xformers_memory_efficient_attention()
59
  pipe.force_zeros_for_empty_prompt = False
60
 
61
+ def get_size(init_image):
62
+ w,h=init_image.size
63
+ curr_ratio = w/h
64
+ ind = np.argmin(np.abs(curr_ratio-ratios))
65
+ ratio = ratios[ind]
66
+ chosen_ratio = ratios_map[ratio]
67
+ w,h = chosen_ratio['width'], chosen_ratio['height']
68
+ return w,h
69
+
70
  def resize_image(image):
71
+ image = image.convert('RGB')
72
+ w,h = get_size(image)
73
+ resized_image = image.resize((w, h))
74
+ return resized_image
75
+
76
+ def resize_image_old(image):
77
  image = image.convert('RGB')
78
  current_size = image.size
79
  if current_size[0] > current_size[1]: