Update app.py
Browse files
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 |
-
|
| 27 |
</h1>
|
| 28 |
-
|
| 29 |
-
<
|
| 30 |
-
|
| 31 |
-
</
|
|
|
|
| 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 |
-
|
| 37 |
[](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('''##
|
| 92 |
-
-
|
| 93 |
-
-
|
| 94 |
-
-
|
| 95 |
|
| 96 |
''')
|
| 97 |
with gr.Row():
|
| 98 |
with gr.Column():
|
| 99 |
-
gr.Markdown('''
|
| 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('
|
| 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('''
|
| 116 |
-
![
|
| 117 |
|
| 118 |
|
| 119 |
with gr.Box():
|
| 120 |
-
gr.Markdown('''##
|
| 121 |
-
-
|
| 122 |
-
-
|
| 123 |
-
-
|
| 124 |
-
-
|
| 125 |
-
- **<font color=red>
|
| 126 |
-
-
|
| 127 |
-
-
|
| 128 |
|
| 129 |
''')
|
| 130 |
with gr.Row():
|
| 131 |
with gr.Box():
|
| 132 |
with gr.Column():
|
| 133 |
-
gr.Markdown('''
|
| 134 |
-
![
|
| 135 |
with gr.Row():
|
| 136 |
top = gr.Slider(128,
|
| 137 |
256,
|
| 138 |
value=200,
|
| 139 |
step=8,
|
| 140 |
-
label='
|
| 141 |
with gr.Row():
|
| 142 |
bottom = gr.Slider(128,
|
| 143 |
256,
|
| 144 |
value=200,
|
| 145 |
step=8,
|
| 146 |
-
label='
|
| 147 |
with gr.Row():
|
| 148 |
left = gr.Slider(128,
|
| 149 |
256,
|
| 150 |
value=200,
|
| 151 |
step=8,
|
| 152 |
-
label='
|
| 153 |
with gr.Row():
|
| 154 |
right = gr.Slider(128,
|
| 155 |
256,
|
| 156 |
value=200,
|
| 157 |
step=8,
|
| 158 |
-
label='
|
| 159 |
with gr.Box():
|
| 160 |
with gr.Column():
|
| 161 |
-
gr.Markdown('''
|
| 162 |
with gr.Row():
|
| 163 |
-
input_image = gr.Image(label='
|
| 164 |
type='filepath')
|
| 165 |
with gr.Row():
|
| 166 |
-
preprocess_image_button = gr.Button('
|
| 167 |
with gr.Row():
|
| 168 |
-
input_video = gr.Video(label='
|
| 169 |
mirror_webcam=False,
|
| 170 |
type='filepath')
|
| 171 |
with gr.Row():
|
| 172 |
-
preprocess_video0_button = gr.Button('
|
| 173 |
-
preprocess_video1_button = gr.Button('
|
| 174 |
|
| 175 |
with gr.Box():
|
| 176 |
with gr.Column():
|
| 177 |
gr.Markdown('''View''')
|
| 178 |
with gr.Row():
|
| 179 |
-
input_info = gr.Textbox(label='
|
| 180 |
with gr.Row():
|
| 181 |
-
aligned_face = gr.Image(label='
|
| 182 |
type='numpy',
|
| 183 |
interactive=False)
|
| 184 |
instyle = gr.Variable()
|
| 185 |
with gr.Row():
|
| 186 |
-
aligned_video = gr.Video(label='
|
| 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='
|
| 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('''##
|
| 209 |
with gr.Row():
|
| 210 |
with gr.Column():
|
| 211 |
gr.Markdown('''
|
| 212 |
|
| 213 |
-
-
|
| 214 |
-
-
|
| 215 |
-
-
|
| 216 |
''')
|
| 217 |
style_degree = gr.Slider(0,
|
| 218 |
1,
|
| 219 |
value=0.5,
|
| 220 |
step=0.05,
|
| 221 |
-
label='
|
| 222 |
with gr.Column():
|
| 223 |
-
gr.Markdown('''](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 |
+
''')
|
| 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 |
+
''')
|
| 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('''
|
| 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)
|