from midiutil import MIDIFile from musicpy import * import gradio as gr def write_song(): w = (C('Cmadd9,add11',5) @ [1,3,1.1,4,2.1,5,2.1,4] % (1/2,1/8) * 2 | C('A#add9,add11',4) @ [1,3,1.1,4,2.1,5,2.1,4] % (1/2,1/8) * 2 | C('G#add9',4) @ [1,3,1.1,4,2.1,4,1.1,3] % (1/2,1/8) * 2 | C('A#add9',4) @ [1,3,1.1,4,2.1,4,1.1,3] % (1/2,1/8) * 2) w2 = translate('C2;C3[l:2], i:2, A#1;A#2[l:2], i:2, G#1;G#2[l:2], i:2, A#1;A#2[l:2]') # Write the song as a MIDI file write(w2, bpm=100, channel=0, name='funky_song.mid', save_as_file=True) return "funky_song.mid" def make_mid(): degrees = [60, 62, 64, 65, 67, 69, 71, 72] # MIDI note number track = 0 channel = 0 time = 0 # In beats duration = 1 # In beats tempo = 60 # In BPM volume = 100 # 0-127, as per the MIDI standard MyMIDI = MIDIFile(1) # One track, defaults to format 1 (tempo track # automatically created) MyMIDI.addTempo(track,time, tempo) for pitch in degrees: MyMIDI.addNote(track, channel, pitch, time, duration, volume) time = time + 1 with open("major-scale.mid", "wb") as output_file: MyMIDI.writeFile(output_file) return "major-scale.mid" with gr.Blocks() as iface: btn=gr.Button() outp=gr.Files() btn.click(write_song,None,outp) iface.launch()