Spaces:
Runtime error
Runtime error
File size: 2,991 Bytes
95addfe 4d6b66b 3d0ab7b d94feec 95addfe f04af8f 4d6b66b cdbc599 984b844 cdbc599 4d6b66b 4fa625b 3d0ab7b 95addfe cdbc599 4d6b66b 95addfe cdbc599 95addfe |
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
import streamlit as st
import numpy as np
import pretty_midi
from accompaniment_generator.generator.base import Generator
import os
import uuid
import time
from midi2audio import FluidSynth
from scipy.io import wavfile
ABOUT_TEXT = "🤗 Accompaniment Generator - generate accompaniment part with chord using Evolutionary algorithm."
CONTACT_TEXT = """
_Built by Aleksey Korshuk with love_ ❤️
[![Follow](https://img.shields.io/github/followers/AlekseyKorshuk?style=social)](https://github.com/AlekseyKorshuk)
[![Follow](https://img.shields.io/twitter/follow/alekseykorshuk?style=social)](https://twitter.com/intent/follow?screen_name=alekseykorshuk)
Star project repository:
[![GitHub stars](https://img.shields.io/github/stars/AlekseyKorshuk/accompaniment-generator?style=social)](https://github.com/AlekseyKorshuk/accompaniment-generator)
"""
st.sidebar.markdown(
"""
<style>
.aligncenter {
text-align: center;
}
</style>
<p class="aligncenter">
<img src="https://seeklogo.com/images/A/apple-music-logo-4FBA5FADCC-seeklogo.com.png" width="220" />
</p>
""",
unsafe_allow_html=True,
)
st.sidebar.markdown(ABOUT_TEXT)
st.sidebar.markdown(CONTACT_TEXT)
def inference(audio, num_epoch):
generator = Generator()
output_midi_data = generator(audio, num_epoch=int(num_epoch))[0]
name = uuid.uuid4()
output_midi_data.write(f'{name}.mid')
fs = FluidSynth("font.sf2")
fs.midi_to_audio(f'{name}.mid', f'{name}.wav')
fs.midi_to_audio(audio, f'{name}-init.wav')
# time.sleep(2)
print([f'{name}-init.wav', f'{name}.wav'])
return f'{name}-init.wav', f'{name}.wav'
st.title("Accompaniment Generator")
st.markdown(
"App to generate accompaniment for MIDI music file with Evolutionary algorithm. Check out [project repository](https://github.com/AlekseyKorshuk/accompaniment-generator).")
article = "<p style='text-align: center'>" \
"<a href='https://github.com/AlekseyKorshuk/accompaniment-generator' target='_blank'>Github Repo</a>" \
"</p>"
from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir("./examples") if isfile(join("./examples", f))]
model_name = st.selectbox(
'Select example MIDI file (will be used only for empty file field):',
onlyfiles
)
uploaded_file = st.file_uploader(
'Upload MIDI file:'
)
num_epoch = st.number_input("Number of epochs:",
min_value=1,
max_value=1000,
step=1,
value=10,
)
generate_image_button = st.button("Generate")
if generate_image_button:
input_file = f"./examples/{model_name}"
if uploaded_file is not None:
input_file = uploaded_file.name
with st.spinner(text=f"Generating, this may take some time..."):
before, after = inference(input_file, num_epoch)
st.markdown("Before:")
st.audio(before)
st.markdown("After:")
st.audio(after)
|