File size: 2,447 Bytes
871cdce
 
 
 
 
 
 
 
 
 
334bc59
871cdce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
334bc59
871cdce
 
 
 
 
 
 
 
334bc59
 
 
 
871cdce
334bc59
871cdce
 
 
 
 
334bc59
871cdce
 
 
 
 
 
 
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
import streamlit as st

from app.helpers import load_audio_segment, plot_audio

def _load_example(name: str):
    st.markdown("<center><h3> Original </h3></center>", unsafe_allow_html=True)

    cols = st.columns(2)
    with cols[0]:
        auseg = load_audio_segment(f"samples/{name}", "mp3")
        plot_audio(auseg, step=50)
    with cols[1]:
        audio_file = open(f"samples/{name}", "rb")
        audio_bytes = audio_file.read()
        st.audio(audio_bytes)
    
    for file in ["vocals.mp3", "drums.mp3", "bass.mp3", "other.mp3"]:
        st.markdown("<br>", unsafe_allow_html=True)
        label = file.split(".")[0].capitalize()
        label = {
            "Drums": "πŸ₯",
            "Bass": "🎸",
            "Other": "🎹",
            "Vocals": "🎀",
        }.get(label)  + " " + label
        st.markdown("<center><h3>" + label + "</h3></center>", unsafe_allow_html=True)

        cols = st.columns(2)
        with cols[0]:
            auseg = load_audio_segment(f"samples/{name.split('.mp3')[0]}/{file}", "mp3")
            plot_audio(auseg, step=50)
        with cols[1]:
            audio_file = open(f"samples/{name.split('.mp3')[0]}/{file}", "rb")
            audio_bytes = audio_file.read()
            st.audio(audio_bytes)
    

def show_examples():
    with st.columns([2, 8, 1])[1]:
        selection = st.selectbox("Select an example music to quickly see results", ["Something About You - Marilyn Ford", "Broke Me - FASSounds", "Indie Rock"])
    if selection == "Broke Me - FASSounds":
        _load_example("broke-me-fassounds.mp3")
        link = "https://pixabay.com/users/fassounds-3433550/"
        st.markdown(
            f"""Music by <a href="{link}">FASSounds</a> from <a href="{link}">Pixabay</a>""",
            unsafe_allow_html=True)
    elif selection == "Indie Rock":
        _load_example("indie-rock.mp3")
        link = "https://pixabay.com/music/indie-rock-112771/"
        st.markdown(
            f"""Music by <a href="{link}">Music_Unlimited</a> from <a href="{link}">Pixabay</a>""",
            unsafe_allow_html=True)
    elif selection == "Something About You - Marilyn Ford":
        _load_example("something-about-you-marilyn-ford.mp3")
        link = "https://pixabay.com/music/rnb-something-about-you-marilyn-ford-135781/"
        st.markdown(
            f"""Music by <a href="{link}">Marilyn Ford</a> from <a href="{link}">Pixabay</a>""",
            unsafe_allow_html=True)