ygangang commited on
Commit
5725f49
·
1 Parent(s): fcdd7fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -49
app.py CHANGED
@@ -23,17 +23,18 @@ def parse_args() -> argparse.Namespace:
23
  DESCRIPTION = '''
24
  <div align=center>
25
  <h1 style="font-weight: 900; margin-bottom: 7px;">
26
- Portrait Style Transfer with <a href="https://github.com/williamyang1991/VToonify">VToonify</a>
27
  </h1>
28
- <video id="video" width=50% controls="" preload="none" poster="https://repository-images.githubusercontent.com/534480768/53715b0f-a2df-4daa-969c-0e74c102d339">
29
- <source id="mp4" src="https://user-images.githubusercontent.com/18130694/189483939-0fc4a358-fb34-43cc-811a-b22adb820d57.mp4
30
- " type="video/mp4">
31
- </videos></div>
 
32
  '''
33
  FOOTER = '<div align=center><img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.laobi.icu/badge?page_id=williamyang1991/VToonify" /></div>'
34
 
35
  ARTICLE = r"""
36
- If VToonify is helpful, please help to ⭐ the <a href='https://github.com/williamyang1991/VToonify' target='_blank'>Github Repo</a>. Thanks!
37
  [![GitHub Stars](https://img.shields.io/github/stars/williamyang1991/VToonify?style=social)](https://github.com/williamyang1991/VToonify)
38
  ---
39
  📝 **Citation**
@@ -88,15 +89,15 @@ def main():
88
  gr.Markdown(DESCRIPTION)
89
 
90
  with gr.Box():
91
- gr.Markdown('''## Step 1(Select Style)
92
- - Select **Style Type**.
93
- - Type with `-d` means it supports style degree adjustment.
94
- - Type without `-d` usually has better toonification quality.
95
 
96
  ''')
97
  with gr.Row():
98
  with gr.Column():
99
- gr.Markdown('''Select Style Type''')
100
  with gr.Row():
101
  style_type = gr.Radio(label='Style Type',
102
  choices=['cartoon1','cartoon1-d','cartoon2-d','cartoon3-d',
@@ -108,82 +109,82 @@ def main():
108
  )
109
  exstyle = gr.Variable()
110
  with gr.Row():
111
- loadmodel_button = gr.Button('Load Model')
112
  with gr.Row():
113
  load_info = gr.Textbox(label='Process Information', interactive=False, value='No model loaded.')
114
  with gr.Column():
115
- gr.Markdown('''Reference Styles
116
- ![example](https://raw.githubusercontent.com/williamyang1991/tmpfile/master/vtoonify/style.jpg)''')
117
 
118
 
119
  with gr.Box():
120
- gr.Markdown('''## Step 2 (Preprocess Input Image / Video)
121
- - Drop an image/video containing a near-frontal face to the **Input Image**/**Input Video**.
122
- - Hit the **Rescale Image**/**Rescale First Frame** button.
123
- - Rescale the input to make it best fit the model.
124
- - The final image result will be based on this **Rescaled Face**. Use padding parameters to adjust the background space.
125
- - **<font color=red>Solution to [Error: no face detected!]</font>**: VToonify uses dlib.get_frontal_face_detector but sometimes it fails to detect a face. You can try several times or use other images until a face is detected, then switch back to the original image.
126
- - For video input, further hit the **Rescale Video** button.
127
- - The final video result will be based on this **Rescaled Video**. To avoid overload, video is cut to at most **100/300** frames for CPU/GPU, respectively.
128
 
129
  ''')
130
  with gr.Row():
131
  with gr.Box():
132
  with gr.Column():
133
- gr.Markdown('''Choose the padding parameters.
134
- ![example](https://raw.githubusercontent.com/williamyang1991/tmpfile/master/vtoonify/rescale.jpg)''')
135
  with gr.Row():
136
  top = gr.Slider(128,
137
  256,
138
  value=200,
139
  step=8,
140
- label='top')
141
  with gr.Row():
142
  bottom = gr.Slider(128,
143
  256,
144
  value=200,
145
  step=8,
146
- label='bottom')
147
  with gr.Row():
148
  left = gr.Slider(128,
149
  256,
150
  value=200,
151
  step=8,
152
- label='left')
153
  with gr.Row():
154
  right = gr.Slider(128,
155
  256,
156
  value=200,
157
  step=8,
158
- label='right')
159
  with gr.Box():
160
  with gr.Column():
161
- gr.Markdown('''Input''')
162
  with gr.Row():
163
- input_image = gr.Image(label='Input Image',
164
  type='filepath')
165
  with gr.Row():
166
- preprocess_image_button = gr.Button('Rescale Image')
167
  with gr.Row():
168
- input_video = gr.Video(label='Input Video',
169
  mirror_webcam=False,
170
  type='filepath')
171
  with gr.Row():
172
- preprocess_video0_button = gr.Button('Rescale First Frame')
173
- preprocess_video1_button = gr.Button('Rescale Video')
174
 
175
  with gr.Box():
176
  with gr.Column():
177
  gr.Markdown('''View''')
178
  with gr.Row():
179
- input_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
180
  with gr.Row():
181
- aligned_face = gr.Image(label='Rescaled Face',
182
  type='numpy',
183
  interactive=False)
184
  instyle = gr.Variable()
185
  with gr.Row():
186
- aligned_video = gr.Video(label='Rescaled Video',
187
  type='mp4',
188
  interactive=False)
189
  with gr.Row():
@@ -191,7 +192,7 @@ def main():
191
  paths = ['./vtoonify/data/pexels-andrea-piacquadio-733872.jpg','./vtoonify/data/i5R8hbZFDdc.jpg','./vtoonify/data/yRpe13BHdKw.jpg','./vtoonify/data/ILip77SbmOE.jpg','./vtoonify/data/077436.jpg','./vtoonify/data/081680.jpg']
192
  example_images = gr.Dataset(components=[input_image],
193
  samples=[[path] for path in paths],
194
- label='Image Examples')
195
  with gr.Column():
196
  #example_videos = gr.Dataset(components=[input_video], samples=[['./vtoonify/data/529.mp4']], type='values')
197
  #to render video example on mouse hover/click
@@ -205,40 +206,40 @@ def main():
205
  example_videos.click(load_examples, example_videos, input_video)
206
 
207
  with gr.Box():
208
- gr.Markdown('''## Step 3 (Generate Style Transferred Image/Video)''')
209
  with gr.Row():
210
  with gr.Column():
211
  gr.Markdown('''
212
 
213
- - Adjust **Style Degree**.
214
- - Hit **Toonify!** to toonify one frame. Hit **VToonify!** to toonify full video.
215
- - Estimated time on 1600x1440 video of 300 frames: 1 hour (CPU); 2 mins (GPU)
216
  ''')
217
  style_degree = gr.Slider(0,
218
  1,
219
  value=0.5,
220
  step=0.05,
221
- label='Style Degree')
222
  with gr.Column():
223
- gr.Markdown('''![example](https://raw.githubusercontent.com/williamyang1991/tmpfile/master/vtoonify/degree.jpg)
224
  ''')
225
  with gr.Row():
226
- output_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
227
  with gr.Row():
228
  with gr.Column():
229
  with gr.Row():
230
- result_face = gr.Image(label='Result Image',
231
  type='numpy',
232
  interactive=False)
233
  with gr.Row():
234
- toonify_button = gr.Button('Toonify!')
235
  with gr.Column():
236
  with gr.Row():
237
- result_video = gr.Video(label='Result Video',
238
  type='mp4',
239
  interactive=False)
240
  with gr.Row():
241
- vtoonify_button = gr.Button('VToonify!')
242
 
243
  gr.Markdown(ARTICLE)
244
  gr.Markdown(FOOTER)
 
23
  DESCRIPTION = '''
24
  <div align=center>
25
  <h1 style="font-weight: 900; margin-bottom: 7px;">
26
+ 使用<a href="https://github.com/williamyang1991/VToonify">VToonify</a>将视频人物卡通化
27
  </h1>
28
+
29
+ <font color=red><h2style="font-weight: 900; margin-bottom: 7px;">
30
+ 本页面是为方便英语不太好朋友了解如何使用,采用的是CPU,运算时间较长,请稳步<a href="https://huggingface.co/spaces/PKUWilliamYang/VToonify">原VToonify</a>,速度将提升数十倍
31
+ </h2></font>
32
+ </div>
33
  '''
34
  FOOTER = '<div align=center><img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.laobi.icu/badge?page_id=williamyang1991/VToonify" /></div>'
35
 
36
  ARTICLE = r"""
