glt3953 commited on
Commit
1a30e84
Β·
1 Parent(s): d54bf9c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+
4
+ model2 = torch.hub.load(
5
+ "AK391/animegan2-pytorch:main",
6
+ "generator",
7
+ pretrained=True,
8
+ progress=False
9
+ )
10
+ model1 = torch.hub.load("AK391/animegan2-pytorch:main", "generator", pretrained="face_paint_512_v1")
11
+ face2paint = torch.hub.load(
12
+ 'AK391/animegan2-pytorch:main', 'face2paint',
13
+ size=512,side_by_side=False
14
+ )
15
+
16
+ def inference(img, ver):
17
+ if ver == 'version 2 (πŸ”Ί robustness,πŸ”» stylization)':
18
+ out = face2paint(model2, img)
19
+ else:
20
+ out = face2paint(model1, img)
21
+ return out
22
+
23
+ title = "AnimeGANv2"
24
+ 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."
25
+ 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>"
26
+ examples=[['groot.jpeg','version 2 (πŸ”Ί robustness,πŸ”» stylization)'],['gongyoo.jpeg','version 1 (πŸ”Ί stylization, πŸ”» robustness)']]
27
+
28
+ demo = gr.Interface(
29
+ fn=inference,
30
+ inputs=[gr.inputs.Image(type="pil"),gr.inputs.Radio(['version 1 (πŸ”Ί stylization, πŸ”» robustness)','version 2 (πŸ”Ί robustness,πŸ”» stylization)'], type="value", default='version 2 (πŸ”Ί robustness,πŸ”» stylization)', label='version')],
31
+ outputs=gr.outputs.Image(type="pil"),
32
+ title=title,
33
+ description=description,
34
+ article=article,
35
+ examples=examples)
36
+
37
+ demo.launch()