Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from IPython.display import clear_output
|
4 |
+
|
5 |
+
# Your Lipsync code here
|
6 |
+
def main():
|
7 |
+
st.title("Lipsync App")
|
8 |
+
st.markdown("Upload your video and audio files to create a lipsynced video.")
|
9 |
+
|
10 |
+
# Audio upload
|
11 |
+
st.sidebar.markdown("### Upload Audio")
|
12 |
+
audio_file = st.sidebar.file_uploader("Upload Audio File", type=["wav"])
|
13 |
+
|
14 |
+
# Video upload
|
15 |
+
st.sidebar.markdown("### Upload Video")
|
16 |
+
video_file = st.sidebar.file_uploader("Upload Video File", type=["mp4"])
|
17 |
+
|
18 |
+
if st.sidebar.button("Sync Lips"):
|
19 |
+
if audio_file and video_file:
|
20 |
+
# Save audio file
|
21 |
+
with open("/content/sample_data/input_audio.wav", "wb") as audio_writer:
|
22 |
+
audio_writer.write(audio_file.read())
|
23 |
+
|
24 |
+
# Save video file
|
25 |
+
with open("/content/sample_data/input_vid.mp4", "wb") as video_writer:
|
26 |
+
video_writer.write(video_file.read())
|
27 |
+
|
28 |
+
# Run Lipsync code
|
29 |
+
pad_top = 0
|
30 |
+
pad_bottom = 10
|
31 |
+
pad_left = 0
|
32 |
+
pad_right = 0
|
33 |
+
rescaleFactor = 1
|
34 |
+
nosmooth = True
|
35 |
+
use_hd_model = False
|
36 |
+
checkpoint_path = 'checkpoints/wav2lip.pth' if not use_hd_model else 'checkpoints/wav2lip_gan.pth'
|
37 |
+
|
38 |
+
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}"
|
39 |
+
if nosmooth:
|
40 |
+
cmd += " --nosmooth"
|
41 |
+
|
42 |
+
os.system(cmd)
|
43 |
+
|
44 |
+
output_file_path = '/content/Wav2Lip/results/result_voice.mp4'
|
45 |
+
|
46 |
+
# Display output video
|
47 |
+
if os.path.exists(output_file_path):
|
48 |
+
clear_output()
|
49 |
+
st.video(output_file_path)
|
50 |
+
else:
|
51 |
+
st.error("Processing failed. Output video not found.")
|
52 |
+
|
53 |
+
if __name__ == "__main__":
|
54 |
+
main()
|