Update README.md
Browse files
README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
---
|
2 |
-
inference:
|
3 |
tags:
|
4 |
- musicgen
|
5 |
license: cc-by-nc-4.0
|
6 |
-
pipeline_tag: text-to-
|
7 |
---
|
8 |
|
9 |
# MusicGen - Small - 300M
|
@@ -47,17 +47,30 @@ Try out MusicGen yourself!
|
|
47 |
|
48 |
You can run MusicGen locally with the 🤗 Transformers library from version 4.31.0 onwards.
|
49 |
|
50 |
-
1. First install the 🤗 [Transformers library](https://github.com/huggingface/transformers)
|
51 |
|
52 |
```
|
53 |
-
pip install
|
|
|
54 |
```
|
55 |
|
56 |
-
2. Run the
|
57 |
|
58 |
-
```
|
59 |
-
from transformers import
|
|
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
|
63 |
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")
|
@@ -73,7 +86,7 @@ audio_values = model.generate(**inputs, max_new_tokens=256)
|
|
73 |
|
74 |
3. Listen to the audio samples either in an ipynb notebook:
|
75 |
|
76 |
-
```
|
77 |
from IPython.display import Audio
|
78 |
|
79 |
sampling_rate = model.config.audio_encoder.sampling_rate
|
@@ -82,7 +95,7 @@ Audio(audio_values[0].numpy(), rate=sampling_rate)
|
|
82 |
|
83 |
Or save them as a `.wav` file using a third-party library, e.g. `scipy`:
|
84 |
|
85 |
-
```
|
86 |
import scipy
|
87 |
|
88 |
sampling_rate = model.config.audio_encoder.sampling_rate
|
|
|
1 |
---
|
2 |
+
inference: true
|
3 |
tags:
|
4 |
- musicgen
|
5 |
license: cc-by-nc-4.0
|
6 |
+
pipeline_tag: text-to-speech
|
7 |
---
|
8 |
|
9 |
# MusicGen - Small - 300M
|
|
|
47 |
|
48 |
You can run MusicGen locally with the 🤗 Transformers library from version 4.31.0 onwards.
|
49 |
|
50 |
+
1. First install the 🤗 [Transformers library](https://github.com/huggingface/transformers) and scipy:
|
51 |
|
52 |
```
|
53 |
+
pip install --upgrade pip
|
54 |
+
pip install --upgrade transformers scipy
|
55 |
```
|
56 |
|
57 |
+
2. Run inference via the `Text-to-Audio` (TTA) pipeline. You can infer the MusicGen model via the TTA pipeline in just a few lines of code!
|
58 |
|
59 |
+
```python
|
60 |
+
from transformers import pipeline
|
61 |
+
import scipy
|
62 |
|
63 |
+
synthesiser = pipeline("text-to-audio", "facebook/musicgen-small")
|
64 |
+
|
65 |
+
music = pipe("lo-fi music with a soothing melody", forward_params={"do_sample": True})
|
66 |
+
|
67 |
+
scipy.io.wavfile.write("musicgen_out.wav", rate=music["sampling_rate"], music=audio["audio"])
|
68 |
+
```
|
69 |
+
|
70 |
+
3. Run inference via the Transformers modelling code. You can use the processor + generate code to convert text into a mono 32 kHz audio waveform for more fine-grained control.
|
71 |
+
|
72 |
+
```python
|
73 |
+
from transformers import AutoProcessor, MusicgenForConditionalGeneration
|
74 |
|
75 |
processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
|
76 |
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")
|
|
|
86 |
|
87 |
3. Listen to the audio samples either in an ipynb notebook:
|
88 |
|
89 |
+
```python
|
90 |
from IPython.display import Audio
|
91 |
|
92 |
sampling_rate = model.config.audio_encoder.sampling_rate
|
|
|
95 |
|
96 |
Or save them as a `.wav` file using a third-party library, e.g. `scipy`:
|
97 |
|
98 |
+
```python
|
99 |
import scipy
|
100 |
|
101 |
sampling_rate = model.config.audio_encoder.sampling_rate
|