Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ import shutil
|
|
7 |
import numpy as np
|
8 |
import matplotlib.pyplot as plt
|
9 |
from scipy.io import wavfile
|
|
|
10 |
|
11 |
# download model
|
12 |
huggingface_hub.snapshot_download(
|
@@ -71,7 +72,7 @@ def plot_spectrogram(wav_file, output_image):
|
|
71 |
audio_data = audio_data.mean(axis=1)
|
72 |
|
73 |
# Create a plot for the spectrogram
|
74 |
-
plt.figure(figsize=(10,
|
75 |
plt.specgram(audio_data, Fs=sample_rate, NFFT=1024, noverlap=512, cmap='gray', aspect='auto')
|
76 |
|
77 |
# Remove gridlines and ticks for a cleaner look
|
@@ -81,7 +82,22 @@ def plot_spectrogram(wav_file, output_image):
|
|
81 |
|
82 |
# Save the plot as an image file
|
83 |
plt.savefig(output_image, bbox_inches='tight', pad_inches=0, dpi=300)
|
84 |
-
plt.close
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
def infer(video_in):
|
87 |
|
@@ -124,15 +140,18 @@ def infer(video_in):
|
|
124 |
with gr.Blocks() as demo:
|
125 |
with gr.Column(elem_id="col-container"):
|
126 |
gr.Markdown("# Video-To-Audio")
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
132 |
submit_btn.click(
|
133 |
fn = infer,
|
134 |
inputs = [video_in],
|
135 |
-
outputs = [output_sound, output_spectrogram],
|
136 |
show_api = False
|
137 |
)
|
138 |
demo.launch(show_api=False, show_error=True)
|
|
|
7 |
import numpy as np
|
8 |
import matplotlib.pyplot as plt
|
9 |
from scipy.io import wavfile
|
10 |
+
from moviepy.editor import VideoFileClip, AudioFileClip
|
11 |
|
12 |
# download model
|
13 |
huggingface_hub.snapshot_download(
|
|
|
72 |
audio_data = audio_data.mean(axis=1)
|
73 |
|
74 |
# Create a plot for the spectrogram
|
75 |
+
plt.figure(figsize=(10, 2))
|
76 |
plt.specgram(audio_data, Fs=sample_rate, NFFT=1024, noverlap=512, cmap='gray', aspect='auto')
|
77 |
|
78 |
# Remove gridlines and ticks for a cleaner look
|
|
|
82 |
|
83 |
# Save the plot as an image file
|
84 |
plt.savefig(output_image, bbox_inches='tight', pad_inches=0, dpi=300)
|
85 |
+
plt.close
|
86 |
+
|
87 |
+
def merge_audio_to_video(input_vid, input_aud):
|
88 |
+
# Load the video file
|
89 |
+
video = VideoFileClip(input_vid)
|
90 |
+
|
91 |
+
# Load the new audio file
|
92 |
+
new_audio = AudioFileClip(input_aud)
|
93 |
+
|
94 |
+
# Set the new audio to the video
|
95 |
+
video_with_new_audio = video.set_audio(new_audio)
|
96 |
+
|
97 |
+
# Save the result to a new file
|
98 |
+
video_with_new_audio.write_videofile("output_video.mp4", codec='libx264', audio_codec='aac')
|
99 |
+
|
100 |
+
return "output_video.mp4"
|
101 |
|
102 |
def infer(video_in):
|
103 |
|
|
|
140 |
with gr.Blocks() as demo:
|
141 |
with gr.Column(elem_id="col-container"):
|
142 |
gr.Markdown("# Video-To-Audio")
|
143 |
+
with gr.Row():
|
144 |
+
video_in = gr.Video(label='Video IN')
|
145 |
+
submit_btn = gr.Button("Submit")
|
146 |
+
with gr.Row():
|
147 |
+
output_sound = gr.Audio(label="Audio OUT")
|
148 |
+
output_spectrogram = gr.Image(label='Spectrogram')
|
149 |
+
merged_out = gr.Video(label="Merged video + generated audio")
|
150 |
+
|
151 |
submit_btn.click(
|
152 |
fn = infer,
|
153 |
inputs = [video_in],
|
154 |
+
outputs = [output_sound, output_spectrogram, merged_out],
|
155 |
show_api = False
|
156 |
)
|
157 |
demo.launch(show_api=False, show_error=True)
|