File size: 1,562 Bytes
98dae30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import subprocess
import os

def process_video_and_audio(face_path, audio_path):
    # Define the directory to store the processed video
    results_dir = "results"
    os.makedirs(results_dir, exist_ok=True)  # Create the directory if it doesn't exist

    # Extract the filename of the face video
    video_name = os.path.basename(face_path)

    # Define the output file path for the processed video
    outfile_path = os.path.join(results_dir, video_name)

    print(f"Processing face video: {face_path}, audio: {audio_path}, and saving to: {outfile_path}")

    # Define the command to run
    command = f"python3 inference.py --face {face_path} --audio {audio_path} --outfile {outfile_path}"

    try:
        # Run the command using subprocess.run
        result = subprocess.run(command, shell=True, capture_output=True, check=True, text=True)

        # Print the output of the command
        print("Output:", result.stdout)

        # Check if the command was successful
        if result.returncode == 0:
            print("Processing complete.")
            return outfile_path
        else:
            return f"Error occurred: {result.stderr}"
    except subprocess.CalledProcessError as e:
        return f"Error occurred: {e.stderr}"

# Define the Gradio interface
iface = gr.Interface(
    fn=process_video_and_audio,
    inputs=[gr.Video(label="Face Video"), gr.File(type='filepath',label="Audio")],
    outputs=gr.Video(label="Processed Video"),
    title="Video LipSyncing"
)

# Launch the Gradio interface
iface.launch()