Spaces:
Running
on
Zero
Running
on
Zero
tori29umai
commited on
Commit
β’
240afb7
1
Parent(s):
774f35c
Update app.py
Browse files
app.py
CHANGED
@@ -74,9 +74,6 @@ def predict(lora_model, input_image_path, prompt, negative_prompt, controlnet_sc
|
|
74 |
# γγγ³γγηζ
|
75 |
prompt = "masterpiece, best quality, monochrome, greyscale, lineart, white background, " + prompt
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
execute_tags = ["realistic", "nose", "asian"]
|
81 |
prompt = execute_prompt(execute_tags, prompt)
|
82 |
prompt = remove_duplicates(prompt)
|
@@ -103,8 +100,6 @@ class Img2Img:
|
|
103 |
def __init__(self):
|
104 |
self.demo = self.layout()
|
105 |
self.tagger_model = None
|
106 |
-
self.input_image_path = None
|
107 |
-
self.bg_removed_image = None
|
108 |
|
109 |
def process_prompt_analysis(self, input_image_path):
|
110 |
if self.tagger_model is None:
|
@@ -116,6 +111,15 @@ class Img2Img:
|
|
116 |
prompt = remove_duplicates(prompt)
|
117 |
return prompt
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
def layout(self):
|
120 |
css = """
|
121 |
#intro{
|
@@ -128,32 +132,25 @@ class Img2Img:
|
|
128 |
with gr.Row():
|
129 |
with gr.Column():
|
130 |
# LoRAγ’γγ«ιΈζγγγγγγ¦γ³
|
131 |
-
self.lora_model = gr.Dropdown(label="Image Style",
|
132 |
self.input_image_path = gr.Image(label="Input image", type='filepath')
|
133 |
self.bg_removed_image_path = gr.Image(label="Background Removed Image", type='filepath')
|
134 |
-
|
135 |
-
#
|
136 |
self.input_image_path.change(
|
137 |
-
fn=self.
|
138 |
inputs=[self.input_image_path],
|
139 |
-
outputs=[self.bg_removed_image_path]
|
140 |
)
|
141 |
|
142 |
self.prompt = gr.Textbox(label="Prompt", lines=3)
|
143 |
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")
|
144 |
-
prompt_analysis_button = gr.Button("Prompt analysis")
|
145 |
self.controlnet_scale = gr.Slider(minimum=0.4, maximum=1.0, value=0.55, step=0.01, label="Photo fidelity")
|
146 |
generate_button = gr.Button(value="Generate", variant="primary")
|
147 |
|
148 |
with gr.Column():
|
149 |
self.output_image = gr.Image(type="pil", label="Output image")
|
150 |
|
151 |
-
prompt_analysis_button.click(
|
152 |
-
fn=self.process_prompt_analysis,
|
153 |
-
inputs=[self.bg_removed_image_path],
|
154 |
-
outputs=self.prompt
|
155 |
-
)
|
156 |
-
|
157 |
generate_button.click(
|
158 |
fn=predict,
|
159 |
inputs=[self.lora_model, self.bg_removed_image_path, self.prompt, self.negative_prompt, self.controlnet_scale],
|
@@ -161,12 +158,6 @@ class Img2Img:
|
|
161 |
)
|
162 |
return demo
|
163 |
|
164 |
-
def auto_background_removal(self, input_image_path):
|
165 |
-
if input_image_path is not None:
|
166 |
-
bg_removed_image = background_removal(input_image_path)
|
167 |
-
return bg_removed_image
|
168 |
-
return None
|
169 |
-
|
170 |
img2img = Img2Img()
|
171 |
img2img.demo.queue()
|
172 |
-
img2img.demo.launch(share=True)
|
|
|
74 |
# γγγ³γγηζ
|
75 |
prompt = "masterpiece, best quality, monochrome, greyscale, lineart, white background, " + prompt
|
76 |
|
|
|
|
|
|
|
77 |
execute_tags = ["realistic", "nose", "asian"]
|
78 |
prompt = execute_prompt(execute_tags, prompt)
|
79 |
prompt = remove_duplicates(prompt)
|
|
|
100 |
def __init__(self):
|
101 |
self.demo = self.layout()
|
102 |
self.tagger_model = None
|
|
|
|
|
103 |
|
104 |
def process_prompt_analysis(self, input_image_path):
|
105 |
if self.tagger_model is None:
|
|
|
111 |
prompt = remove_duplicates(prompt)
|
112 |
return prompt
|
113 |
|
114 |
+
def auto_background_removal_and_prompt_analysis(self, input_image_path):
|
115 |
+
if input_image_path is not None:
|
116 |
+
# θζ―ι€ε»
|
117 |
+
bg_removed_image = background_removal(input_image_path)
|
118 |
+
# γγγ³γγ解ζ
|
119 |
+
prompt = self.process_prompt_analysis(bg_removed_image)
|
120 |
+
return bg_removed_image, prompt
|
121 |
+
return None, ""
|
122 |
+
|
123 |
def layout(self):
|
124 |
css = """
|
125 |
#intro{
|
|
|
132 |
with gr.Row():
|
133 |
with gr.Column():
|
134 |
# LoRAγ’γγ«ιΈζγγγγγγ¦γ³
|
135 |
+
self.lora_model = gr.Dropdown(label="Image Style", choices=["ε°ε₯³ζΌ«η»ι’¨", "γγ¬γΌγ³"], value="ε°ε₯³ζΌ«η»ι’¨")
|
136 |
self.input_image_path = gr.Image(label="Input image", type='filepath')
|
137 |
self.bg_removed_image_path = gr.Image(label="Background Removed Image", type='filepath')
|
138 |
+
|
139 |
+
# θͺεθζ―ι€ε»γ¨γγγ³γγ解ζγγͺγ¬γΌ
|
140 |
self.input_image_path.change(
|
141 |
+
fn=self.auto_background_removal_and_prompt_analysis,
|
142 |
inputs=[self.input_image_path],
|
143 |
+
outputs=[self.bg_removed_image_path, self.prompt]
|
144 |
)
|
145 |
|
146 |
self.prompt = gr.Textbox(label="Prompt", lines=3)
|
147 |
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")
|
|
|
148 |
self.controlnet_scale = gr.Slider(minimum=0.4, maximum=1.0, value=0.55, step=0.01, label="Photo fidelity")
|
149 |
generate_button = gr.Button(value="Generate", variant="primary")
|
150 |
|
151 |
with gr.Column():
|
152 |
self.output_image = gr.Image(type="pil", label="Output image")
|
153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
generate_button.click(
|
155 |
fn=predict,
|
156 |
inputs=[self.lora_model, self.bg_removed_image_path, self.prompt, self.negative_prompt, self.controlnet_scale],
|
|
|
158 |
)
|
159 |
return demo
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
img2img = Img2Img()
|
162 |
img2img.demo.queue()
|
163 |
+
img2img.demo.launch(share=True)
|