File size: 1,969 Bytes
88c69aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import os
from IPython.display import clear_output

# Your Lipsync code here
def main():
    st.title("Lipsync App")
    st.markdown("Upload your video and audio files to create a lipsynced video.")

    # Audio upload
    st.sidebar.markdown("### Upload Audio")
    audio_file = st.sidebar.file_uploader("Upload Audio File", type=["wav"])

    # Video upload
    st.sidebar.markdown("### Upload Video")
    video_file = st.sidebar.file_uploader("Upload Video File", type=["mp4"])

    if st.sidebar.button("Sync Lips"):
        if audio_file and video_file:
            # Save audio file
            with open("/content/sample_data/input_audio.wav", "wb") as audio_writer:
                audio_writer.write(audio_file.read())

            # Save video file
            with open("/content/sample_data/input_vid.mp4", "wb") as video_writer:
                video_writer.write(video_file.read())

            # Run Lipsync code
            pad_top =  0
            pad_bottom =  10
            pad_left =  0
            pad_right =  0
            rescaleFactor =  1
            nosmooth = True
            use_hd_model = False
            checkpoint_path = 'checkpoints/wav2lip.pth' if not use_hd_model else 'checkpoints/wav2lip_gan.pth'

            cmd = f"!python inference.py --checkpoint_path {checkpoint_path} --face '/content/sample_data/input_vid.mp4' --audio '/content/sample_data/input_audio.wav' --pads {pad_top} {pad_bottom} {pad_left} {pad_right} --resize_factor {rescaleFactor}"
            if nosmooth:
                cmd += " --nosmooth"

            os.system(cmd)

            output_file_path = '/content/Wav2Lip/results/result_voice.mp4'

            # Display output video
            if os.path.exists(output_file_path):
                clear_output()
                st.video(output_file_path)
            else:
                st.error("Processing failed. Output video not found.")

if __name__ == "__main__":
    main()