Spaces:
Runtime error
Runtime error
leejihoon98 commited on
Commit Β·
d5f72bc
1
Parent(s): accd6f4
face2inpaint
Browse files
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)
|