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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -4,14 +4,11 @@ import os
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"
17
  generate_from_filelist = 0
@@ -41,8 +38,7 @@ def process_video(audio_file, video_file):
41
  except subprocess.CalledProcessError as e:
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
 
@@ -52,18 +48,30 @@ with gr.Blocks() as iface:
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
 
4
  import requests
5
 
6
  def process_video(audio_file, video_file):
7
+ # Unpack the audio and video file paths
8
  audio_path = audio_file[1] if isinstance(audio_file, tuple) else audio_file
9
+ video_path = video_file if isinstance(video_file, str) else video_file.name
10
  out_path = "output_video.mp4"
11
 
 
 
 
12
  # Define command flags
13
  sample_mode = "cross" # or "reconstruction"
14
  generate_from_filelist = 0
 
38
  except subprocess.CalledProcessError as e:
39
  return f"Error processing video: {e}"
40
  finally:
41
+ # Clean up output file if it exists
 
42
  if os.path.exists(out_path):
43
  os.remove(out_path)
44
 
 
48
  gr.Markdown("Upload an audio file and a video file to process the video based on the audio input.")
49
 
50
  with gr.Row():
51
+ audio_input = gr.Audio(label="Input Audio", source="upload")
52
+ video_input = gr.Video(label="Input Video", source="upload")
53
 
54
  with gr.Row():
55
  process_button = gr.Button("Process Video")
56
+ status_msg = gr.Textbox(label="Status", interactive=False)
57
+
58
  video_output = gr.Video(label="Processed Video")
59
 
60
+ def process_with_status(audio, video):
61
+ try:
62
+ status_msg.update(value="Processing... Please wait.")
63
+ result = process_video(audio, video)
64
+ status_msg.update(value="Done!")
65
+ return [result, "Processing completed successfully!"]
66
+ except Exception as e:
67
+ error_msg = f"Error during processing: {str(e)}"
68
+ status_msg.update(value=error_msg)
69
+ return [None, error_msg]
70
+
71
  process_button.click(
72
+ fn=process_with_status,
73
  inputs=[audio_input, video_input],
74
+ outputs=[video_output, status_msg]
75
  )
76
 
77
  # Launch the interface