Spaces:
Running
on
Zero
Running
on
Zero
artificialguybr
commited on
Commit
•
4830873
1
Parent(s):
69c7e2d
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torchaudio
|
3 |
from audiocraft.models import MusicGen
|
4 |
from audiocraft.data.audio import audio_write
|
5 |
import spaces
|
6 |
import logging
|
7 |
-
import os
|
8 |
import uuid
|
|
|
|
|
9 |
# Configura o logging
|
10 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
11 |
|
12 |
-
@spaces.GPU(duration=120)
|
13 |
def generate_music(description, melody_audio):
|
14 |
logging.info("Iniciando a geração de música.")
|
15 |
|
@@ -31,16 +33,23 @@ def generate_music(description, melody_audio):
|
|
31 |
else:
|
32 |
logging.info("Gerando música de forma incondicional.")
|
33 |
wav = model.generate_unconditional(1)
|
|
|
|
|
34 |
filename = f'{str(uuid.uuid4())}.wav'
|
35 |
-
|
|
|
|
|
36 |
logging.info(f"Salvando a música gerada em: {output_path}")
|
37 |
-
audio_write(output_path, wav[0].cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)
|
38 |
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
logging.info(f"A forma do tensor de áudio gerado: {wav[0].shape}")
|
41 |
logging.info("Música gerada e salva com sucesso.")
|
42 |
-
if not os.path.exists(output_path):
|
43 |
-
raise ValueError(f'Failed to save audio to {output_path}')
|
44 |
|
45 |
return output_path
|
46 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import torchaudio
|
3 |
from audiocraft.models import MusicGen
|
4 |
from audiocraft.data.audio import audio_write
|
5 |
import spaces
|
6 |
import logging
|
7 |
+
import os
|
8 |
import uuid
|
9 |
+
import tempfile
|
10 |
+
|
11 |
# Configura o logging
|
12 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
13 |
|
14 |
+
@spaces.GPU(duration=120)
|
15 |
def generate_music(description, melody_audio):
|
16 |
logging.info("Iniciando a geração de música.")
|
17 |
|
|
|
33 |
else:
|
34 |
logging.info("Gerando música de forma incondicional.")
|
35 |
wav = model.generate_unconditional(1)
|
36 |
+
|
37 |
+
# Gera nome de arquivo único
|
38 |
filename = f'{str(uuid.uuid4())}.wav'
|
39 |
+
|
40 |
+
# Salva na pasta temporária
|
41 |
+
output_path = tempfile.mktemp(suffix='.wav')
|
42 |
logging.info(f"Salvando a música gerada em: {output_path}")
|
|
|
43 |
|
44 |
+
audio_write(output_path, wav[0].cpu(), model.sample_rate,
|
45 |
+
strategy="loudness", loudness_compressor=True)
|
46 |
+
|
47 |
+
# Verifica se o arquivo existe
|
48 |
+
if not os.access(output_path, os.R_OK):
|
49 |
+
raise ValueError(f'Failed to save audio to {output_path}')
|
50 |
+
|
51 |
logging.info(f"A forma do tensor de áudio gerado: {wav[0].shape}")
|
52 |
logging.info("Música gerada e salva com sucesso.")
|
|
|
|
|
53 |
|
54 |
return output_path
|
55 |
|