DmitrMakeev commited on
Commit
80bf166
1 Parent(s): 86c58e3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -0
app.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import cv2
3
+ import gradio as gr
4
+ import AnimeGANv3_src
5
+
6
+
7
+ os.makedirs('output', exist_ok=True)
8
+
9
+
10
+ def inference(img_path, Style, if_face=None):
11
+ print(img_path, Style, if_face)
12
+ try:
13
+ img = cv2.imread(img_path)
14
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
15
+ if Style == "AnimeGANv3_Arcane":
16
+ f = "A"
17
+ elif Style == "AnimeGANv3_Trump v1.0":
18
+ f = "T"
19
+ elif Style == "AnimeGANv3_Shinkai":
20
+ f = "S"
21
+ elif Style == "AnimeGANv3_PortraitSketch":
22
+ f = "P"
23
+ elif Style == "AnimeGANv3_Hayao":
24
+ f = "H"
25
+ elif Style == "AnimeGANv3_Disney v1.0":
26
+ f = "D"
27
+ elif Style == "AnimeGANv3_JP_face v1.0":
28
+ f = "J"
29
+ else:
30
+ f = "U"
31
+
32
+ try:
33
+ det_face = True if if_face=="Yes" else False
34
+ output = AnimeGANv3_src.Convert(img, f, det_face)
35
+ result = cv2.resize(output, (img.shape[1],img.shape[0] ), interpolation = cv2.INTER_AREA)
36
+ # save_path = f"output/out.{img_path.rsplit('.')[-1]}"
37
+ #cv2.imwrite(save_path, result[:, :, ::-1])
38
+ return result
39
+ except RuntimeError as error:
40
+ print('Error', error)
41
+ except Exception as error:
42
+ print('global exception', error)
43
+ return None, None
44
+
45
+
46
+ title = "AnimeGANv3: To produce your own animation."
47
+ description = r"""Official online demo for <a href='https://github.com/TachibanaYoshino/AnimeGANv3' target='_blank'><b>AnimeGANv3</b></a>. If you like what I'm doing you can tip me on <a href='https://www.patreon.com/Asher_Chan' target='_blank'><b>**patreon**</b></a>.<br>
48
+ It can be used to turn your photos or videos into anime.<br>
49
+ To use it, simply upload your image. It can convert landscape photos to Hayao Miyazaki or Makoto Shinkai style anime, as well as 6 style conversions about human faces.<br>
50
+ If AnimeGANv3 is helpful, please help to ⭐ the <a href='https://github.com/TachibanaYoshino/AnimeGANv3' target='_blank'>Github Repo</a> and recommend it to your friends. 😊
51
+ """
52
+ article = r"""
53
+ [![GitHub Stars](https://img.shields.io/github/stars/TachibanaYoshino/AnimeGANv3?style=social)](https://github.com/TachibanaYoshino/AnimeGANv3)
54
+ ### 🔥 Demo
55
+ I. Video to anime (Hayao Style)
56
+ <p style="display: flex;">
57
+ <a href="https://youtu.be/EosubeJmAnE" target="___blank" style="margin-left: 14px;"><img src="https://img.shields.io/static/v1?label=YouTube&message=video 1&color=red"/></a>
58
+ <a href="https://youtu.be/5qLUflWb45E" target="___blank" style="margin-left: 14px;"><img src="https://img.shields.io/static/v1?label=YouTube&message=video 2&color=green"/></a>
59
+ <a href="https://www.youtube.com/watch?v=iFjiaPlhVm4" target="___blank" style="margin-left: 14px;"><img src="https://img.shields.io/static/v1?label=YouTube&message=video 3&color=pink"/></a>
60
+ </p>
61
+ II. Video to anime (USA cartoon + Disney style)
62
+ <a href="https://youtu.be/vJqQQMRYKh0"><img src="https://img.shields.io/static/v1?label=YouTube&message=AnimeGANv3_Trump style v1.5 &color=gold"/></a>
63
+ ----------
64
+ ## License
65
+ This repo is made freely available to academic and non-academic entities for non-commercial purposes such as academic research, teaching, scientific publications. Permission is granted to use the AnimeGANv3 given that you agree to my license terms. Regarding the request for commercial use, please contact us via email to help you obtain the authorization letter.
66
+ ## Acknowledgement
67
+ * Huggingface UI is referenced from @akhaliq/GFPGAN.
68
+ * The dataset of AnimeGANv3_JP_face v1.0 is from DCTnet and then manually optimized.
69
+ ## Author
70
+ Xin Chen
71
+ If you have any question, please open an issue on GitHub Repo.
72
+
73
+ <center><img src='https://visitor-badge.glitch.me/badge?page_id=AnimeGANv3_online' alt='visitor badge'></center>
74
+ """
75
+ gr.Interface(
76
+ inference, [
77
+ gr.inputs.Image(type="filepath", label="Input"),
78
+ gr.Dropdown([
79
+ 'AnimeGANv3_Hayao',
80
+ 'AnimeGANv3_Shinkai',
81
+ 'AnimeGANv3_Arcane',
82
+ 'AnimeGANv3_USA',
83
+ 'AnimeGANv3_Trump v1.0',
84
+ 'AnimeGANv3_Disney v1.0',
85
+ 'AnimeGANv3_PortraitSketch',
86
+ 'AnimeGANv3_JP_face v1.0',
87
+ ],
88
+ type="value",
89
+ value='AnimeGANv3_Hayao',
90
+ label='AnimeGANv3 Style'),
91
+ gr.inputs.Radio(['Yes', 'No'], type="value", default='No', label='Extract face'),
92
+ ], [
93
+ gr.outputs.Image(type="numpy", label="Output (The whole image)"),
94
+ # gr.outputs.File(label="Download the output image")
95
+ ],
96
+ title=title,
97
+ description=description,
98
+ article=article,
99
+ allow_flagging="never").launch(enable_queue=True)