DmitrMakeev commited on
Commit
ce9879a
·
1 Parent(s): b702f94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -25
app.py CHANGED
@@ -1,33 +1,47 @@
1
- from PIL import Image
2
- import torch
3
- import gradio as gr
4
- # Загрузка моделей с разными вариантами настроек
5
- model1 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="celeba_distill")
6
- model2 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="face_paint_512_v1")
7
- model3 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="face_paint_512_v2")
8
- model4 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="paprika")
9
- face2paint = torch.hub.load('bryandlee/animegan2-pytorch:main', 'face2paint',
10
- size=1024, device="cpu", side_by_side=False)
11
- def inference(img, ver):
12
- if ver == 'Celebrity Distill':
13
- out = face2paint(model1, img)
14
- elif ver == 'Face Paint v1':
15
- out = face2paint(model2, img)
16
- elif ver == 'Face Paint v2':
17
- out = face2paint(model3, img)
18
- elif ver == 'Paprika':
19
- out = face2paint(model4, img)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  return out
21
- title = "AnimeGANv2"
22
- description = "Gradio Demo for AnimeGanv2 Face Portrait. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below. Please use a cropped portrait picture for best results similar to the examples below."
23
- article = ""
24
- # Создание интерфейса Gradio с четырьмя вариантами настроек
25
  gr.Interface(inference,
26
  [gr.inputs.Image(type="pil"),
27
- gr.inputs.Radio(['Celebrity Distill', 'Face Paint v1', 'Face Paint v2', 'Paprika'],
 
28
  type="value",
29
  default='Celebrity Distill',
30
- label='version')],
31
  gr.outputs.Image(type="pil"),
32
  title=title,
33
  description=description,
 
1
+ model1_512 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="celeba_distill")
2
+ model2_512 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="face_paint_512_v1")
3
+ model3_512 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="face_paint_512_v2")
4
+ model4_512 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="paprika")
5
+ model1_1024 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator",
6
+ pretrained="celeba_distill",
7
+ config="stylegan2_ffhq_config")
8
+ model2_1024 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator",
9
+ pretrained="face_paint_1024_v1",
10
+ config="stylegan2_ffhq_config")
11
+ model3_1024 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator",
12
+ pretrained="face_paint_1024_v2",
13
+ config="stylegan2_ffhq_config")
14
+ model4_1024 = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator",
15
+ pretrained="paprika_1024",
16
+ config="stylegan2_ffhq_config")
17
+ def inference(img, ver, size):
18
+ if size == '512':
19
+ if ver == 'Celebrity Distill':
20
+ out = face2paint(model1_512, img)
21
+ elif ver == 'Face Paint v1':
22
+ out = face2paint(model2_512, img)
23
+ elif ver == 'Face Paint v2':
24
+ out = face2paint(model3_512, img)
25
+ elif ver == 'Paprika':
26
+ out = face2paint(model4_512, img)
27
+ elif size == '1024':
28
+ if ver == 'Celebrity Distill':
29
+ out = face2paint(model1_1024, img)
30
+ elif ver == 'Face Paint v1':
31
+ out = face2paint(model2_1024, img)
32
+ elif ver == 'Face Paint v2':
33
+ out = face2paint(model3_1024, img)
34
+ elif ver == 'Paprika':
35
+ out = face2paint(model4_1024, img)
36
  return out
37
+ # Создание интерфейса Gradio с выбором размера и версии модели
 
 
 
38
  gr.Interface(inference,
39
  [gr.inputs.Image(type="pil"),
40
+ gr.inputs.Radio(['512', '1024'], type="value", default='512', label='Size'),
41
+ gr.inputs.Radio(['Celebrity Distill', 'Face Paint v1', 'Face Paint v2', 'Paprika'],
42
  type="value",
43
  default='Celebrity Distill',
44
+ label='Version')],
45
  gr.outputs.Image(type="pil"),
46
  title=title,
47
  description=description,