Spaces:
Sleeping
Sleeping
File size: 15,918 Bytes
ac1883f 5dea586 ac1883f 31083ae 5dea586 ac1883f 5dea586 ac1883f 31083ae 5dea586 ac1883f 5dea586 ac1883f 6a25359 ac1883f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
from __future__ import annotations
from huggingface_hub import hf_hub_download
import numpy as np
import gradio as gr
def create_demo_sr(process):
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Face Super Resolution')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='filepath')
model_type = gr.Radio(label='Model Type', choices=['SR for 32x','SR for 4x-48x'], value='SR for 32x')
resize_scale = gr.Slider(label='Resize Scale',
minimum=4,
maximum=48,
value=32,
step=4)
run_button = gr.Button(label='Run')
gr.Examples(
examples =[['pexels-daniel-xavier-1239291.jpg', 'SR for 32x', 32],
['ILip77SbmOE.png', 'SR for 32x', 32],
['ILip77SbmOE.png', 'SR for 4x-48x', 48],
],
inputs = [input_image, model_type, resize_scale],
)
with gr.Column():
#lrinput = gr.Image(label='Low-resolution input',type='numpy', interactive=False)
#result = gr.Image(label='Output',type='numpy', interactive=False)
result = gr.Gallery(label='LR input and Output',
elem_id='gallery').style(grid=2,
height='auto')
inputs = [
input_image,
resize_scale,
model_type,
]
run_button.click(fn=process,
inputs=inputs,
outputs=[result],
api_name='sr')
return demo
def create_demo_s2f(process):
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Sketch-to-Face Translation')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='filepath')
gr.Markdown("""Note: Input will be cropped if larger than 512x512.""")
seed = gr.Slider(label='Seed for appearance',
minimum=0,
maximum=2147483647,
step=1,
randomize=True)
#input_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
run_button = gr.Button(label='Run')
gr.Examples(
examples =[['234_sketch.jpg', 1024]],
inputs = [input_image, seed],
)
with gr.Column():
result = gr.Image(label='Output',type='numpy', interactive=False)
inputs = [
input_image, seed
]
run_button.click(fn=process,
inputs=inputs,
outputs=[result],
api_name='s2f')
return demo
def create_demo_m2f(process):
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Mask-to-Face Translation')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='filepath')
input_type = gr.Radio(label='Input Type', choices=['color image','parsing mask'], value='color image')
seed = gr.Slider(label='Seed for appearance',
minimum=0,
maximum=2147483647,
step=1,
randomize=True)
#input_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
run_button = gr.Button(label='Run')
gr.Examples(
examples =[['ILip77SbmOE.png', 'color image', 4], ['ILip77SbmOE_mask.png', 'parsing mask', 4]],
inputs = [input_image, input_type, seed],
)
with gr.Column():
#vizmask = gr.Image(label='Visualized mask',type='numpy', interactive=False)
#result = gr.Image(label='Output',type='numpy', interactive=False)
result = gr.Gallery(label='Visualized mask and Output',
elem_id='gallery').style(grid=2,
height='auto')
inputs = [
input_image, input_type, seed
]
run_button.click(fn=process,
inputs=inputs,
outputs=[result],
api_name='m2f')
return demo
def create_demo_editing(process):
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Video Face Editing (for image input)')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='filepath')
model_type = gr.Radio(label='Editing Type', choices=['reduce age','light hair color'], value='color image')
scale_factor = gr.Slider(label='editing degree (-2~2)',
minimum=-2,
maximum=2,
value=1,
step=0.1)
#input_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
run_button = gr.Button(label='Run')
gr.Examples(
examples =[['ILip77SbmOE.png', 'reduce age', -2],
['ILip77SbmOE.png', 'light hair color', 1]],
inputs = [input_image, model_type, scale_factor],
)
with gr.Column():
result = gr.Image(label='Output',type='numpy', interactive=False)
inputs = [
input_image, scale_factor, model_type
]
run_button.click(fn=process,
inputs=inputs,
outputs=[result],
api_name='editing')
return demo
def create_demo_toonify(process):
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Video Face Toonification (for image input)')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='filepath')
style_type = gr.Radio(label='Style Type', choices=['Pixar','Cartoon','Arcane'], value='Pixar')
#input_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
run_button = gr.Button(label='Run')
gr.Examples(
examples =[['ILip77SbmOE.png', 'Pixar'], ['ILip77SbmOE.png', 'Cartoon'], ['ILip77SbmOE.png', 'Arcane']],
inputs = [input_image, style_type],
)
with gr.Column():
result = gr.Image(label='Output',type='numpy', interactive=False)
inputs = [
input_image, style_type
]
run_button.click(fn=process,
inputs=inputs,
outputs=[result],
api_name='toonify')
return demo
def create_demo_vediting(process, max_frame_num = 4):
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Video Face Editing (for video input)')
with gr.Row():
with gr.Column():
input_video = gr.Video(source='upload', mirror_webcam=False, type='filepath')
model_type = gr.Radio(label='Editing Type', choices=['reduce age','light hair color'], value='color image')
scale_factor = gr.Slider(label='editing degree (-2~2)',
minimum=-2,
maximum=2,
value=1,
step=0.1)
info = ''
if max_frame_num < 100:
info = '(full video editing is not allowed so as not to slow down the demo, \
but you can duplicate the Space to modify the number limit to a large value)'
frame_num = gr.Slider(label='Number of frames to edit' + info,
minimum=1,
maximum=max_frame_num,
value=4,
step=1)
#input_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
run_button = gr.Button(label='Run')
gr.Examples(
examples =[['684.mp4', 'reduce age', 1.5, 2],
['684.mp4', 'light hair color', 0.7, 2]],
inputs = [input_video, model_type, scale_factor],
)
with gr.Column():
viz_result = gr.Gallery(label='Several edited frames', elem_id='gallery').style(grid=2, height='auto')
result = gr.Video(label='Output', type='mp4', interactive=False)
inputs = [
input_video, scale_factor, model_type, frame_num
]
run_button.click(fn=process,
inputs=inputs,
outputs=[viz_result, result],
api_name='vediting')
return demo
def create_demo_vtoonify(process, max_frame_num = 4):
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## Video Face Toonification (for video input)')
with gr.Row():
with gr.Column():
input_video = gr.Video(source='upload', mirror_webcam=False, type='filepath')
style_type = gr.Radio(label='Style Type', choices=['Pixar','Cartoon','Arcane'], value='Pixar')
info = ''
if max_frame_num < 100:
info = '(full video toonify is not allowed so as not to slow down the demo, \
but you can duplicate the Space to modify the number limit from 4 to a large value)'
frame_num = gr.Slider(label='Number of frames to toonify' + info,
minimum=1,
maximum=max_frame_num,
value=4,
step=1)
#input_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
run_button = gr.Button(label='Run')
gr.Examples(
examples =[['529_2.mp4', 'Arcane'],
['pexels-anthony-shkraba-production-8136210.mp4', 'Pixar'],
['684.mp4', 'Cartoon']],
inputs = [input_video, style_type],
)
with gr.Column():
viz_result = gr.Gallery(label='Several toonified frames', elem_id='gallery').style(grid=2, height='auto')
result = gr.Video(label='Output', type='mp4', interactive=False)
inputs = [
input_video, style_type, frame_num
]
run_button.click(fn=process,
inputs=inputs,
outputs=[viz_result, result],
api_name='vtoonify')
return demo
def create_demo_inversion(process, allow_optimization=False):
with gr.Blocks() as demo:
with gr.Row():
gr.Markdown('## StyleGANEX Inversion for Editing')
with gr.Row():
with gr.Column():
input_image = gr.Image(source='upload', type='filepath')
info = ''
if allow_optimization == False:
info = ' (latent optimization is not allowed so as not to slow down the demo, \
but you can duplicate the Space to modify the option or directly upload an optimized latent file. \
The file can be computed by inversion.py from the github page or colab)'
optimize = gr.Radio(label='Whether optimize latent' + info, choices=['No optimization','Latent optimization'],
value='No optimization', interactive=allow_optimization)
input_latent = gr.File(label='Optimized latent code (optional)', file_types=[".pt"])
editing_options = gr.Dropdown(['None', 'Style Mixing',
'Attribute Editing: smile',
'Attribute Editing: open_eye',
'Attribute Editing: open_mouth',
'Attribute Editing: pose',
'Attribute Editing: reduce_age',
'Attribute Editing: glasses',
'Attribute Editing: light_hair_color',
'Attribute Editing: slender',
'Domain Transfer: disney_princess',
'Domain Transfer: vintage_comics',
'Domain Transfer: pixar',
'Domain Transfer: edvard_munch',
'Domain Transfer: modigliani',
],
label="editing options (based on StyleGAN-NADA, InterFaceGAN, LowRankGAN)",
value='None')
scale_factor = gr.Slider(label='editing degree (-2~2) for Attribute Editing',
minimum=-2,
maximum=2,
value=2,
step=0.1)
seed = gr.Slider(label='Appearance Seed for Style Mixing',
minimum=0,
maximum=2147483647,
step=1,
randomize=True)
#input_info = gr.Textbox(label='Process Information', interactive=False, value='n.a.')
run_button = gr.Button(label='Run')
gr.Examples(
examples =[['ILip77SbmOE.png', 'ILip77SbmOE_inversion.pt', 'Domain Transfer: vintage_comics'],
['ILip77SbmOE.png', 'ILip77SbmOE_inversion.pt', 'Attribute Editing: smile'],
['ILip77SbmOE.png', 'ILip77SbmOE_inversion.pt', 'Style Mixing'],
],
inputs = [input_image, input_latent, editing_options],
)
with gr.Column():
result = gr.Image(label='Inversion output',type='numpy', interactive=False)
editing_result = gr.Image(label='Editing output',type='numpy', interactive=False)
inputs = [
input_image, optimize, input_latent, editing_options, scale_factor, seed
]
run_button.click(fn=process,
inputs=inputs,
outputs=[result, editing_result],
api_name='inversion')
return demo |