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()