Shadhil commited on
Commit
98dae30
1 Parent(s): e8b5998

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import os
4
+
5
+ def process_video_and_audio(face_path, audio_path):
6
+ # Define the directory to store the processed video
7
+ results_dir = "results"
8
+ os.makedirs(results_dir, exist_ok=True) # Create the directory if it doesn't exist
9
+
10
+ # Extract the filename of the face video
11
+ video_name = os.path.basename(face_path)
12
+
13
+ # Define the output file path for the processed video
14
+ outfile_path = os.path.join(results_dir, video_name)
15
+
16
+ print(f"Processing face video: {face_path}, audio: {audio_path}, and saving to: {outfile_path}")
17
+
18
+ # Define the command to run
19
+ command = f"python3 inference.py --face {face_path} --audio {audio_path} --outfile {outfile_path}"
20
+
21
+ try:
22
+ # Run the command using subprocess.run
23
+ result = subprocess.run(command, shell=True, capture_output=True, check=True, text=True)
24
+
25
+ # Print the output of the command
26
+ print("Output:", result.stdout)
27
+
28
+ # Check if the command was successful
29
+ if result.returncode == 0:
30
+ print("Processing complete.")
31
+ return outfile_path
32
+ else:
33
+ return f"Error occurred: {result.stderr}"
34
+ except subprocess.CalledProcessError as e:
35
+ return f"Error occurred: {e.stderr}"
36
+
37
+ # Define the Gradio interface
38
+ iface = gr.Interface(
39
+ fn=process_video_and_audio,
40
+ inputs=[gr.Video(label="Face Video"), gr.File(type='filepath',label="Audio")],
41
+ outputs=gr.Video(label="Processed Video"),
42
+ title="Video LipSyncing"
43
+ )
44
+
45
+ # Launch the Gradio interface
46
+ iface.launch()