Praveenna/lip_sync
4
1import streamlit as st2import os3 4# Your Lipsync code here5def main():6 st.title("Lipsync App")7 st.markdown("Upload your video and audio files to create a lipsynced video.")8 9 # Audio upload10 st.sidebar.markdown("### Upload Audio")11 audio_file = st.sidebar.file_uploader("Upload Audio File", type=["wav"])12 13 # Video upload14 st.sidebar.markdown("### Upload Video")15 video_file = st.sidebar.file_uploader("Upload Video File", type=["mp4"])16 17 if st.sidebar.button("Sync Lips"):18 if audio_file and video_file:19 # Save audio file20 audio_file_path = "input_audio.wav"21 with open(audio_file_path, "wb") as audio_writer:22 audio_writer.write(audio_file.read())23 24 # Save video file25 video_file_path = "input_vid.mp4"26 with open(video_file_path, "wb") as video_writer:27 video_writer.write(video_file.read())28 29 # Run Lipsync code30 pad_top = 031 pad_bottom = 1032 pad_left = 033 pad_right = 034 rescale_factor = 135 nosmooth = True36 use_hd_model = False37 checkpoint_path = 'checkpoints/wav2lip.pth' if not use_hd_model else 'checkpoints/wav2lip_gan.pth'38 39 cmd = f"python inference.py --checkpoint_path {checkpoint_path} --face '{video_file_path}' --audio '{audio_file_path}' --pads {pad_top} {pad_bottom} {pad_left} {pad_right} --resize_factor {rescale_factor}"40 if nosmooth:41 cmd += " --nosmooth"42 43 os.system(cmd)44 45 output_file_path = 'results/result_voice.mp4'46 47 # Display output video48 if os.path.exists(output_file_path):49 st.video(output_file_path)50 else:51 st.error("Processing failed. Output video not found.")52 53if __name__ == "__main__":54 main()55 