tori29umai commited on
Commit
00c86c6
1 Parent(s): 6e57b9c
app.py CHANGED
@@ -6,7 +6,9 @@ from PIL import Image
6
  import os
7
  import time
8
 
9
- from utils.utils import load_cn_model, load_cn_config, load_tagger_model, load_lora_model, resize_image_aspect_ratio, base_generation
 
 
10
  from utils.prompt_utils import execute_prompt, remove_color, remove_duplicates
11
  from utils.tagger import modelLoad, analysis
12
 
 
6
  import os
7
  import time
8
 
9
+ from utils.dl_utils import load_cn_model, load_cn_config, load_tagger_model, load_lora_model
10
+ from utils.image_utils import resize_image_aspect_ratio, base_generation
11
+
12
  from utils.prompt_utils import execute_prompt, remove_color, remove_duplicates
13
  from utils.tagger import modelLoad, analysis
14
 
utils/{utils.py → dl_utils.py} RENAMED
File without changes
utils/image_utils.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import requests
4
+ from tqdm import tqdm
5
+ import shutil
6
+
7
+ from PIL import Image, ImageOps
8
+ import numpy as np
9
+ import cv2
10
+
11
+ def resize_image_aspect_ratio(image):
12
+ # 元の画像サイズを取得
13
+ original_width, original_height = image.size
14
+
15
+ # アスペクト比を計算
16
+ aspect_ratio = original_width / original_height
17
+
18
+ # 標準のアスペクト比サイズを定義
19
+ sizes = {
20
+ 1: (1024, 1024), # 正方形
21
+ 4/3: (1152, 896), # 横長画像
22
+ 3/2: (1216, 832),
23
+ 16/9: (1344, 768),
24
+ 21/9: (1568, 672),
25
+ 3/1: (1728, 576),
26
+ 1/4: (512, 2048), # 縦長画像
27
+ 1/3: (576, 1728),
28
+ 9/16: (768, 1344),
29
+ 2/3: (832, 1216),
30
+ 3/4: (896, 1152)
31
+ }
32
+
33
+ # 最も近いアスペクト比を見つける
34
+ closest_aspect_ratio = min(sizes.keys(), key=lambda x: abs(x - aspect_ratio))
35
+ target_width, target_height = sizes[closest_aspect_ratio]
36
+
37
+ # リサイズ処理
38
+ resized_image = image.resize((target_width, target_height), Image.LANCZOS)
39
+
40
+ return resized_image
41
+
42
+
43
+ def base_generation(size, color):
44
+ canvas = Image.new("RGBA", size, color)
45
+ return canvas