Spaces:
Running
on
Zero
Running
on
Zero
Commit
•
111970c
1
Parent(s):
e663a52
app.py
Browse files- app.py +1 -3
- utils/dl_utils.py +1 -1
- utils/image_utils.py +0 -44
app.py
CHANGED
@@ -12,8 +12,6 @@ from utils.image_utils import resize_image_aspect_ratio, base_generation
|
|
12 |
from utils.prompt_utils import execute_prompt, remove_color, remove_duplicates
|
13 |
from utils.tagger import modelLoad, analysis
|
14 |
|
15 |
-
|
16 |
-
|
17 |
path = os.getcwd()
|
18 |
cn_dir = f"{path}/controlnet"
|
19 |
tagger_dir = f"{path}/tagger"
|
@@ -99,7 +97,7 @@ class Img2Img:
|
|
99 |
with gr.Column():
|
100 |
self.input_image_path = gr.Image(label="input_image", type='filepath')
|
101 |
self.prompt = gr.Textbox(label="prompt", lines=3)
|
102 |
-
self.negative_prompt = gr.Textbox(label="negative_prompt", lines=3, value="lowres, error, extra digit, fewer digits, cropped, worst quality,low quality, normal quality, jpeg artifacts, blurry")
|
103 |
prompt_analysis_button = gr.Button("prompt_analysis")
|
104 |
self.controlnet_scale = gr.Slider(minimum=0.5, maximum=1.25, value=1.0, step=0.01, label="controlnet_scale")
|
105 |
generate_button = gr.Button("generate")
|
|
|
12 |
from utils.prompt_utils import execute_prompt, remove_color, remove_duplicates
|
13 |
from utils.tagger import modelLoad, analysis
|
14 |
|
|
|
|
|
15 |
path = os.getcwd()
|
16 |
cn_dir = f"{path}/controlnet"
|
17 |
tagger_dir = f"{path}/tagger"
|
|
|
97 |
with gr.Column():
|
98 |
self.input_image_path = gr.Image(label="input_image", type='filepath')
|
99 |
self.prompt = gr.Textbox(label="prompt", lines=3)
|
100 |
+
self.negative_prompt = gr.Textbox(label="negative_prompt", lines=3, value="sketch, lowres, error, extra digit, fewer digits, cropped, worst quality,low quality, normal quality, jpeg artifacts, blurry")
|
101 |
prompt_analysis_button = gr.Button("prompt_analysis")
|
102 |
self.controlnet_scale = gr.Slider(minimum=0.5, maximum=1.25, value=1.0, step=0.01, label="controlnet_scale")
|
103 |
generate_button = gr.Button("generate")
|
utils/dl_utils.py
CHANGED
@@ -33,7 +33,7 @@ def dl_cn_config(model_dir):
|
|
33 |
shutil.copy(config_path, file_path)
|
34 |
|
35 |
def dl_tagger_model(model_dir):
|
36 |
-
model_id = 'SmilingWolf/wd-
|
37 |
files = [
|
38 |
'config.json', 'model.onnx', 'selected_tags.csv', 'sw_jax_cv_config.json'
|
39 |
]
|
|
|
33 |
shutil.copy(config_path, file_path)
|
34 |
|
35 |
def dl_tagger_model(model_dir):
|
36 |
+
model_id = 'SmilingWolf/wd-vit-tagger-v3'
|
37 |
files = [
|
38 |
'config.json', 'model.onnx', 'selected_tags.csv', 'sw_jax_cv_config.json'
|
39 |
]
|
utils/image_utils.py
CHANGED
@@ -27,50 +27,6 @@ def canny_process(image_path, threshold1, threshold2):
|
|
27 |
return canny
|
28 |
|
29 |
|
30 |
-
def line_process(image_path, sigma, gamma):
|
31 |
-
def DoG_filter(image, kernel_size=0, sigma=1.0, k_sigma=2.0, gamma=1.5):
|
32 |
-
g1 = cv2.GaussianBlur(image, (kernel_size, kernel_size), sigma)
|
33 |
-
g2 = cv2.GaussianBlur(image, (kernel_size, kernel_size), sigma * k_sigma)
|
34 |
-
return g1 - gamma * g2
|
35 |
-
|
36 |
-
def XDoG_filter(image, kernel_size=0, sigma=1.4, k_sigma=1.6, epsilon=0, phi=10, gamma=0.98):
|
37 |
-
epsilon /= 255
|
38 |
-
dog = DoG_filter(image, kernel_size, sigma, k_sigma, gamma)
|
39 |
-
dog /= dog.max()
|
40 |
-
e = 1 + np.tanh(phi * (dog - epsilon))
|
41 |
-
e[e >= 1] = 1
|
42 |
-
return (e * 255).astype('uint8')
|
43 |
-
|
44 |
-
def binarize_image(image):
|
45 |
-
_, binarized = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
|
46 |
-
return binarized
|
47 |
-
|
48 |
-
def process_XDoG(image, kernel_size=0, sigma=1.4, k_sigma=1.6, epsilon=0, phi=10, gamma=0.98):
|
49 |
-
xdog_image = XDoG_filter(image, kernel_size, sigma, k_sigma, epsilon, phi, gamma)
|
50 |
-
binarized_image = binarize_image(xdog_image)
|
51 |
-
final_image_pil = Image.fromarray(binarized_image)
|
52 |
-
return final_image_pil
|
53 |
-
|
54 |
-
# 画像を開き、RGBA形式に変換して透過情報を保持
|
55 |
-
img = Image.open(image_path)
|
56 |
-
img = img.convert("RGBA")
|
57 |
-
|
58 |
-
canvas_image = Image.new('RGBA', img.size, (255, 255, 255, 255))
|
59 |
-
|
60 |
-
# 画像をキャンバスにペーストし、透過部分が白色になるように設定
|
61 |
-
canvas_image.paste(img, (0, 0), img)
|
62 |
-
|
63 |
-
# RGBAからRGBに変換し、透過部分を白色にする
|
64 |
-
image_pil = canvas_image.convert("RGB")
|
65 |
-
|
66 |
-
# OpenCVが扱える形式に変換
|
67 |
-
image_cv = cv2.cvtColor(np.array(image_pil), cv2.COLOR_RGB2BGR)
|
68 |
-
image_gray = cv2.cvtColor(image_cv, cv2.COLOR_BGR2GRAY)
|
69 |
-
inv_Line = process_XDoG(image_gray, kernel_size=0, sigma=sigma, k_sigma=1.6, epsilon=0, phi=10, gamma=gamma)
|
70 |
-
return inv_Line
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
def resize_image_aspect_ratio(image):
|
75 |
# 元の画像サイズを取得
|
76 |
original_width, original_height = image.size
|
|
|
27 |
return canny
|
28 |
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def resize_image_aspect_ratio(image):
|
31 |
# 元の画像サイズを取得
|
32 |
original_width, original_height = image.size
|