vumichien commited on
Commit
fa9e198
·
1 Parent(s): dd71511

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import cv2
3
+ import gradio as gr
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ os.makedirs('output', exist_ok=True)
7
+
8
+ MODEL_PATH = {
9
+ "AnimeGANv2_Hayao": hf_hub_download('vumichien/AnimeGANv2_Hayao', 'AnimeGANv2_Hayao.onnx'),
10
+ "AnimeGANv2_Shinkai": hf_hub_download('vumichien/AnimeGANv2_Shinkai', 'AnimeGANv2_Shinkai.onnx'),
11
+ "AnimeGANv2_Paprika": hf_hub_download('vumichien/AnimeGANv2_Paprika', 'AnimeGANv2_Paprika.onnx'),
12
+ "AnimeGANv3_PortraitSketch": hf_hub_download('vumichien/AnimeGANv3_PortraitSketch', 'AnimeGANv3_PortraitSketch.onnx'),
13
+ "AnimeGANv3_JP_face": hf_hub_download('vumichien/AnimeGANv3_JP_face', 'AnimeGANv3_JP_face.onnx'),
14
+ }
15
+
16
+
17
+ def inference(img_path, model, focus_face=None):
18
+ print(img_path, model, focus_face)
19
+ mat, scale = load_image(img_path, focus_face)
20
+ output = convert(mat, model, scale)
21
+ save_path = f"output/out.{img_path.rsplit('.')[-1]}"
22
+ cv2.imwrite(save_path, output)
23
+ return output, save_path
24
+
25
+
26
+ title = "AnimeGANv2: To produce your own animation 😶‍🌫️"
27
+ description = r"""### 🔥Demo AnimeGANv2: To produce your own animation. To use it, simply upload your image.<br>
28
+ """
29
+ article = r"""
30
+ <center><img src='https://visitor-badge.glitch.me/badge?page_id=AnimeGAN_demo&left_color=green&right_color=blue' alt='visitor badge'></center>
31
+ <center><a href='https://github.com/TachibanaYoshino/AnimeGANv3' target='_blank'>Github Repo</a></center>
32
+ """
33
+ gr.Interface(
34
+ inference, [
35
+ gr.Image(type="filepath", label="Input image"),
36
+ gr.Dropdown([
37
+ 'AnimeGANv2_Hayao',
38
+ 'AnimeGANv2_Shinkai',
39
+ 'AnimeGANv2_Paprika',
40
+ 'AnimeGANv3_PortraitSketch',
41
+ 'AnimeGANv3_JP_face',
42
+ ],
43
+ type="value",
44
+ value='AnimeGANv3_PortraitSketch',
45
+ label='AnimeGAN Style'),
46
+ gr.Radio(['Yes', 'No'], type="value", value='No', label='Extract face'),
47
+ ], [
48
+ gr.Image(type="numpy", label="Output (The whole image)"),
49
+ gr.File(label="Download the output image")
50
+ ],
51
+ title=title,
52
+ description=description,
53
+ article=article,
54
+ allow_flagging="never").launch(debug=True)