Spaces:
Paused
Paused
Commit
路
c689a76
1
Parent(s):
48b19ab
app.py
Browse files- app.py +10 -2
- requirements.txt +3 -3
- utils/utils.py +22 -0
app.py
CHANGED
|
@@ -16,7 +16,7 @@ import os
|
|
| 16 |
import time
|
| 17 |
import numpy as np
|
| 18 |
|
| 19 |
-
from utils.utils import load_cn_model, load_cn_config, load_tagger_model, resize_image_aspect_ratio, base_generation
|
| 20 |
from utils.prompt_analysis import PromptAnalysis
|
| 21 |
|
| 22 |
path = os.getcwd()
|
|
@@ -24,10 +24,13 @@ cn_dir = f"{path}/controlnet"
|
|
| 24 |
os.makedirs(cn_dir)
|
| 25 |
tagger_dir = f"{path}/tagger"
|
| 26 |
os.mkdir(tagger_dir)
|
|
|
|
|
|
|
| 27 |
|
| 28 |
load_cn_model(cn_dir)
|
| 29 |
load_cn_config(cn_dir)
|
| 30 |
load_tagger_model(tagger_dir)
|
|
|
|
| 31 |
|
| 32 |
IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
|
| 33 |
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
|
@@ -49,11 +52,16 @@ pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
|
| 49 |
model,
|
| 50 |
controlnet=controlnet,
|
| 51 |
torch_dtype=dtype,
|
| 52 |
-
variant="fp16",
|
| 53 |
use_safetensors=True,
|
| 54 |
scheduler=scheduler,
|
| 55 |
)
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
compel = Compel(
|
| 58 |
tokenizer=[pipe.tokenizer, pipe.tokenizer_2],
|
| 59 |
text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
|
|
|
|
| 16 |
import time
|
| 17 |
import numpy as np
|
| 18 |
|
| 19 |
+
from utils.utils import load_cn_model, load_cn_config, load_tagger_model, load_lora_model, resize_image_aspect_ratio, base_generation
|
| 20 |
from utils.prompt_analysis import PromptAnalysis
|
| 21 |
|
| 22 |
path = os.getcwd()
|
|
|
|
| 24 |
os.makedirs(cn_dir)
|
| 25 |
tagger_dir = f"{path}/tagger"
|
| 26 |
os.mkdir(tagger_dir)
|
| 27 |
+
lora_dir = f"{path}/lora"
|
| 28 |
+
os.mkdir(lora_dir)
|
| 29 |
|
| 30 |
load_cn_model(cn_dir)
|
| 31 |
load_cn_config(cn_dir)
|
| 32 |
load_tagger_model(tagger_dir)
|
| 33 |
+
load_lora_model(lora_dir)
|
| 34 |
|
| 35 |
IS_SPACES_ZERO = os.environ.get("SPACES_ZERO_GPU", "0") == "1"
|
| 36 |
IS_SPACE = os.environ.get("SPACE_ID", None) is not None
|
|
|
|
| 52 |
model,
|
| 53 |
controlnet=controlnet,
|
| 54 |
torch_dtype=dtype,
|
|
|
|
| 55 |
use_safetensors=True,
|
| 56 |
scheduler=scheduler,
|
| 57 |
)
|
| 58 |
|
| 59 |
+
pipe.load_lora_weights(
|
| 60 |
+
lora_dir,
|
| 61 |
+
weight_name="sdxl_BWLine.safetensors"
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
compel = Compel(
|
| 66 |
tokenizer=[pipe.tokenizer, pipe.tokenizer_2],
|
| 67 |
text_encoder=[pipe.text_encoder, pipe.text_encoder_2],
|
requirements.txt
CHANGED
|
@@ -19,6 +19,6 @@ hidiffusion==0.1.8
|
|
| 19 |
spaces
|
| 20 |
torch==2.2
|
| 21 |
controlnet-aux==0.0.9
|
| 22 |
-
onnx
|
| 23 |
-
onnxruntime
|
| 24 |
-
mediapipe
|
|
|
|
| 19 |
spaces
|
| 20 |
torch==2.2
|
| 21 |
controlnet-aux==0.0.9
|
| 22 |
+
onnx==1.16.1
|
| 23 |
+
onnxruntime==1.18.0
|
| 24 |
+
mediapipe==0.10.14
|
utils/utils.py
CHANGED
|
@@ -61,6 +61,28 @@ def load_tagger_model(model_dir):
|
|
| 61 |
print(f'{file} already exists.')
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
def resize_image_aspect_ratio(image):
|
| 65 |
# 鍏冦伄鐢诲儚銈点偆銈恒倰鍙栧緱
|
| 66 |
original_width, original_height = image.size
|
|
|
|
| 61 |
print(f'{file} already exists.')
|
| 62 |
|
| 63 |
|
| 64 |
+
def load_lora_model(model_dir):
|
| 65 |
+
folder = model_dir
|
| 66 |
+
file_name = 'sdxl_BWLine.safetensors'
|
| 67 |
+
url = "https://huggingface.co/tori29umai/lineart/resolve/main/sdxl_BWLine.safetensors"
|
| 68 |
+
|
| 69 |
+
file_path = os.path.join(folder, file_name)
|
| 70 |
+
if not os.path.exists(file_path):
|
| 71 |
+
response = requests.get(url, stream=True)
|
| 72 |
+
|
| 73 |
+
total_size = int(response.headers.get('content-length', 0))
|
| 74 |
+
with open(file_path, 'wb') as f, tqdm(
|
| 75 |
+
desc=file_name,
|
| 76 |
+
total=total_size,
|
| 77 |
+
unit='iB',
|
| 78 |
+
unit_scale=True,
|
| 79 |
+
unit_divisor=1024,
|
| 80 |
+
) as bar:
|
| 81 |
+
for data in response.iter_content(chunk_size=1024):
|
| 82 |
+
size = f.write(data)
|
| 83 |
+
bar.update(size)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
def resize_image_aspect_ratio(image):
|
| 87 |
# 鍏冦伄鐢诲儚銈点偆銈恒倰鍙栧緱
|
| 88 |
original_width, original_height = image.size
|