Spaces:
Running
on
Zero
Running
on
Zero
tori29umai
commited on
Commit
•
543d5ec
1
Parent(s):
0aa210d
Update app.py
Browse files
app.py
CHANGED
@@ -5,10 +5,8 @@ from diffusers import ControlNetModel, StableDiffusionXLControlNetImg2ImgPipelin
|
|
5 |
from PIL import Image
|
6 |
import os
|
7 |
import time
|
8 |
-
|
9 |
from utils.dl_utils import dl_cn_model, dl_cn_config, dl_tagger_model, dl_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 |
|
@@ -58,7 +56,7 @@ def predict(input_image_path, prompt, negative_prompt, controlnet_scale):
|
|
58 |
control_image=resize_image,
|
59 |
strength=1.0,
|
60 |
prompt=prompt,
|
61 |
-
negative_prompt
|
62 |
controlnet_conditioning_scale=float(controlnet_scale),
|
63 |
generator=generator,
|
64 |
num_inference_steps=30,
|
@@ -73,8 +71,7 @@ class Img2Img:
|
|
73 |
self.demo = self.layout()
|
74 |
self.tagger_model = None
|
75 |
self.input_image_path = None
|
76 |
-
self.
|
77 |
-
|
78 |
|
79 |
def process_prompt_analysis(self, input_image_path):
|
80 |
if self.tagger_model is None:
|
@@ -83,10 +80,9 @@ class Img2Img:
|
|
83 |
prompt = remove_color(tags)
|
84 |
execute_tags = ["realistic", "nose", "asian"]
|
85 |
prompt = execute_prompt(execute_tags, prompt)
|
86 |
-
prompt = remove_duplicates(prompt)
|
87 |
return prompt
|
88 |
|
89 |
-
|
90 |
def layout(self):
|
91 |
css = """
|
92 |
#intro{
|
@@ -99,18 +95,28 @@ class Img2Img:
|
|
99 |
with gr.Row():
|
100 |
with gr.Column():
|
101 |
self.input_image_path = gr.Image(label="Input image", type='filepath')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
self.prompt = gr.Textbox(label="Prompt", lines=3)
|
103 |
self.negative_prompt = gr.Textbox(label="Negative prompt", lines=3, value="nose, asian, realistic, lowres, error, extra digit, fewer digits, cropped, worst quality,low quality, normal quality, jpeg artifacts, blurry")
|
104 |
prompt_analysis_button = gr.Button("Prompt analysis")
|
105 |
-
self.controlnet_scale = gr.Slider(minimum=0.4, maximum=1.0, value=0.55, step=0.01, label="
|
106 |
generate_button = gr.Button(value="Generate", variant="primary")
|
|
|
107 |
with gr.Column():
|
108 |
self.output_image = gr.Image(type="pil", label="Output image")
|
109 |
|
110 |
prompt_analysis_button.click(
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
)
|
115 |
|
116 |
generate_button.click(
|
@@ -120,6 +126,12 @@ class Img2Img:
|
|
120 |
)
|
121 |
return demo
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
img2img = Img2Img()
|
124 |
img2img.demo.queue()
|
125 |
img2img.demo.launch(share=True)
|
|
|
5 |
from PIL import Image
|
6 |
import os
|
7 |
import time
|
|
|
8 |
from utils.dl_utils import dl_cn_model, dl_cn_config, dl_tagger_model, dl_lora_model
|
9 |
+
from utils.image_utils import resize_image_aspect_ratio, base_generation, background_removal
|
|
|
10 |
from utils.prompt_utils import execute_prompt, remove_color, remove_duplicates
|
11 |
from utils.tagger import modelLoad, analysis
|
12 |
|
|
|
56 |
control_image=resize_image,
|
57 |
strength=1.0,
|
58 |
prompt=prompt,
|
59 |
+
negative_prompt=negative_prompt,
|
60 |
controlnet_conditioning_scale=float(controlnet_scale),
|
61 |
generator=generator,
|
62 |
num_inference_steps=30,
|
|
|
71 |
self.demo = self.layout()
|
72 |
self.tagger_model = None
|
73 |
self.input_image_path = None
|
74 |
+
self.bg_removed_image = None
|
|
|
75 |
|
76 |
def process_prompt_analysis(self, input_image_path):
|
77 |
if self.tagger_model is None:
|
|
|
80 |
prompt = remove_color(tags)
|
81 |
execute_tags = ["realistic", "nose", "asian"]
|
82 |
prompt = execute_prompt(execute_tags, prompt)
|
83 |
+
prompt = remove_duplicates(prompt)
|
84 |
return prompt
|
85 |
|
|
|
86 |
def layout(self):
|
87 |
css = """
|
88 |
#intro{
|
|
|
95 |
with gr.Row():
|
96 |
with gr.Column():
|
97 |
self.input_image_path = gr.Image(label="Input image", type='filepath')
|
98 |
+
self.bg_removed_image = gr.Image(label="Background Removed Image")
|
99 |
+
|
100 |
+
# 自動背景除去トリガー
|
101 |
+
self.input_image_path.change(
|
102 |
+
fn=self.auto_background_removal,
|
103 |
+
inputs=[self.input_image_path],
|
104 |
+
outputs=[self.bg_removed_image]
|
105 |
+
)
|
106 |
+
|
107 |
self.prompt = gr.Textbox(label="Prompt", lines=3)
|
108 |
self.negative_prompt = gr.Textbox(label="Negative prompt", lines=3, value="nose, asian, realistic, lowres, error, extra digit, fewer digits, cropped, worst quality,low quality, normal quality, jpeg artifacts, blurry")
|
109 |
prompt_analysis_button = gr.Button("Prompt analysis")
|
110 |
+
self.controlnet_scale = gr.Slider(minimum=0.4, maximum=1.0, value=0.55, step=0.01, label="Photo fidelity")
|
111 |
generate_button = gr.Button(value="Generate", variant="primary")
|
112 |
+
|
113 |
with gr.Column():
|
114 |
self.output_image = gr.Image(type="pil", label="Output image")
|
115 |
|
116 |
prompt_analysis_button.click(
|
117 |
+
fn=self.process_prompt_analysis,
|
118 |
+
inputs=[self.input_image_path],
|
119 |
+
outputs=self.prompt
|
120 |
)
|
121 |
|
122 |
generate_button.click(
|
|
|
126 |
)
|
127 |
return demo
|
128 |
|
129 |
+
def auto_background_removal(self, input_image_path):
|
130 |
+
if input_image_path is not None:
|
131 |
+
bg_removed_image = background_removal(input_image_path)
|
132 |
+
return bg_removed_image
|
133 |
+
return None
|
134 |
+
|
135 |
img2img = Img2Img()
|
136 |
img2img.demo.queue()
|
137 |
img2img.demo.launch(share=True)
|