Omnibus commited on
Commit
26a0249
1 Parent(s): 13067ba

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ from pathlib import Path
3
+
4
+ from audiocraft.models import musicgen
5
+ from audiocraft.data.audio import audio_write
6
+ #from audiocraft.utils.notebook import display_audio
7
+
8
+ model = musicgen.MusicGen.get_pretrained('nateraw/musicgen-songstarter-v0.1', device='cpu')
9
+
10
+ # path to save our samples.
11
+ out_dir = Path("./samples")
12
+ out_dir.mkdir(exist_ok=True, parents=True)
13
+
14
+ model.set_generation_params(
15
+ duration=15,
16
+ use_sampling=True,
17
+ temperature=1.0,
18
+ top_k=250,
19
+ cfg_coef=3.0,
20
+ )
21
+
22
+ text = "hip hop, soul, piano, chords, jazz, neo jazz, G# minor, 140 bpm"
23
+ N = 4
24
+ out = model.generate(
25
+ [text] * N,
26
+ progress=True,
27
+ )
28
+
29
+ # Write to files
30
+ dt_str = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
31
+ for i in range(N):
32
+ audio_write(
33
+ out_dir / f"{dt_str}_{i:02d}",
34
+ out[i].cpu(),
35
+ model.sample_rate,
36
+ strategy="loudness",
37
+ )
38
+
39
+ # Or, if in a notebook, display audio widgets
40
+ # display_audio(out, model.sample_rate)