File size: 2,987 Bytes
dc9acf1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2a9297b
 
dc9acf1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
564c46b
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
import os, sys
import gradio as gr
from src.gradio_demo import SadTalker  

try:
    import webui  # in webui
    in_webui = True
except:
    in_webui = False

def toggle_audio_file(choice):
    if choice == False:
        return gr.update(visible=True), gr.update(visible=False)
    else:
        return gr.update(visible=False), gr.update(visible=True)
    
def ref_video_fn(path_of_ref_video):
    if path_of_ref_video is not None:
        return gr.update(value=True)
    else:
        return gr.update(value=False)

sad_talker = SadTalker("checkpoints", "src/config", lazy_load=True)

with gr.Blocks(analytics_enabled=False) as demo:
        
    with gr.Row().style(equal_height=False):
        with gr.Column(variant='panel'):
            with gr.Tabs(elem_id="sadtalker_source_image"):
                with gr.TabItem('Upload image'):
                    with gr.Row():
                        source_image = gr.Image(label="Source image", source="upload", type="filepath", elem_id="img2img_image").style(width=512)

            with gr.Tabs(elem_id="sadtalker_driven_audio"):
                with gr.TabItem('Upload OR TTS'):
                    with gr.Column(variant='panel'):
                        driven_audio = gr.Audio(label="Input audio", source="upload", type="filepath")

        with gr.Column(variant='panel'): 
            with gr.Tabs(elem_id="sadtalker_checkbox"):
                with gr.TabItem('Settings'):
                    with gr.Column(variant='panel'):
                        pose_style = gr.Slider(minimum=0, maximum=46, step=1, label="Pose style", value=0) # 
                        size_of_image = gr.Radio([256, 512], value=512, label='face model resolution', info="use 256/512 model?") # 
                        preprocess_type = gr.Radio(['crop', 'resize','full', 'extcrop', 'extfull'], value='full', label='preprocess', info="How to handle input image?")
                        is_still_mode = gr.Checkbox(label="Still Mode (fewer hand motion, works with preprocess `full`)")
                        batch_size = gr.Slider(label="batch size in generation", step=1, maximum=10, value=2)
                        enhancer = gr.Checkbox(label="GFPGAN as Face enhancer")
                        submit = gr.Button('Generate', elem_id="sadtalker_generate", variant='primary')
                            
            with gr.Tabs(elem_id="sadtalker_genearted"):
                    gen_video = gr.Video(label="Generated video", format="mp4").style(width=256)

    submit.click(
                fn=sad_talker.test, 
                inputs=[source_image,
                        driven_audio,
                        preprocess_type,
                        is_still_mode,
                        enhancer,
                        batch_size,                            
                        size_of_image,
                        pose_style
                        ], 
                outputs=[gen_video]
                )

demo.queue().launch()