Update app.py
Browse files
app.py
CHANGED
|
@@ -99,8 +99,9 @@ def inference( prompt, negative_prompt, guidance_scale, ddim_steps, seed):
|
|
| 99 |
return [image]
|
| 100 |
|
| 101 |
|
|
|
|
| 102 |
@torch.no_grad()
|
| 103 |
-
def edit_inference(prompt, negative_prompt, guidance_scale, ddim_steps, seed, start_noise, a1, a2, a3):
|
| 104 |
|
| 105 |
global device
|
| 106 |
global generator
|
|
@@ -111,13 +112,14 @@ def edit_inference(prompt, negative_prompt, guidance_scale, ddim_steps, seed, st
|
|
| 111 |
global noise_scheduler
|
| 112 |
global young
|
| 113 |
global pointy
|
| 114 |
-
global
|
|
|
|
| 115 |
|
| 116 |
original_weights = network.proj.clone()
|
| 117 |
|
| 118 |
|
| 119 |
-
edited_weights = original_weights+a1*young+a2*pointy+a3*
|
| 120 |
-
|
| 121 |
generator = generator.manual_seed(seed)
|
| 122 |
latents = torch.randn(
|
| 123 |
(1, unet.in_channels, 512 // 8, 512 // 8),
|
|
@@ -204,20 +206,43 @@ def sample_then_run():
|
|
| 204 |
#directions
|
| 205 |
global young
|
| 206 |
global pointy
|
| 207 |
-
global
|
|
|
|
|
|
|
| 208 |
young = get_direction(df, "Young", pinverse, 1000, device)
|
| 209 |
young = debias(young, "Male", df, pinverse, device)
|
|
|
|
|
|
|
|
|
|
| 210 |
young_max = torch.max(proj@young[0]/(torch.norm(young))**2).item()
|
| 211 |
young_min = torch.min(proj@young[0]/(torch.norm(young))**2).item()
|
| 212 |
|
| 213 |
pointy = get_direction(df, "Pointy_Nose", pinverse, 1000, device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
pointy_max = torch.max(proj@pointy[0]/(torch.norm(pointy))**2).item()
|
| 215 |
pointy_min = torch.min(proj@pointy[0]/(torch.norm(pointy))**2).item()
|
| 216 |
|
| 217 |
-
bags = get_direction(df, "Bags_Under_Eyes", pinverse, 1000, device)
|
| 218 |
-
bags_max = torch.max(proj@bags[0]/(torch.norm(bags))**2).item()
|
| 219 |
-
bags_min = torch.min(proj@bags[0]/(torch.norm(bags))**2).item()
|
| 220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
|
| 223 |
intro = """
|
|
@@ -252,9 +277,11 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 252 |
value="sks person")
|
| 253 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, cartoon", value="low quality, blurry, unfinished, cartoon")
|
| 254 |
with gr.Row():
|
| 255 |
-
a1 = gr.Slider(label="Young", value=0, step=
|
| 256 |
-
a2 = gr.Slider(label="Pointy Nose", value=0, step=
|
| 257 |
-
|
|
|
|
|
|
|
| 258 |
|
| 259 |
|
| 260 |
with gr.Accordion("Advanced Options", open=False):
|
|
@@ -268,8 +295,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 268 |
|
| 269 |
submit = gr.Button("Submit")
|
| 270 |
|
| 271 |
-
|
| 272 |
-
|
| 273 |
|
| 274 |
|
| 275 |
|
|
@@ -278,7 +305,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 278 |
|
| 279 |
|
| 280 |
submit.click(fn=edit_inference,
|
| 281 |
-
inputs=[prompt, negative_prompt, cfg, steps, seed, injection_step, a1, a2, a3],
|
| 282 |
outputs=gallery2)
|
| 283 |
|
| 284 |
|
|
@@ -289,6 +316,5 @@ with gr.Blocks(css="style.css") as demo:
|
|
| 289 |
demo.launch(share=True)
|
| 290 |
|
| 291 |
|
| 292 |
-
|
| 293 |
|
| 294 |
|
|
|
|
| 99 |
return [image]
|
| 100 |
|
| 101 |
|
| 102 |
+
|
| 103 |
@torch.no_grad()
|
| 104 |
+
def edit_inference(prompt, negative_prompt, guidance_scale, ddim_steps, seed, start_noise, a1, a2, a3, a4):
|
| 105 |
|
| 106 |
global device
|
| 107 |
global generator
|
|
|
|
| 112 |
global noise_scheduler
|
| 113 |
global young
|
| 114 |
global pointy
|
| 115 |
+
global wavy
|
| 116 |
+
global large
|
| 117 |
|
| 118 |
original_weights = network.proj.clone()
|
| 119 |
|
| 120 |
|
| 121 |
+
edited_weights = original_weights+a1*1e6*young+a2*1e6*pointy+a3*1e6*wavy+a4*2e6*large
|
| 122 |
+
|
| 123 |
generator = generator.manual_seed(seed)
|
| 124 |
latents = torch.randn(
|
| 125 |
(1, unet.in_channels, 512 // 8, 512 // 8),
|
|
|
|
| 206 |
#directions
|
| 207 |
global young
|
| 208 |
global pointy
|
| 209 |
+
global wavy
|
| 210 |
+
global large
|
| 211 |
+
|
| 212 |
young = get_direction(df, "Young", pinverse, 1000, device)
|
| 213 |
young = debias(young, "Male", df, pinverse, device)
|
| 214 |
+
young = debias(young, "Pointy_Nose", df, pinverse, device)
|
| 215 |
+
young = debias(young, "Wavy_Hair", df, pinverse, device)
|
| 216 |
+
young = debias(young, "Chubby", df, pinverse, device)
|
| 217 |
young_max = torch.max(proj@young[0]/(torch.norm(young))**2).item()
|
| 218 |
young_min = torch.min(proj@young[0]/(torch.norm(young))**2).item()
|
| 219 |
|
| 220 |
pointy = get_direction(df, "Pointy_Nose", pinverse, 1000, device)
|
| 221 |
+
pointy = debias(pointy, "Young", df, pinverse, device)
|
| 222 |
+
pointy = debias(pointy, "Male", df, pinverse, device)
|
| 223 |
+
pointy = debias(pointy, "Wavy_Hair", df, pinverse, device)
|
| 224 |
+
pointy = debias(pointy, "Chubby", df, pinverse, device)
|
| 225 |
+
pointy = debias(pointy, "Heavy_Makeup", df, pinverse, device)
|
| 226 |
pointy_max = torch.max(proj@pointy[0]/(torch.norm(pointy))**2).item()
|
| 227 |
pointy_min = torch.min(proj@pointy[0]/(torch.norm(pointy))**2).item()
|
| 228 |
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
+
wavy = get_direction(df, "Wavy_Hair", pinverse, 1000, device)
|
| 231 |
+
wavy = debias(wavy, "Young", df, pinverse, device)
|
| 232 |
+
wavy = debias(wavy, "Male", df, pinverse, device)
|
| 233 |
+
wavy = debias(wavy, "Pointy_Nose", df, pinverse, device)
|
| 234 |
+
wavy = debias(wavy, "Chubby", df, pinverse, device)
|
| 235 |
+
wavy = debias(wavy, "Heavy_Makeup", df, pinverse, device)
|
| 236 |
+
wavy_max = torch.max(proj@wavy[0]/(torch.norm(wavy))**2).item()
|
| 237 |
+
wavy_min = torch.min(proj@wavy[0]/(torch.norm(wavy))**2).item()
|
| 238 |
+
|
| 239 |
+
large = get_direction(df, "Chubby", pinverse, 1000, device)
|
| 240 |
+
large = debias(large, "Male", df, pinverse, device)
|
| 241 |
+
large = debias(large, "Young", df, pinverse, device)
|
| 242 |
+
large = debias(large, "Pointy_Nose", df, pinverse, device)
|
| 243 |
+
large = debias(large, "Wavy_Hair", df, pinverse, device)
|
| 244 |
+
large_max = torch.max(proj@large[0]/(torch.norm(large))**2).item()
|
| 245 |
+
large_min = torch.min(proj@large[0]/(torch.norm(large))**2).item()
|
| 246 |
|
| 247 |
|
| 248 |
intro = """
|
|
|
|
| 277 |
value="sks person")
|
| 278 |
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality, blurry, unfinished, cartoon", value="low quality, blurry, unfinished, cartoon")
|
| 279 |
with gr.Row():
|
| 280 |
+
a1 = gr.Slider(label="+Young", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
| 281 |
+
a2 = gr.Slider(label="+Pointy Nose", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
| 282 |
+
with gr.Row():
|
| 283 |
+
a3 = gr.Slider(label="+Curly Hair", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
| 284 |
+
a4 = gr.Slider(label="+Large", value=0, step=0.001, minimum=-1, maximum=1, interactive=True)
|
| 285 |
|
| 286 |
|
| 287 |
with gr.Accordion("Advanced Options", open=False):
|
|
|
|
| 295 |
|
| 296 |
submit = gr.Button("Submit")
|
| 297 |
|
| 298 |
+
|
| 299 |
+
|
| 300 |
|
| 301 |
|
| 302 |
|
|
|
|
| 305 |
|
| 306 |
|
| 307 |
submit.click(fn=edit_inference,
|
| 308 |
+
inputs=[prompt, negative_prompt, cfg, steps, seed, injection_step, a1, a2, a3, a4],
|
| 309 |
outputs=gallery2)
|
| 310 |
|
| 311 |
|
|
|
|
| 316 |
demo.launch(share=True)
|
| 317 |
|
| 318 |
|
|
|
|
| 319 |
|
| 320 |
|