darshankr commited on
Commit
4391147
·
verified ·
1 Parent(s): 2ff20eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -4,14 +4,13 @@ import os
4
  import requests
5
 
6
  def process_video(audio_file, video_file):
7
- # Define file paths
8
- audio_path = audio_file.name
9
- video_path = video_file.name
10
  out_path = "output_video.mp4"
11
 
12
- # Save uploaded files
13
- audio_file.save(audio_path)
14
- video_file.save(video_path)
15
 
16
  # Define command flags
17
  sample_mode = "cross" # or "reconstruction"
@@ -43,24 +42,29 @@ def process_video(audio_file, video_file):
43
  return f"Error processing video: {e}"
44
  finally:
45
  # Clean up the files after processing
46
- if os.path.exists(audio_path):
47
- os.remove(audio_path)
48
- if os.path.exists(video_path):
49
- os.remove(video_path)
50
  if os.path.exists(out_path):
51
  os.remove(out_path)
52
 
53
  # Create a Gradio interface
54
- iface = gr.Interface(
55
- fn=process_video,
56
- inputs=[
57
- gr.Audio(label="Input Audio"), # Updated syntax
58
- gr.Video(label="Input Video") # Updated syntax
59
- ],
60
- outputs=gr.Video(label="Processed Video"), # Updated syntax
61
- title="Audio-Video Processing",
62
- description="Upload an audio file and a video file to process the video based on the audio input."
63
- )
 
 
 
 
 
 
 
 
64
 
65
  # Launch the interface
66
  iface.launch()
 
4
  import requests
5
 
6
  def process_video(audio_file, video_file):
7
+ # Unpack the audio and video file tuples
8
+ audio_path = audio_file[1] if isinstance(audio_file, tuple) else audio_file
9
+ video_path = video_file[1] if isinstance(video_file, tuple) else video_file
10
  out_path = "output_video.mp4"
11
 
12
+ # No need to save files as Gradio now handles this automatically
13
+ # and provides the path directly
 
14
 
15
  # Define command flags
16
  sample_mode = "cross" # or "reconstruction"
 
42
  return f"Error processing video: {e}"
43
  finally:
44
  # Clean up the files after processing
45
+ # Don't remove input files as they're managed by Gradio
 
 
 
46
  if os.path.exists(out_path):
47
  os.remove(out_path)
48
 
49
  # Create a Gradio interface
50
+ with gr.Blocks() as iface:
51
+ gr.Markdown("# Audio-Video Processing")
52
+ gr.Markdown("Upload an audio file and a video file to process the video based on the audio input.")
53
+
54
+ with gr.Row():
55
+ audio_input = gr.Audio(label="Input Audio", type="filepath")
56
+ video_input = gr.Video(label="Input Video", type="filepath")
57
+
58
+ with gr.Row():
59
+ process_button = gr.Button("Process Video")
60
+
61
+ video_output = gr.Video(label="Processed Video")
62
+
63
+ process_button.click(
64
+ fn=process_video,
65
+ inputs=[audio_input, video_input],
66
+ outputs=video_output
67
+ )
68
 
69
  # Launch the interface
70
  iface.launch()