Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -40,7 +40,7 @@ v = torch.load(f"{models_path}/files/V.pt", map_location=torch.device('cpu')).bf
|
|
40 |
proj = torch.load(f"{models_path}/files/proj_1000pc.pt", map_location=torch.device('cpu')).bfloat16().to(device)
|
41 |
df = torch.load(f"{models_path}/files/identity_df.pt")
|
42 |
weight_dimensions = torch.load(f"{models_path}/files/weight_dimensions.pt")
|
43 |
-
pinverse = torch.load(f"{models_path}/files/pinverse_1000pc.pt", map_location=torch.device('cpu'))
|
44 |
|
45 |
unet, vae, text_encoder, tokenizer, noise_scheduler = load_models(device)
|
46 |
|
@@ -109,7 +109,7 @@ def inference( prompt, negative_prompt, guidance_scale, ddim_steps, seed):
|
|
109 |
@torch.no_grad()
|
110 |
@spaces.GPU
|
111 |
def edit_inference(prompt, negative_prompt, guidance_scale, ddim_steps, seed, start_noise, a1, a2, a3, a4):
|
112 |
-
|
113 |
global device
|
114 |
#global generator
|
115 |
global unet
|
@@ -207,7 +207,6 @@ def sample_then_run():
|
|
207 |
|
208 |
#@spaces.GPU
|
209 |
def start_items():
|
210 |
-
device = "cpu"
|
211 |
print("Starting items")
|
212 |
global young
|
213 |
global pointy
|
@@ -221,7 +220,6 @@ def start_items():
|
|
221 |
young = debias(young, "No_Beard", df, pinverse, device)
|
222 |
young = debias(young, "Mustache", df, pinverse, device)
|
223 |
|
224 |
-
|
225 |
pointy = get_direction(df, "Pointy_Nose", pinverse, 1000, device)
|
226 |
pointy = debias(pointy, "Young", df, pinverse, device)
|
227 |
pointy = debias(pointy, "Male", df, pinverse, device)
|
@@ -229,16 +227,13 @@ def start_items():
|
|
229 |
pointy = debias(pointy, "Chubby", df, pinverse, device)
|
230 |
pointy = debias(pointy, "Heavy_Makeup", df, pinverse, device)
|
231 |
|
232 |
-
|
233 |
-
|
234 |
wavy = get_direction(df, "Wavy_Hair", pinverse, 1000, device)
|
235 |
wavy = debias(wavy, "Young", df, pinverse, device)
|
236 |
wavy = debias(wavy, "Male", df, pinverse, device)
|
237 |
wavy = debias(wavy, "Pointy_Nose", df, pinverse, device)
|
238 |
wavy = debias(wavy, "Chubby", df, pinverse, device)
|
239 |
wavy = debias(wavy, "Heavy_Makeup", df, pinverse, device)
|
240 |
-
|
241 |
-
|
242 |
thick = get_direction(df, "Bushy_Eyebrows", pinverse, 1000, device)
|
243 |
thick = debias(thick, "Male", df, pinverse, device)
|
244 |
thick = debias(thick, "Young", df, pinverse, device)
|
@@ -254,8 +249,6 @@ def start_items():
|
|
254 |
thick = debias(thick, "Pale_Skin", df, pinverse, device)
|
255 |
thick = debias(thick, "Heavy_Makeup", df, pinverse, device)
|
256 |
|
257 |
-
start_items()
|
258 |
-
|
259 |
class CustomImageDataset(Dataset):
|
260 |
def __init__(self, images, transform=None):
|
261 |
self.images = images
|
@@ -488,11 +481,10 @@ with gr.Blocks(css="style.css") as demo:
|
|
488 |
|
489 |
|
490 |
sample.click(fn=sample_then_run, outputs=[input_image, file_output])
|
491 |
-
|
492 |
|
493 |
submit.click(
|
494 |
-
|
495 |
-
|
496 |
file_input.change(fn=file_upload, inputs=file_input, outputs = gallery)
|
497 |
|
498 |
|
|
|
40 |
proj = torch.load(f"{models_path}/files/proj_1000pc.pt", map_location=torch.device('cpu')).bfloat16().to(device)
|
41 |
df = torch.load(f"{models_path}/files/identity_df.pt")
|
42 |
weight_dimensions = torch.load(f"{models_path}/files/weight_dimensions.pt")
|
43 |
+
pinverse = torch.load(f"{models_path}/files/pinverse_1000pc.pt", map_location=torch.device('cpu')).bfloat16().to(device)
|
44 |
|
45 |
unet, vae, text_encoder, tokenizer, noise_scheduler = load_models(device)
|
46 |
|
|
|
109 |
@torch.no_grad()
|
110 |
@spaces.GPU
|
111 |
def edit_inference(prompt, negative_prompt, guidance_scale, ddim_steps, seed, start_noise, a1, a2, a3, a4):
|
112 |
+
start_items()
|
113 |
global device
|
114 |
#global generator
|
115 |
global unet
|
|
|
207 |
|
208 |
#@spaces.GPU
|
209 |
def start_items():
|
|
|
210 |
print("Starting items")
|
211 |
global young
|
212 |
global pointy
|
|
|
220 |
young = debias(young, "No_Beard", df, pinverse, device)
|
221 |
young = debias(young, "Mustache", df, pinverse, device)
|
222 |
|
|
|
223 |
pointy = get_direction(df, "Pointy_Nose", pinverse, 1000, device)
|
224 |
pointy = debias(pointy, "Young", df, pinverse, device)
|
225 |
pointy = debias(pointy, "Male", df, pinverse, device)
|
|
|
227 |
pointy = debias(pointy, "Chubby", df, pinverse, device)
|
228 |
pointy = debias(pointy, "Heavy_Makeup", df, pinverse, device)
|
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 |
+
|
|
|
237 |
thick = get_direction(df, "Bushy_Eyebrows", pinverse, 1000, device)
|
238 |
thick = debias(thick, "Male", df, pinverse, device)
|
239 |
thick = debias(thick, "Young", df, pinverse, device)
|
|
|
249 |
thick = debias(thick, "Pale_Skin", df, pinverse, device)
|
250 |
thick = debias(thick, "Heavy_Makeup", df, pinverse, device)
|
251 |
|
|
|
|
|
252 |
class CustomImageDataset(Dataset):
|
253 |
def __init__(self, images, transform=None):
|
254 |
self.images = images
|
|
|
481 |
|
482 |
|
483 |
sample.click(fn=sample_then_run, outputs=[input_image, file_output])
|
|
|
484 |
|
485 |
submit.click(
|
486 |
+
fn=edit_inference, inputs=[prompt, negative_prompt, cfg, steps, seed, injection_step, a1, a2, a3, a4], outputs=[gallery]
|
487 |
+
)
|
488 |
file_input.change(fn=file_upload, inputs=file_input, outputs = gallery)
|
489 |
|
490 |
|