leejihoon98 commited on
Commit
d5f72bc
Β·
1 Parent(s): accd6f4

face2inpaint

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import torch
3
+ import gradio as gr
4
+
5
+
6
+ #from torch.fx import symbolic_trace
7
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
8
+
9
+
10
+ model1 = torch.hub.load('bryandlee/animegan2-pytorch:main','generator',pretrained='face_paint_512_v1',device=device)
11
+ model2 = torch.hub.load('bryandlee/animegan2-pytorch:main','generator',pretrained='face_paint_512_v2',device=device)
12
+ model3 = torch.hub.load('bryandlee/animegan2-pytorch:main','generator',pretrained='celeba_distill', device=device)
13
+ model4 = torch.hub.load('bryandlee/animegan2-pytorch:main','generator',pretrained='paprika',device=device)
14
+
15
+ face2paint = torch.hub.load(
16
+ 'bryandlee/animegan2-pytorch:main', 'face2paint',
17
+ size=512, device=device,side_by_side=False
18
+ )
19
+ def inference(img, ver):
20
+ if ver == 'version 1':
21
+ out = face2paint(model1,img)
22
+ elif ver == 'version 2':
23
+ out = face2paint(model2,img)
24
+ elif ver == 'version 3':
25
+ out = face2paint(model3, img)
26
+ elif ver == 'version 4':
27
+ out = face2paint(model4, img)
28
+ return out
29
+
30
+ title = 'KNU BrainAI LAB : Face to Paint'
31
+ # 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."
32
+ description = 'λ§Œν™”λ‘œ 바뀐 λ‚΄ 얼꡴을 ν™•μΈν•΄λ³΄μ„Έμš”!'
33
+ # description = 'version1 : μ—¬μ„±μŠ€λŸ¬μš΄\n version2: λ‚¨μ„±μŠ€λŸ¬μš΄\n version3: μ›Ήνˆ°κ°™μ€\n version4: μž‘ν’ˆκ°™μ€'
34
+ article = "<p style='text-align: center'><a href='https://github.com/bryandlee/animegan2-pytorch' target='_blank'>Github Repo Pytorch</a></p> <center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_animegan' alt='visitor badge'></center></p>"
35
+ examples=[['μ•„μ΄μœ .png','version 1-μ•„μ΄μœ '],['μ•ˆμƒνƒœκ΅μˆ˜λ‹˜.png','version 2-μ•ˆμƒνƒœκ΅μˆ˜λ‹˜'],['일둠머슀크.png','version 3-일둠머슀크'],['ν˜„λΉˆ.png','version 4-ν˜„λΉˆ']]
36
+ gr.Interface(inference, [gr.inputs.Image(type="pil"),gr.inputs.Radio(['version 1','version 2','version 3','version 4'], type="value", default='version 2', label='version')],
37
+ gr.outputs.Image(type="pil"),title=title,description=description,article=article,examples=examples,allow_flagging=False,allow_screenshot=False,css="body {background-image: url('file=brainai.png')}").launch(share=True)