File size: 4,060 Bytes
b1fba94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
import streamlit as st
import autotab.TabPrediction as tp
import pandas as pd
import numpy as np 
from autotab.TabDataReprGen import TabDataReprGen
from PIL import Image

st.set_page_config(
    page_title="AutoTab tab generator",
    layout="centered", # centered
    initial_sidebar_state="auto") # collapsed

image_path = "https://images.unsplash.com/photo-1535587566541-97121a128dc5?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80"
st.write(f'<div class="banner" style="background-image: linear-gradient(rgba(0,0,0,0.4),rgba(0,0,0,0.4)), url({image_path});"><h1>Autotab</h1><p>Learning the guitar the easy way</p></div>', unsafe_allow_html=True)
CSS = """

.banner {

    background-position: center;

    background-repeat: no-repeat;

    background-size: cover;

    position: relative;

    height: 300px;

    text-align: center;

    margin-top: -100px;

    margin-left: -480px;

    margin-right: -480px;

}

.banner h1 {

    padding-top: 120px;

    margin: 0;

    color: white;

    text-shadow: 1px 1px 3px rgba(0,0,0,0.2);

    font-size: 56px;

    font-weight: bold;

}

.banner p {

    font-size: 32px;

    color: white;

    opacity: .7;

    text-shadow: 1px 1px 3px rgba(0,0,0,0.2);

}

"""
st.write(f'<style>{CSS}</style>', unsafe_allow_html=True)


st.set_option('deprecation.showfileUploaderEncoding', False)

uploaded_file = st.file_uploader("choose a music file:", type="wav")

processed_file = None

mode = st.radio('Choose Mode of Tab production:', ('Ergonomic Simple', 'Ergonomic Rhythm', 'All Frames'))
st.write('<style>div.row-widget.stRadio > div{flex-direction:row;}</style>', unsafe_allow_html=True)

###########################################################
# slider for number of divisions 

num_div = st.slider('Select number of frets per line', 1, 10, 3)
# web_tabs(tabs, num_div=4, len_div=16)

###########################################################

model = tp.load_model_and_weights()
model.load_weights('./h5-model/full_val0_75acc_weights.h5')
genrep = TabDataReprGen()

if uploaded_file is not None:
    x_new = genrep.load_rep_from_raw_file(uploaded_file)
    y_pred = model.predict(x_new)
    processed_file= uploaded_file
    
if uploaded_file is not None and mode == 'Ergonomic Simple': 
    st.title("""

            Ergonomic Simple predicted Tabs: 

    """)
    if uploaded_file != processed_file:        
        x_new = genrep.load_rep_from_raw_file(uploaded_file)
        # st.write(x_new.shape)
        y_pred = model.predict(x_new)
        processed_file = uploaded_file
    
    all_frames_tab = tp.make_smart_tab(y_pred, len(y_pred))
    simple_tabs = tp.make_squeezed_tab(all_frames_tab)
    simple_text = tp.web_tabs(simple_tabs)
    st.text(simple_text)
    
if uploaded_file is not None and mode == 'Ergonomic Rhythm': 
    st.title("""

            Ergonomic Rhythm predicted Tabs:

    """)
    if uploaded_file != processed_file:        
        x_new = genrep.load_rep_from_raw_file(uploaded_file)
        # st.write(x_new.shape)
        y_pred = model.predict(x_new)
        processed_file = uploaded_file
    
    all_frames_tab = tp.make_smart_tab(y_pred, len(y_pred))
    rythm_tabs = tp.make_dynamic_tab(all_frames_tab)
    rythm_text = tp.web_tabs(rythm_tabs)
    st.text(rythm_text)
    
if uploaded_file is not None and mode == 'All Frames': 
    st.title("""

            All Frames predicted Tabs:

    """)
    if uploaded_file != processed_file:        
        x_new = genrep.load_rep_from_raw_file(uploaded_file)
        # st.write(x_new.shape)
        y_pred = model.predict(x_new)
        processed_file = uploaded_file
    

    all_frames_tab = tp.make_smart_tab(y_pred, len(y_pred))
    ################################################
    # all_frames_tab.to_csv('all_frames_tab.csv')
    ################################################
    all_frames_text = tp.web_tabs(all_frames_tab)
    st.text(all_frames_text)