Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,7 @@ import model_build
|
|
9 |
|
10 |
|
11 |
psp = model_build.build_psp()
|
12 |
-
|
13 |
-
stylegan2_v2 = model_build.build_stylegan2(network_pkl = 'pretrained/ohayou_face2.pkl')
|
14 |
|
15 |
pretransform = transforms.Compose([
|
16 |
transforms.Resize((256, 256)),
|
@@ -21,13 +20,12 @@ def pipeline(img, v):
|
|
21 |
img = model_build.img_preprocess(img, pretransform)
|
22 |
with torch.no_grad():
|
23 |
latent_space = psp(img.float(), randomize_noise=True, resize=False, return_latents=True)
|
24 |
-
|
25 |
-
elif v == 'version2': img = stylegan2_v2(latent_space, noise_mode='none')
|
26 |
img = Image.fromarray(np.array((img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8).squeeze(0)[20:-20,:,:]))
|
27 |
img.save('output.png')
|
28 |
return 'output.png'
|
29 |
|
30 |
examples=[['1.png',False], ['2.png', False], ['3.png', False], ['4.png', False], ['5.png', False]]
|
31 |
description="이미지 업로드 후 연필모양 아이콘 누르면 정사각형으로 자르기 할 수 있습니다. 디테일은 좀 떨어짐. 잘 안되면 얼굴 클로즈업하면 좀 나아요. After uploading the image, you can square crop."
|
32 |
-
gr.Interface(pipeline, [gr.inputs.Image(type="pil")
|
33 |
|
|
|
9 |
|
10 |
|
11 |
psp = model_build.build_psp()
|
12 |
+
stylegan2 = model_build.build_stylegan2(network_pkl = 'pretrained/ohayou_face2.pkl')
|
|
|
13 |
|
14 |
pretransform = transforms.Compose([
|
15 |
transforms.Resize((256, 256)),
|
|
|
20 |
img = model_build.img_preprocess(img, pretransform)
|
21 |
with torch.no_grad():
|
22 |
latent_space = psp(img.float(), randomize_noise=True, resize=False, return_latents=True)
|
23 |
+
img = stylegan2(latent_space, noise_mode='none')
|
|
|
24 |
img = Image.fromarray(np.array((img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8).squeeze(0)[20:-20,:,:]))
|
25 |
img.save('output.png')
|
26 |
return 'output.png'
|
27 |
|
28 |
examples=[['1.png',False], ['2.png', False], ['3.png', False], ['4.png', False], ['5.png', False]]
|
29 |
description="이미지 업로드 후 연필모양 아이콘 누르면 정사각형으로 자르기 할 수 있습니다. 디테일은 좀 떨어짐. 잘 안되면 얼굴 클로즈업하면 좀 나아요. After uploading the image, you can square crop."
|
30 |
+
gr.Interface(pipeline, [gr.inputs.Image(type="pil")], gr.outputs.Image(type="file"),description=description,allow_flagging=False,examples=examples,allow_screenshot=False,enable_queue=False).launch()
|
31 |
|