37
+ 如果VToonify对你有帮助请在<a href='https://github.com/williamyang1991/VToonify' target='_blank'>Github Repo</a>上为它点亮⭐.谢谢!
38
  [![GitHub Stars](https://img.shields.io/github/stars/williamyang1991/VToonify?style=social)](https://github.com/williamyang1991/VToonify)
39
  ---
40
  📝 **Citation**
 
89
  gr.Markdown(DESCRIPTION)
90
 
91
  with gr.Box():
92
+ gr.Markdown('''## 1(选择卡通类型)
93
+ - 选择 **卡通类型**.
94
+ - 带有 `-d` 表示它可以调整卡通化的程度.
95
+ - 不带 `-d` 通常会有更好的卡通效果.
96
 
97
  ''')
98
  with gr.Row():
99
  with gr.Column():
100
+ gr.Markdown('''选择类型''')
101
  with gr.Row():
102
  style_type = gr.Radio(label='Style Type',
103
  choices=['cartoon1','cartoon1-d','cartoon2-d','cartoon3-d',
 
109
  )
110
  exstyle = gr.Variable()
111
  with gr.Row():
112
+ loadmodel_button = gr.Button('加载模型')
113
  with gr.Row():
114
  load_info = gr.Textbox(label='Process Information', interactive=False, value='No model loaded.')
115
  with gr.Column():
116
+ gr.Markdown('''类型参考
117
+ ![示例](https://raw.githubusercontent.com/williamyang1991/tmpfile/master/vtoonify/style.jpg)''')
118
 
119
 
120
  with gr.Box():
121
+ gr.Markdown('''## 2 (对图片或视频进行预处理)
122
+ - 拖动1个含有人脸的图片或视频到 **输入图像**/**输入视频**.
123
+ - 点击 **缩放图像**/**缩放第1帧** 按钮.
124
+ - 缩放输入使它更好的适用模型.
125
+ - 最后的图像结果将是基于 **缩放后的脸**. 使用边框距离参数调整背景.
126
+ - **<font color=red>若出现[Error: no face detected!]错误</font>**: 是因为vtoonify没有检测到人脸,请调整后再试,或者更换原始图像.
127
+ - 对于视频输入, 则点击 **缩放视频** 按钮.
128
+ - 最后的视频结果将是基于 **缩放后的视频**. 为了避免超出硬件处理能力, 视频将被裁剪成 **100/300** 帧来适应 CPU/GPU.
129
 
130
  ''')
131
  with gr.Row():
132
  with gr.Box():
133
  with gr.Column():
134
+ gr.Markdown('''调整边框距离参数.
135
+ ![示例](https://raw.githubusercontent.com/williamyang1991/tmpfile/master/vtoonify/rescale.jpg)''')
136
  with gr.Row():
137
  top = gr.Slider(128,
138
  256,
139
  value=200,
140
  step=8,
141
+ label='')
142
  with gr.Row():
143
  bottom = gr.Slider(128,
144
  256,
145
  value=200,
146
  step=8,
147
+ label='')
148
  with gr.Row():
149
  left = gr.Slider(128,
150
  256,
151
  value=200,
152
  step=8,
153
+ label='')
154
  with gr.Row():
155
  right = gr.Slider(128,
156
  256,
157
  value=200,
158
  step=8,
159
+ label='')
160
  with gr.Box():
161
  with gr.Column():
162
+ gr.Markdown('''输入''')
163
  with gr.Row():
164
+ input_image = gr.Image(label='输入图像',
165
  type='filepath')
166
  with gr.Row():
167
+ preprocess_image_button = gr.Button('缩放图像')
168
  with gr.Row():
169
+ input_video = gr.Video(label='输入视频',
170
  mirror_webcam=False,
171
  type='filepath')
172
  with gr.Row():
173
+ preprocess_video0_button = gr.Button('缩放第一帧')
174
+ preprocess_video1_button = gr.Button('绽放视频')
175
 
176
  with gr.Box():
177
  with gr.Column():
178
  gr.Markdown('''View''')
179
  with gr.Row():
180
+ input_info = gr.Textbox(label='处理信息', interactive=False, value='n.a.')
181
  with gr.Row():
182
+ aligned_face = gr.Image(label='绽放脸',
183
  type='numpy',
184
  interactive=False)
185
  instyle = gr.Variable()
186
  with gr.Row():
187
+ aligned_video = gr.Video(label='绽放视频',
188
  type='mp4',
189
  interactive=False)
190
  with gr.Row():
 
192
  paths = ['./vtoonify/data/pexels-andrea-piacquadio-733872.jpg','./vtoonify/data/i5R8hbZFDdc.jpg','./vtoonify/data/yRpe13BHdKw.jpg','./vtoonify/data/ILip77SbmOE.jpg','./vtoonify/data/077436.jpg','./vtoonify/data/081680.jpg']
193
  example_images = gr.Dataset(components=[input_image],
194
  samples=[[path] for path in paths],
195
+ label='示例图像')
196
  with gr.Column():
197
  #example_videos = gr.Dataset(components=[input_video], samples=[['./vtoonify/data/529.mp4']], type='values')
198
  #to render video example on mouse hover/click
 
206
  example_videos.click(load_examples, example_videos, input_video)
207
 
208
  with gr.Box():
209
+ gr.Markdown('''## 3(生成 图像/视频)''')
210
  with gr.Row():
211
  with gr.Column():
212
  gr.Markdown('''
213
 
214
+ - 调整 **卡通化程度**.
215
+ - 点击 **图像卡通化!** 来将第1帧卡通化. 点击 **视频卡通化!** 来让整个视频卡通化.
216
+ - 预计时间 对于300帧的1600x1440视频 : 1 小时 (CPU); 2 分钟 (GPU)
217
  ''')
218
  style_degree = gr.Slider(0,
219
  1,
220
  value=0.5,
221
  step=0.05,
222
+ label='卡通化程度')
223
  with gr.Column():
224
+ gr.Markdown('''![示例](https://raw.githubusercontent.com/williamyang1991/tmpfile/master/vtoonify/degree.jpg)
225
  ''')
226
  with gr.Row():
227
+ output_info = gr.Textbox(label='示例信息', interactive=False, value='n.a.')
228
  with gr.Row():
229
  with gr.Column():
230
  with gr.Row():
231
+ result_face = gr.Image(label='图像结果',
232
  type='numpy',
233
  interactive=False)
234
  with gr.Row():
235
+ toonify_button = gr.Button('图像卡通化!')
236
  with gr.Column():
237
  with gr.Row():
238
+ result_video = gr.Video(label='视频结果',
239
  type='mp4',
240
  interactive=False)
241
  with gr.Row():
242
+ vtoonify_button = gr.Button('视频卡通化!')
243
 
244
  gr.Markdown(ARTICLE)
245
  gr.Markdown(FOOTER)