Spaces:
Sleeping
Sleeping
Commit
路
5836c22
1
Parent(s):
e71b11b
app.py
Browse files- utils/utils.py +28 -38
utils/utils.py
CHANGED
|
@@ -9,24 +9,20 @@ import numpy as np
|
|
| 9 |
import cv2
|
| 10 |
|
| 11 |
def load_cn_model(model_dir):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
) as bar:
|
| 27 |
-
for data in response.iter_content(chunk_size=1024):
|
| 28 |
-
size = f.write(data)
|
| 29 |
-
bar.update(size)
|
| 30 |
|
| 31 |
def load_cn_config(model_dir):
|
| 32 |
folder = model_dir
|
|
@@ -61,27 +57,21 @@ def load_tagger_model(model_dir):
|
|
| 61 |
|
| 62 |
|
| 63 |
def load_lora_model(model_dir):
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
unit_scale=True,
|
| 78 |
-
unit_divisor=1024,
|
| 79 |
-
) as bar:
|
| 80 |
-
for data in response.iter_content(chunk_size=1024):
|
| 81 |
-
size = f.write(data)
|
| 82 |
-
bar.update(size)
|
| 83 |
-
|
| 84 |
|
|
|
|
| 85 |
def resize_image_aspect_ratio(image):
|
| 86 |
# 鍏冦伄鐢诲儚銈点偆銈恒倰鍙栧緱
|
| 87 |
original_width, original_height = image.size
|
|
|
|
| 9 |
import cv2
|
| 10 |
|
| 11 |
def load_cn_model(model_dir):
|
| 12 |
+
folder = model_dir
|
| 13 |
+
file_name = 'diffusion_pytorch_model.safetensors'
|
| 14 |
+
url = " https://huggingface.co/2vXpSwA7/iroiro-lora/resolve/main/test_controlnet2/CN-anytest_v3-50000_fp16.safetensors"
|
| 15 |
+
file_path = os.path.join(folder, file_name)
|
| 16 |
+
if not os.path.exists(file_path):
|
| 17 |
+
response = requests.get(url, allow_redirects=True)
|
| 18 |
+
if response.status_code == 200:
|
| 19 |
+
with open(file_path, 'wb') as f:
|
| 20 |
+
f.write(response.content)
|
| 21 |
+
print(f'Downloaded {file_name}')
|
| 22 |
+
else:
|
| 23 |
+
print(f'Failed to download {file_name}')
|
| 24 |
+
else:
|
| 25 |
+
print(f'{file_name} already exists.')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
def load_cn_config(model_dir):
|
| 28 |
folder = model_dir
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
def load_lora_model(model_dir):
|
| 60 |
+
file_name = 'style-lineart_02.safetensors'
|
| 61 |
+
file_path = os.path.join(model_dir, file_name)
|
| 62 |
+
if not os.path.exists(file_path):
|
| 63 |
+
url = "https://huggingface.co/2vXpSwA7/iroiro-lora/resolve/main/test3/style-lineart_02.safetensors"
|
| 64 |
+
response = requests.get(url, allow_redirects=True)
|
| 65 |
+
if response.status_code == 200:
|
| 66 |
+
with open(file_path, 'wb') as f:
|
| 67 |
+
f.write(response.content)
|
| 68 |
+
print(f'Downloaded {file_name}')
|
| 69 |
+
else:
|
| 70 |
+
print(f'Failed to download {file_name}')
|
| 71 |
+
else:
|
| 72 |
+
print(f'{file_name} already exists.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
|
| 75 |
def resize_image_aspect_ratio(image):
|
| 76 |
# 鍏冦伄鐢诲儚銈点偆銈恒倰鍙栧緱
|
| 77 |
original_width, original_height = image.size
|