Spaces:
Runtime error
Runtime error
Commit ·
e1d53b6
1
Parent(s): b4e4dd0
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import librosa
|
| 4 |
+
git lfs install
|
| 5 |
+
git clone https://huggingface.co/amongusrickroll68/MeloMind
|
| 6 |
+
from diffusers import DiffusionPipeline
|
| 7 |
+
|
| 8 |
+
pipeline = DiffusionPipeline.from_pretrained("amongusrickroll68/MeloMind")
|
| 9 |
+
class TextToMusicGenerator:
|
| 10 |
+
def __init__(self):
|
| 11 |
+
self.model = tf.keras.models.load_model('path/to/model')
|
| 12 |
+
self.sampling_rate = 22050
|
| 13 |
+
|
| 14 |
+
def generate_music(self, prompt):
|
| 15 |
+
prompt_encoded = self._encode_prompt(prompt)
|
| 16 |
+
sequence = self._generate_sequence(prompt_encoded)
|
| 17 |
+
audio = self._sequence_to_audio(sequence)
|
| 18 |
+
return audio
|
| 19 |
+
|
| 20 |
+
def _encode_prompt(self, prompt):
|
| 21 |
+
# encode text prompt as input for the model
|
| 22 |
+
# ...
|
| 23 |
+
return prompt_encoded
|
| 24 |
+
|
| 25 |
+
def _generate_sequence(self, prompt_encoded):
|
| 26 |
+
# generate sequence of musical notes from encoded prompt
|
| 27 |
+
# ...
|
| 28 |
+
return sequence
|
| 29 |
+
|
| 30 |
+
def _sequence_to_audio(self, sequence):
|
| 31 |
+
# convert sequence to audio waveform
|
| 32 |
+
notes = self._sequence_to_notes(sequence)
|
| 33 |
+
audio = self._notes_to_audio(notes)
|
| 34 |
+
return audio
|
| 35 |
+
|
| 36 |
+
def _sequence_to_notes(self, sequence):
|
| 37 |
+
# convert sequence of musical notes to Note objects
|
| 38 |
+
# ...
|
| 39 |
+
return notes
|
| 40 |
+
|
| 41 |
+
def _notes_to_audio(self, notes):
|
| 42 |
+
# convert Note objects to audio waveform
|
| 43 |
+
# ...
|
| 44 |
+
return audio
|
| 45 |
+
|
| 46 |
+
generator = TextToMusicGenerator()
|
| 47 |
+
prompt = "Generate a cheerful and upbeat song in the key of C major with a tempo of 120 bpm"
|
| 48 |
+
audio = generator.generate_music(prompt)
|
| 49 |
+
librosa.output.write_wav('generated_music.wav', audio, sr=generator.sampling_rate)
|
| 50 |
+
|