File size: 3,068 Bytes
e5a51ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import tempfile
import subprocess
import streamlit as st
import logging
import numpy as np
import sys

# Clear the cache programmatically
st.cache_data.clear()
st.cache_resource.clear()
st.write("Streamlit cache has been cleared.")


numpy_path = np.__file__

st.write("Numpy is installed at: ")
st.code(numpy_path)

# Set up logging
logging.basicConfig(level=logging.INFO)

processed_file_path = None

# Allowed file extensions
ALLOWED_AUDIO_VIDEO_EXTENSIONS = {'mp3', 'mp4', 'wav'}

# Streamlit App
st.title("Audio-Video Inference App")
st.write("Upload a video file and an audio file for processing.")

# File Upload
video_file = st.file_uploader("Upload Video File (mp4):", type=['mp3', 'mp4', 'wav'])
audio_file = st.file_uploader("Upload Audio File (mp3, wav):", type=['mp3', 'mp4', 'wav'])

# Path to checkpoint
checkpoint_path = "checkpoints/wav2lip_gan.pth"

# Process files on button click
if st.button("Process Files"):
    if video_file is None or audio_file is None:
        st.error("Please upload both video and audio files!")
    else:
        # Save uploaded files temporarily
        with tempfile.TemporaryDirectory() as tempdir:
            video_path = os.path.join(tempdir, video_file.name)
            audio_path = os.path.join(tempdir, audio_file.name)
            output_path = "./results/result_voice.mp4"
            
            with open(video_path, "wb") as f:
                f.write(video_file.read())
            
            with open(audio_path, "wb") as f:
                f.write(audio_file.read())

            # Run the inference script
            try:
                st.info("Processing files... This may take a moment.")
                result = subprocess.run(
                    ['python', 'inference.py', '--checkpoint_path', checkpoint_path, '--face', video_path, '--audio', audio_path],
                    capture_output=True, text=True
                )

                # Show output
                if result.returncode == 0:
                    st.success("Processing complete!")
                    processed_file_path = output_path  # Save processed file path for download
                    st.success("Processed file saved at: " + processed_file_path)
                else:
                    st.error(f"Error during processing:\n{result.stderr}")
            except Exception as e:
                st.error(f"An error occurred: {e}")

# Provide the download button if the file was successfully processed
if processed_file_path: 
#and os.path.exists(processed_file_path):
    st.success("Download your processed file below:")
    with open(processed_file_path, "rb") as f:
        st.download_button(
            label="Download Processed Video",
            data=f,
            file_name="result_voice.mp4",
            mime="video/mp4"
            )

st.write("Numpy is installed at: ")
st.code(numpy_path)

st.write("python version: ",sys.version)

import os

st.write("Python Executable:", sys.executable)
st.write("Python Version:", sys.version)
st.write("Environment Variables:", os.environ)