PascalLiu commited on
Commit
f78b6a9
1 Parent(s): 0a0b30c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +248 -248
app.py CHANGED
@@ -1,248 +1,248 @@
1
- import os
2
- import gradio as gr
3
- import yaml
4
- from argparse import ArgumentParser
5
- from tqdm import tqdm
6
-
7
- import numpy as np
8
- import imageio
9
- from skimage.transform import resize
10
- from skimage import img_as_ubyte
11
- from scipy.spatial import ConvexHull
12
- import torch
13
- from sync_batchnorm import DataParallelWithCallback
14
- import face_alignment
15
-
16
- from modules.generator import OcclusionAwareGenerator_SPADE
17
- from modules.keypoint_detector import KPDetector
18
-
19
-
20
- def normalize_kp(kp_source, kp_driving, kp_driving_initial, adapt_movement_scale=False,
21
- use_relative_movement=False, use_relative_jacobian=False):
22
- kp_new = {k: v for k, v in kp_driving.items()}
23
-
24
- if adapt_movement_scale:
25
- source_area = ConvexHull(kp_source['value'][0].data.cpu().numpy()).volume
26
- driving_area = ConvexHull(kp_driving_initial['value'][0].data.cpu().numpy()).volume
27
- adapt_movement_scale = np.sqrt(source_area) / np.sqrt(driving_area)
28
- kp_new['value'] = kp_driving['value'] * adapt_movement_scale # for reenactment demo
29
- else:
30
- adapt_movement_scale = 1
31
-
32
- if use_relative_movement:
33
- kp_value_diff = (kp_driving['value'] - kp_driving_initial['value'])
34
- kp_value_diff *= adapt_movement_scale
35
- kp_new['value'] = kp_value_diff + kp_source['value']
36
-
37
- if use_relative_jacobian:
38
- jacobian_diff = torch.matmul(kp_driving['jacobian'], torch.inverse(kp_driving_initial['jacobian']))
39
- kp_new['jacobian'] = torch.matmul(jacobian_diff, kp_source['jacobian'])
40
-
41
- return kp_new
42
-
43
-
44
- def load_checkpoints(config_path, checkpoint_path, cpu=False):
45
- with open(config_path) as f:
46
- # config = yaml.load(f)
47
- config = yaml.load(f, Loader=yaml.FullLoader)
48
-
49
- generator = OcclusionAwareGenerator_SPADE(**config['model_params']['generator_params'],
50
- **config['model_params']['common_params'])
51
- if not cpu:
52
- generator.cuda()
53
-
54
- kp_detector = KPDetector(**config['model_params']['kp_detector_params'],
55
- **config['model_params']['common_params'])
56
- if not cpu:
57
- kp_detector.cuda()
58
-
59
- if cpu:
60
- checkpoint = torch.load(checkpoint_path, map_location=torch.device('cpu'))
61
- else:
62
- checkpoint = torch.load(checkpoint_path)
63
-
64
- generator.load_state_dict(checkpoint['generator'])
65
- kp_detector.load_state_dict(checkpoint['kp_detector'])
66
-
67
- if not cpu:
68
- generator = DataParallelWithCallback(generator)
69
- kp_detector = DataParallelWithCallback(kp_detector)
70
-
71
- generator.eval()
72
- kp_detector.eval()
73
-
74
- return generator, kp_detector
75
-
76
-
77
- def make_animation(source_image, driving_video, generator, kp_detector, relative=True, adapt_movement_scale=True,
78
- cpu=False):
79
- with torch.no_grad():
80
- predictions = []
81
- source = torch.tensor(source_image[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)
82
- if not cpu:
83
- source = source.cuda()
84
- driving = torch.tensor(np.array(driving_video)[np.newaxis].astype(np.float32)).permute(0, 4, 1, 2, 3)
85
- kp_source = kp_detector(source)
86
- kp_driving_initial = kp_detector(driving[:, :, 0])
87
-
88
- for frame_idx in tqdm(range(driving.shape[2])):
89
- driving_frame = driving[:, :, frame_idx]
90
- if not cpu:
91
- driving_frame = driving_frame.cuda()
92
- kp_driving = kp_detector(driving_frame)
93
- kp_norm = normalize_kp(kp_source=kp_source, kp_driving=kp_driving,
94
- kp_driving_initial=kp_driving_initial, use_relative_movement=relative,
95
- use_relative_jacobian=relative, adapt_movement_scale=adapt_movement_scale)
96
- out = generator(source, kp_source=kp_source, kp_driving=kp_norm)
97
-
98
- predictions.append(np.transpose(out['prediction'].data.cpu().numpy(), [0, 2, 3, 1])[0])
99
- return predictions
100
-
101
-
102
- def find_best_frame_func(source, driving, cpu=False):
103
- def normalize_kp_infunc(kp):
104
- kp = kp - kp.mean(axis=0, keepdims=True)
105
- area = ConvexHull(kp[:, :2]).volume
106
- area = np.sqrt(area)
107
- kp[:, :2] = kp[:, :2] / area
108
- return kp
109
-
110
- fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, flip_input=True,
111
- device='cpu' if cpu else 'cuda')
112
- kp_source = fa.get_landmarks(255 * source)[0]
113
- kp_source = normalize_kp_infunc(kp_source)
114
- norm = float('inf')
115
- frame_num = 0
116
- for i, image in tqdm(enumerate(driving)):
117
- kp_driving = fa.get_landmarks(255 * image)[0]
118
- kp_driving = normalize_kp_infunc(kp_driving)
119
- new_norm = (np.abs(kp_source - kp_driving) ** 2).sum()
120
- if new_norm < norm:
121
- norm = new_norm
122
- frame_num = i
123
- return frame_num
124
-
125
-
126
- def drive_im(source_image, driving_image, adapt_scale):
127
- source_image = resize(source_image, (256, 256))[..., :3]
128
- driving_image = [resize(driving_image, (256, 256))[..., :3]]
129
-
130
- prediction = make_animation(source_image, driving_image, generator, kp_detector, relative=False,
131
- adapt_movement_scale=adapt_scale, cpu=cpu)
132
- return img_as_ubyte(prediction[0])
133
-
134
-
135
- def drive_vi(source_image, driving_video, mode, find_best_frame, relative, adapt_scale):
136
- reader = imageio.get_reader(driving_video)
137
- fps = reader.get_meta_data()['fps']
138
- driving_video = []
139
- try:
140
- for im in reader:
141
- driving_video.append(im)
142
- except RuntimeError:
143
- pass
144
- reader.close()
145
-
146
-
147
- if mode == 'reconstruction':
148
- source_image = driving_video[0]
149
-
150
- source_image = resize(source_image, (256, 256))[..., :3]
151
- driving_video = [resize(frame, (256, 256))[..., :3] for frame in driving_video]
152
-
153
- if find_best_frame:
154
- i = find_best_frame_func(source_image, driving_video, cpu=cpu)
155
- print("Best frame: " + str(i))
156
- driving_forward = driving_video[i:]
157
- driving_backward = driving_video[:(i + 1)][::-1]
158
- predictions_forward = make_animation(source_image, driving_forward, generator, kp_detector,
159
- relative=relative, adapt_movement_scale=adapt_scale, cpu=cpu)
160
- predictions_backward = make_animation(source_image, driving_backward, generator, kp_detector,
161
- relative=relative, adapt_movement_scale=adapt_scale, cpu=cpu)
162
- predictions = predictions_backward[::-1] + predictions_forward[1:]
163
- else:
164
- predictions = make_animation(source_image, driving_video, generator, kp_detector, relative=relative,
165
- adapt_movement_scale=adapt_scale, cpu=cpu)
166
- result_video_path = "result_video.mp4"
167
- imageio.mimsave(result_video_path, [img_as_ubyte(frame) for frame in predictions], fps=fps)
168
- return result_video_path
169
-
170
-
171
- os.environ['CUDA_VISIBLE_DEVICES'] = "3"
172
- config = "config/vox-256.yaml"
173
- checkpoint = "00000099-checkpoint.pth.tar"
174
- mode = "reenactment"
175
- relative = True
176
- adapt_scale = True
177
- find_best_frame = True
178
- cpu = False # decided by the deploying environment
179
-
180
- description = "We propose a Face Neural Volume Rendering (FNeVR) network for more realistic face animation, by taking the merits of 2D motion warping on facial expression transformation and 3D volume rendering on high-quality image synthesis in a unified framework.<br>[Paper](https://arxiv.org/abs/2209.10340) and [Code](https://github.com/zengbohan0217/FNeVR)"
181
- im_description = "We can animate a face portrait by a single image in this tab.<br>Please input the origin face and the driving face which provides pose and expression information, then we can obtain the virtual generated face.<br>We can select \"adaptive scale\" parameter for better optic flow estimation using adaptive movement scale based on convex hull of keypoints."
182
- vi_description = "We can animate a face portrait by a video in this tab.<br>Please input the origin face and the driving video which provides pose and expression information, then we can obtain the virtual generated video.<br>Please select inference mode (reenactment for different identities and reconstruction for the same identities).<br>We can select \"find best frame\" parameter to generate video from the frame that is the most alligned with source image, select \"relative motion\" paramter to use relative keypoint coordinates for preserving global object geometry, and select \"adaptive scale\" parameter for better optic flow estimation using adaptive movement scale based on convex hull of keypoints."
183
- acknowledgements = "This work was supported by “the Fundamental Research Funds for the Central Universities”, and the National Natural Science Foundation of China under Grant 62076016, Beijing Natural Science Foundation-Xiaomi Innovation Joint Fund L223024. Besides, we gratefully acknowledge the support of [MindSpore](https://www.mindspore.cn), CANN (Compute Architecture for Neural Networks) and Ascend AI processor used for this research.<br>Our FNeVR implementation is inspired by [FOMM](https://github.com/AliaksandrSiarohin/first-order-model) and [DECA](https://github.com/YadiraF/DECA). We appreciate the authors of these papers for making their codes available to the public."
184
-
185
- generator, kp_detector = load_checkpoints(config_path=config, checkpoint_path=checkpoint, cpu=cpu)
186
-
187
- # iface = gr.Interface(fn=drive_im,
188
- # inputs=[gr.Image(label="Origin face"),
189
- # gr.Image(label="Driving face"),
190
- # gr.CheckboxGroup(label="adapt scale")],
191
- # outputs=gr.Image(label="Generated face"), examples=[["sup-mat/source.png"], ["sup-mat/driving.png"]],
192
- # title="Demostration of FNeVR", description=description)
193
-
194
- with gr.Blocks(title="Demostration of FNeVR") as demo:
195
- gr.Markdown("# <center> Demostration of FNeVR")
196
- gr.Markdown(description)
197
-
198
- with gr.Tab("Driving by image"):
199
- gr.Markdown(im_description)
200
-
201
- with gr.Row():
202
- with gr.Column():
203
- gr.Markdown("#### Inputs")
204
- inp2 = gr.Image(label="Driving face")
205
- inp1 = gr.Image(label="Origin face")
206
-
207
- gr.Markdown("#### Parameter")
208
- inp3 = gr.Checkbox(value=True, label="adaptive scale")
209
-
210
- btn = gr.Button(value="Animate")
211
- with gr.Column():
212
- gr.Markdown("#### Output")
213
- outp = gr.Image(label="Generated face")
214
-
215
- gr.Examples([["sup-mat/driving.png", "sup-mat/source.png"]], [inp2, inp1])
216
-
217
- btn.click(fn=drive_im, inputs=[inp1, inp2, inp3], outputs=outp)
218
- with gr.Tab("Driving by video"):
219
- gr.Markdown(vi_description)
220
-
221
- with gr.Row():
222
- with gr.Column():
223
- gr.Markdown("#### Inputs")
224
- inp2 = gr.Video(label="Driving video")
225
- inp1 = gr.Image(label="Origin face")
226
-
227
- gr.Markdown("#### Parameters")
228
- inp3 = gr.Radio(choices=['reenactment', 'reconstruction'], value="reenactment", label="mode (if \"reconstruction\" selected, origin face is the first frame of driving video)")
229
- inp4 = gr.Checkbox(value=True, label="find best frame (more time consumed)")
230
- inp5 = gr.Checkbox(value=True, label="relative motion")
231
- inp6 = gr.Checkbox(value=True, label="adaptive scale")
232
-
233
- btn = gr.Button(value="Animate")
234
- with gr.Column():
235
- gr.Markdown("#### Output")
236
- outp = gr.Video(label="Generated video")
237
-
238
- gr.Examples([["sup-mat/driving.mp4", "sup-mat/source_for_video.png"]], [inp2, inp1])
239
-
240
- btn.click(fn=drive_vi, inputs=[inp1, inp2, inp3, inp4, inp5, inp6], outputs=outp)
241
-
242
- with gr.Tab("Real time animation"):
243
- gr.Markdown("#### Real time animation")
244
-
245
- gr.Markdown("## Acknowledgements")
246
- gr.Markdown(acknowledgements)
247
-
248
- demo.launch()
 
