Spaces:
Running
Running
modify app
Browse files
app.py
CHANGED
@@ -40,6 +40,29 @@ def loudness_normalize(audio, sample_rate, target_loudness=-12.0):
|
|
40 |
loudness_normalized_audio = pyln.normalize.loudness(audio, loudness, target_loudness)
|
41 |
return loudness_normalized_audio
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
def process_audio(input_audio, reference_audio):
|
44 |
output_audio, predicted_params, sr = mastering_transfer.process_audio(
|
45 |
input_audio, reference_audio, reference_audio
|
@@ -138,6 +161,34 @@ with gr.Blocks() as demo:
|
|
138 |
outputs=[output_audio, param_output]
|
139 |
)
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
gr.Markdown("## Inference Time Optimization (ITO)")
|
142 |
|
143 |
with gr.Row():
|
|
|
40 |
loudness_normalized_audio = pyln.normalize.loudness(audio, loudness, target_loudness)
|
41 |
return loudness_normalized_audio
|
42 |
|
43 |
+
def process_youtube_url(url):
|
44 |
+
try:
|
45 |
+
audio, sr = download_youtube_audio(url)
|
46 |
+
return (sr, audio)
|
47 |
+
except Exception as e:
|
48 |
+
return None, f"Error processing YouTube URL: {str(e)}"
|
49 |
+
|
50 |
+
def process_audio_with_youtube(input_audio, input_youtube_url, reference_audio, reference_youtube_url):
|
51 |
+
if input_youtube_url:
|
52 |
+
input_audio, error = process_youtube_url(input_youtube_url)
|
53 |
+
if error:
|
54 |
+
return None, None, error
|
55 |
+
|
56 |
+
if reference_youtube_url:
|
57 |
+
reference_audio, error = process_youtube_url(reference_youtube_url)
|
58 |
+
if error:
|
59 |
+
return None, None, error
|
60 |
+
|
61 |
+
if input_audio is None or reference_audio is None:
|
62 |
+
return None, None, "Both input and reference audio are required."
|
63 |
+
|
64 |
+
return process_audio(input_audio, reference_audio)
|
65 |
+
|
66 |
def process_audio(input_audio, reference_audio):
|
67 |
output_audio, predicted_params, sr = mastering_transfer.process_audio(
|
68 |
input_audio, reference_audio, reference_audio
|
|
|
161 |
outputs=[output_audio, param_output]
|
162 |
)
|
163 |
|
164 |
+
with gr.Tab("YouTube Audio"):
|
165 |
+
with gr.Row():
|
166 |
+
input_audio_yt = gr.Audio(label="Input Audio (Optional)")
|
167 |
+
input_youtube_url = gr.Textbox(label="Input YouTube URL (Optional)")
|
168 |
+
with gr.Row():
|
169 |
+
reference_audio_yt = gr.Audio(label="Reference Audio (Optional)")
|
170 |
+
reference_youtube_url = gr.Textbox(label="Reference YouTube URL (Optional)")
|
171 |
+
|
172 |
+
process_button_yt = gr.Button("Process Mastering Style Transfer")
|
173 |
+
|
174 |
+
with gr.Row():
|
175 |
+
output_audio_yt = gr.Audio(label="Output Audio", type='numpy')
|
176 |
+
param_output_yt = gr.Textbox(label="Predicted Parameters", lines=5)
|
177 |
+
|
178 |
+
error_message_yt = gr.Textbox(label="Error Message", visible=False)
|
179 |
+
|
180 |
+
def process_and_handle_errors(input_audio, input_youtube_url, reference_audio, reference_youtube_url):
|
181 |
+
result = process_audio_with_youtube(input_audio, input_youtube_url, reference_audio, reference_youtube_url)
|
182 |
+
if len(result) == 3 and isinstance(result[2], str): # Error occurred
|
183 |
+
return None, None, gr.update(visible=True, value=result[2])
|
184 |
+
return result[0], result[1], gr.update(visible=False, value="")
|
185 |
+
|
186 |
+
process_button_yt.click(
|
187 |
+
process_and_handle_errors,
|
188 |
+
inputs=[input_audio_yt, input_youtube_url, reference_audio_yt, reference_youtube_url],
|
189 |
+
outputs=[output_audio_yt, param_output_yt, error_message_yt]
|
190 |
+
)
|
191 |
+
|
192 |
gr.Markdown("## Inference Time Optimization (ITO)")
|
193 |
|
194 |
with gr.Row():
|