Spaces:
Sleeping
Sleeping
File size: 1,635 Bytes
df7326d 14e425b b97eb76 963f674 df7326d 4066139 5a114c0 963f674 d0befe8 c0479c9 d0befe8 b97eb76 c44d5aa 5a114c0 b97eb76 963f674 ca309ed df7326d 5a114c0 df7326d 6fd7b3a 482d77f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import gradio as gr
import numpy
import pathlib
import tensorflow as tf
from PIL import Image
from music21 import stream,chord,duration,clef
myModel = tf.keras.models.load_model('my_model.h5')
class_names = ['Crash',
'Crash + KickBass',
'Crash + Snare',
'Crash + Snare + KickBass',
'Crash + Tom',
'Crash + Tom + KickBass',
'Hihat',
'Hihat + KickBass',
'Hihat + Snare',
'Hihat + Snare + KickBass',
'Hihat + Tom',
'Hihat + Tom + KickBass',
'KickBass',
'Ride',
'Ride + KickBass',
'Ride + Snare',
'Ride + Snare + KickBass',
'Ride + Tom',
'Ride + Tom + KickBass',
'Snare',
'Snare + KickBass',
'Snare + Tom',
'Snare + Tom + KickBass',
'Tom',
'Tom + KickBass']
def PredictionToNotation(predict):
score = stream.Score()
drum_part = stream.Part()
drum_part.id = 'Drums'
for prediction in predict:
n=chord.Chord(PredictionToChord(prediction))
n.duration = duration.Duration(0.5)
drum_part.append(n)
drum_part.clef = clef.PercussionClef()
score.insert(0, drum_part)
score.write('lily.png',"notation")
return Image.open('notation.png')
def PredictionToChord(prediction):
noteToChord = []
drumComponent = {"Hihat":"A4","Snare":"D4","KickBass":"G3","Crash":"B4","Tom":"E4","Ride":"G4"}
for component in prediction.split(" "):
if(component in drumComponent):
noteToChord.append(drumComponent[component])
return noteToChord
def transcribe(AudioFile):
return PredictionToNotation(["Hihat + Snare"])
gr.Interface(
fn=transcribe,
inputs=gr.Audio(type="filepath"),
outputs="image").launch() |