1
+ import os
2
+ import gradio as gr
3
+ import yaml
4
+ from argparse import ArgumentParser
5
+ from tqdm import tqdm
6
+
7
+ import numpy as np
8
+ import imageio
9
+ from skimage.transform import resize
10
+ from skimage import img_as_ubyte
11
+ from scipy.spatial import ConvexHull
12
+ import torch
13
+ from sync_batchnorm import DataParallelWithCallback
14
+ import face_alignment
15
+
16
+ from modules.generator import OcclusionAwareGenerator_SPADE
17
+ from modules.keypoint_detector import KPDetector
18
+
19
+
20
+ def normalize_kp(kp_source, kp_driving, kp_driving_initial, adapt_movement_scale=False,
21
+ use_relative_movement=False, use_relative_jacobian=False):
22
+ kp_new = {k: v for k, v in kp_driving.items()}
23
+
24
+ if adapt_movement_scale:
25
+ source_area = ConvexHull(kp_source['value'][0].data.cpu().numpy()).volume
26
+ driving_area = ConvexHull(kp_driving_initial['value'][0].data.cpu().numpy()).volume
27
+ adapt_movement_scale = np.sqrt(source_area) / np.sqrt(driving_area)
28
+ kp_new['value'] = kp_driving['value'] * adapt_movement_scale # for reenactment demo
29
+ else:
30
+ adapt_movement_scale = 1
31
+
32
+ if use_relative_movement:
33
+ kp_value_diff = (kp_driving['value'] - kp_driving_initial['value'])
34
+ kp_value_diff *= adapt_movement_scale
35
+ kp_new['value'] = kp_value_diff + kp_source['value']
36
+
37
+ if use_relative_jacobian:
38
+ jacobian_diff = torch.matmul(kp_driving['jacobian'], torch.inverse(kp_driving_initial['jacobian']))
39
+ kp_new['jacobian'] = torch.matmul(jacobian_diff, kp_source['jacobian'])
40
+
41
+ return kp_new
42
+
43
+
44
+ def load_checkpoints(config_path, checkpoint_path, cpu=False):
45
+ with open(config_path) as f:
46
+ # config = yaml.load(f)
47
+ config = yaml.load(f, Loader=yaml.FullLoader)
48
+
49
+ generator = OcclusionAwareGenerator_SPADE(**config['model_params']['generator_params'],
50
+ **config['model_params']['common_params'])
51
+ if not cpu:
52
+ generator.cuda()
53
+
54
+ kp_detector = KPDetector(**config['model_params']['kp_detector_params'],
55
+ **config['model_params']['common_params'])
56
+ if not cpu:
57
+ kp_detector.cuda()
58
+
59
+ if cpu:
60
+ checkpoint = torch.load(checkpoint_path, map_location=torch.device('cpu'))
61
+ else:
62
+ checkpoint = torch.load(checkpoint_path)
63
+
64
+ generator.load_state_dict(checkpoint['generator'])
65
+ kp_detector.load_state_dict(checkpoint['kp_detector'])
66
+
67
+ if not cpu:
68
+ generator = DataParallelWithCallback(generator)
69
+ kp_detector = DataParallelWithCallback(kp_detector)
70
+
71
+ generator.eval()
72
+ kp_detector.eval()
73
+
74
+ return generator, kp_detector
75
+
76
+
77
+ def make_animation(source_image, driving_video, generator, kp_detector, relative=True, adapt_movement_scale=True,
78
+ cpu=False):
79
+ with torch.no_grad():
80
+ predictions = []
81
+ source = torch.tensor(source_image[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)
82
+ if not cpu:
83
+ source = source.cuda()
84
+ driving = torch.tensor(np.array(driving_video)[np.newaxis].astype(np.float32)).permute(0, 4, 1, 2, 3)
85
+ kp_source = kp_detector(source)
86
+ kp_driving_initial = kp_detector(driving[:, :, 0])
87
+
88
+ for frame_idx in tqdm(range(driving.shape[2])):
89
+ driving_frame = driving[:, :, frame_idx]
90
+ if not cpu:
91
+ driving_frame = driving_frame.cuda()
92
+ kp_driving = kp_detector(driving_frame)
93
+ kp_norm = normalize_kp(kp_source=kp_source, kp_driving=kp_driving,
94
+ kp_driving_initial=kp_driving_initial, use_relative_movement=relative,
95
+ use_relative_jacobian=relative, adapt_movement_scale=adapt_movement_scale)
96
+ out = generator(source, kp_source=kp_source, kp_driving=kp_norm)
97
+
98
+ predictions.append(np.transpose(out['prediction'].data.cpu().numpy(), [0, 2, 3, 1])[0])
99
+ return predictions
100
+
101
+
102
+ def find_best_frame_func(source, driving, cpu=False):
103
+ def normalize_kp_infunc(kp):
104
+ kp = kp - kp.mean(axis=0, keepdims=True)
105
+ area = ConvexHull(kp[:, :2]).volume
106
+ area = np.sqrt(area)
107
+ kp[:, :2] = kp[:, :2] / area
108
+ return kp
109
+
110
+ fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, flip_input=True,
111
+ device='cpu' if cpu else 'cuda')
112
+ kp_source = fa.get_landmarks(255 * source)[0]
113
+ kp_source = normalize_kp_infunc(kp_source)
114
+ norm = float('inf')
115
+ frame_num = 0
116
+ for i, image in tqdm(enumerate(driving)):
117
+ kp_driving = fa.get_landmarks(255 * image)[0]
118
+ kp_driving = normalize_kp_infunc(kp_driving)
119
+ new_norm = (np.abs(kp_source - kp_driving) ** 2).sum()
120
+ if new_norm < norm:
121
+ norm = new_norm
122
+ frame_num = i
123
+ return frame_num
124
+
125
+
126
+ def drive_im(source_image, driving_image, adapt_scale):
127
+ source_image = resize(source_image, (256, 256))[..., :3]
128
+ driving_image = [resize(driving_image, (256, 256))[..., :3]]
129
+
130
+ prediction = make_animation(source_image, driving_image, generator, kp_detector, relative=False,
131
+ adapt_movement_scale=adapt_scale, cpu=cpu)
132
+ return img_as_ubyte(prediction[0])
133
+
134
+
135
+ def drive_vi(source_image, driving_video, mode, find_best_frame, relative, adapt_scale):
136
+ reader = imageio.get_reader(driving_video)
137
+ fps = reader.get_meta_data()['fps']
138
+ driving_video = []
139
+ try:
140
+ for im in reader:
141
+ driving_video.append(im)
142
+ except RuntimeError:
143
+ pass
144
+ reader.close()
145
+
146
+
147
+ if mode == 'reconstruction':
148
+ source_image = driving_video[0]
149
+
150
+ source_image = resize(source_image, (256, 256))[..., :3]
151
+ driving_video = [resize(frame, (256, 256))[..., :3] for frame in driving_video]
152
+
153
+ if find_best_frame:
154
+ i = find_best_frame_func(source_image, driving_video, cpu=cpu)
155
+ print("Best frame: " + str(i))
156
+ driving_forward = driving_video[i:]
157
+ driving_backward = driving_video[:(i + 1)][::-1]
158
+ predictions_forward = make_animation(source_image, driving_forward, generator, kp_detector,
159
+ relative=relative, adapt_movement_scale=adapt_scale, cpu=cpu)
160
+ predictions_backward = make_animation(source_image, driving_backward, generator, kp_detector,
161
+ relative=relative, adapt_movement_scale=adapt_scale, cpu=cpu)
162
+ predictions = predictions_backward[::-1] + predictions_forward[1:]
163
+ else:
164
+ predictions = make_animation(source_image, driving_video, generator, kp_detector, relative=relative,
165
+ adapt_movement_scale=adapt_scale, cpu=cpu)
166
+ result_video_path = "result_video.mp4"
167
+ imageio.mimsave(result_video_path, [img_as_ubyte(frame) for frame in predictions], fps=fps)
168
+ return result_video_path
169
+
170
+
171
+ os.environ['CUDA_VISIBLE_DEVICES'] = "3"
172
+ config = "config/vox-256.yaml"
173
+ checkpoint = "00000099-checkpoint.pth.tar"
174
+ mode = "reenactment"
175
+ relative = True
176
+ adapt_scale = True
177
+ find_best_frame = True
178
+ cpu = torch.cuda.is_available() # decided by the deploying environment
179
+
180
+ description = "We propose a Face Neural Volume Rendering (FNeVR) network for more realistic face animation, by taking the merits of 2D motion warping on facial expression transformation and 3D volume rendering on high-quality image synthesis in a unified framework.<br>[Paper](https://arxiv.org/abs/2209.10340) and [Code](https://github.com/zengbohan0217/FNeVR)"
181
+ im_description = "We can animate a face portrait by a single image in this tab.<br>Please input the origin face and the driving face which provides pose and expression information, then we can obtain the virtual generated face.<br>We can select \"adaptive scale\" parameter for better optic flow estimation using adaptive movement scale based on convex hull of keypoints."
182
+ vi_description = "We can animate a face portrait by a video in this tab.<br>Please input the origin face and the driving video which provides pose and expression information, then we can obtain the virtual generated video.<br>Please select inference mode (reenactment for different identities and reconstruction for the same identities).<br>We can select \"find best frame\" parameter to generate video from the frame that is the most alligned with source image, select \"relative motion\" paramter to use relative keypoint coordinates for preserving global object geometry, and select \"adaptive scale\" parameter for better optic flow estimation using adaptive movement scale based on convex hull of keypoints."
183
+ acknowledgements = "This work was supported by “the Fundamental Research Funds for the Central Universities”, and the National Natural Science Foundation of China under Grant 62076016, Beijing Natural Science Foundation-Xiaomi Innovation Joint Fund L223024. Besides, we gratefully acknowledge the support of [MindSpore](https://www.mindspore.cn), CANN (Compute Architecture for Neural Networks) and Ascend AI processor used for this research.<br>Our FNeVR implementation is inspired by [FOMM](https://github.com/AliaksandrSiarohin/first-order-model) and [DECA](https://github.com/YadiraF/DECA). We appreciate the authors of these papers for making their codes available to the public."
184
+
185
+ generator, kp_detector = load_checkpoints(config_path=config, checkpoint_path=checkpoint, cpu=cpu)
186
+
187
+ # iface = gr.Interface(fn=drive_im,
188
+ # inputs=[gr.Image(label="Origin face"),
189
+ # gr.Image(label="Driving face"),
190
+ # gr.CheckboxGroup(label="adapt scale")],
191
+ # outputs=gr.Image(label="Generated face"), examples=[["sup-mat/source.png"], ["sup-mat/driving.png"]],
192
+ # title="Demostration of FNeVR", description=description)
193
+
194
+ with gr.Blocks(title="Demostration of FNeVR") as demo:
195
+ gr.Markdown("# <center> Demostration of FNeVR")
196
+ gr.Markdown(description)
197
+
198
+ with gr.Tab("Driving by image"):
199
+ gr.Markdown(im_description)
200
+
201
+ with gr.Row():
202
+ with gr.Column():
203
+ gr.Markdown("#### Inputs")
204
+ inp2 = gr.Image(label="Driving face")
205
+ inp1 = gr.Image(label="Origin face")
206
+
207
+ gr.Markdown("#### Parameter")
208
+ inp3 = gr.Checkbox(value=True, label="adaptive scale")
209
+
210
+ btn = gr.Button(value="Animate")
211
+ with gr.Column():
212
+ gr.Markdown("#### Output")
213
+ outp = gr.Image(label="Generated face")
214
+
215
+ gr.Examples([["sup-mat/driving.png", "sup-mat/source.png"]], [inp2, inp1])
216
+
217
+ btn.click(fn=drive_im, inputs=[inp1, inp2, inp3], outputs=outp)
218
+ with gr.Tab("Driving by video"):
219
+ gr.Markdown(vi_description)
220
+
221
+ with gr.Row():
222
+ with gr.Column():
223
+ gr.Markdown("#### Inputs")
224
+ inp2 = gr.Video(label="Driving video")
225
+ inp1 = gr.Image(label="Origin face")
226
+
227
+ gr.Markdown("#### Parameters")
228
+ inp3 = gr.Radio(choices=['reenactment', 'reconstruction'], value="reenactment", label="mode (if \"reconstruction\" selected, origin face is the first frame of driving video)")
229
+ inp4 = gr.Checkbox(value=True, label="find best frame (more time consumed)")
230
+ inp5 = gr.Checkbox(value=True, label="relative motion")
231
+ inp6 = gr.Checkbox(value=True, label="adaptive scale")
232
+
233
+ btn = gr.Button(value="Animate")
234
+ with gr.Column():
235
+ gr.Markdown("#### Output")
236
+ outp = gr.Video(label="Generated video")
237
+
238
+ gr.Examples([["sup-mat/driving.mp4", "sup-mat/source_for_video.png"]], [inp2, inp1])
239
+
240
+ btn.click(fn=drive_vi, inputs=[inp1, inp2, inp3, inp4, inp5, inp6], outputs=outp)
241
+
242
+ with gr.Tab("Real time animation"):
243
+ gr.Markdown("#### Real time animation")
244
+
245
+ gr.Markdown("## Acknowledgements")
246
+ gr.Markdown(acknowledgements)
247
+
248
+ demo.launch()