Spaces:
Running
on
L40S
Running
on
L40S
updated
Browse files
app.py
CHANGED
|
@@ -161,11 +161,12 @@ def generate_music(text_prompt, duration=10, guidance_scale=3.0):
|
|
| 161 |
max_val = np.max(np.abs(audio_data))
|
| 162 |
if max_val > 0:
|
| 163 |
audio_data = audio_data / max_val * 0.95 # Scale to 95% to avoid clipping
|
| 164 |
-
|
| 165 |
-
audio_data = audio_data.astype(np.
|
| 166 |
-
|
| 167 |
print(f"[GENERATION] Final audio shape: {audio_data.shape}")
|
| 168 |
-
print(f"[GENERATION] Audio range: [{np.min(audio_data)
|
|
|
|
| 169 |
print(f"[GENERATION] Sample rate: {sample_rate}")
|
| 170 |
|
| 171 |
timestamp = int(time.time() * 1000)
|
|
@@ -178,12 +179,13 @@ def generate_music(text_prompt, duration=10, guidance_scale=3.0):
|
|
| 178 |
file_size = os.path.getsize(temp_path)
|
| 179 |
print(f"[GENERATION] Audio saved to: {temp_path}")
|
| 180 |
print(f"[GENERATION] File size: {file_size} bytes")
|
|
|
|
|
|
|
|
|
|
| 181 |
else:
|
| 182 |
print(f"[ERROR] Failed to create audio file: {temp_path}")
|
| 183 |
return None
|
| 184 |
|
| 185 |
-
return temp_path
|
| 186 |
-
|
| 187 |
except Exception as e:
|
| 188 |
print(f"[ERROR] Generation failed: {str(e)}")
|
| 189 |
cleanup_gpu()
|
|
@@ -225,14 +227,7 @@ with gr.Blocks(title="MusicGen Large - Music Generation") as demo:
|
|
| 225 |
with gr.Column():
|
| 226 |
audio_output = gr.Audio(
|
| 227 |
label="Generated Music",
|
| 228 |
-
type="
|
| 229 |
-
format="wav",
|
| 230 |
-
interactive=False,
|
| 231 |
-
autoplay=True,
|
| 232 |
-
show_download_button=True,
|
| 233 |
-
waveform_options=gr.WaveformOptions(
|
| 234 |
-
show_recording_waveform=True
|
| 235 |
-
)
|
| 236 |
)
|
| 237 |
|
| 238 |
with gr.Accordion("Tips", open=False):
|
|
|
|
| 161 |
max_val = np.max(np.abs(audio_data))
|
| 162 |
if max_val > 0:
|
| 163 |
audio_data = audio_data / max_val * 0.95 # Scale to 95% to avoid clipping
|
| 164 |
+
|
| 165 |
+
audio_data = (audio_data * 32767).astype(np.int16). ###
|
| 166 |
+
|
| 167 |
print(f"[GENERATION] Final audio shape: {audio_data.shape}")
|
| 168 |
+
print(f"[GENERATION] Audio range: [{np.min(audio_data)}, {np.max(audio_data)}]")
|
| 169 |
+
print(f"[GENERATION] Audio dtype: {audio_data.dtype}")
|
| 170 |
print(f"[GENERATION] Sample rate: {sample_rate}")
|
| 171 |
|
| 172 |
timestamp = int(time.time() * 1000)
|
|
|
|
| 179 |
file_size = os.path.getsize(temp_path)
|
| 180 |
print(f"[GENERATION] Audio saved to: {temp_path}")
|
| 181 |
print(f"[GENERATION] File size: {file_size} bytes")
|
| 182 |
+
|
| 183 |
+
print(f"[GENERATION] Returning numpy tuple: ({sample_rate}, audio_array)")
|
| 184 |
+
return (sample_rate, audio_data)
|
| 185 |
else:
|
| 186 |
print(f"[ERROR] Failed to create audio file: {temp_path}")
|
| 187 |
return None
|
| 188 |
|
|
|
|
|
|
|
| 189 |
except Exception as e:
|
| 190 |
print(f"[ERROR] Generation failed: {str(e)}")
|
| 191 |
cleanup_gpu()
|
|
|
|
| 227 |
with gr.Column():
|
| 228 |
audio_output = gr.Audio(
|
| 229 |
label="Generated Music",
|
| 230 |
+
type="numpy"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
)
|
| 232 |
|
| 233 |
with gr.Accordion("Tips", open=False):
|