-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
324 lines (268 loc) · 9.74 KB
/
streamlit_app.py
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
from chordSolverML import (
chordPredictionDF,
romanPredictionDF,
keyPredictionDF,
notesPredictionDF,
)
import streamlit as st
from joblib import dump, load
import streamlit as st
import pandas as pd
import numpy as np
from streamlit.proto.Radio_pb2 import Radio
import streamlit.components.v1 as components
st.set_page_config(
layout="wide",
page_title="Music Theory Suite",
page_icon="./Assets/musicTheoryLogo.jpeg",
)
chordPipe, chordScore = chordPredictionDF()
romanPipe, romanScore = romanPredictionDF()
keyPipe, keyScore = keyPredictionDF()
notesPipe, notesScore = notesPredictionDF()
page = st.sidebar.radio(
"Choose your page", ["Music Tools v3", "Music Tools v1 & v2", "About"]
)
if page == "Music Tools v3":
# Display details of page 1
st.image("./Assets/mustheorysuite.jpeg", width=750, clamp=True)
f"""
# Music Tools - v3
"""
moreInfo = st.expander(
"More Info",
)
# prediction = st.checkbox("Prediction Accuracy")
prediction = False
with moreInfo:
"""
> The results are **_NOT_** perfect. There currently isn't a good dataset for music theory, so I did my best to create my own.
> Until there is better data, the more accurate your input is, the more accurate the results will be. Put spaces between the notes.
"""
# > Chord Prediction Accuracy = {100*chordScore}%
# > Roman Numeral Prediction Accuracy = {100*romanScore}%
"""
----------------------------------------------------------------
# Predictor:
"""
predictions = st.selectbox(
label="What would you like to predict?",
options=["Chord & Roman Numeral", "Key", "Notes"],
index=0,
)
col1, col2, col3 = st.columns(3)
col4, col5 = st.columns(2)
keys = [
"C♭",
"C",
"C♯",
"D♭",
"D",
"D♯",
"E♭",
"E",
"E♯",
"F♭",
"F",
"F♯",
"G♭",
"G",
"G♯",
"A♭",
"A",
"A♯",
"B♭",
"B",
"B♯",
]
if len(predictions) == 0:
"# ^ Select something to predict"
elif predictions in ["Chord & Roman Numeral"]:
row2Col1, row2Col2 = st.columns(2)
with row2Col1:
KEY = st.selectbox("Key", keys, index=1)
with row2Col2:
NOTES = st.text_input("Enter Notes", value="")
NOTES = NOTES.title()
if NOTES != "" and KEY is not None:
y = pd.DataFrame({"Key": [KEY], "Notes": [NOTES]})
if prediction:
f"""
---
## Result:
### Predictions Accuracy: {round(chordScore*100, 2)}% & {round(romanScore*100, 2)}%
> ### Chord Name: {chordPipe.predict(y)[0]} Roman Numeral: ${romanPipe.predict(y)[0]}$
"""
else:
f"""
---
## Result:
### Chord Name: {chordPipe.predict(y)[0]} Roman Numeral: ${romanPipe.predict(y)[0]}$
###
"""
elif predictions == "Key":
with col1:
ROMAN = st.selectbox(
label="Roman Numeral",
options=[
"I",
"ii",
"iii",
"IV",
"V",
"vi",
"vii°",
"i",
"ii°",
"III",
"iv",
"v",
"VI",
"VII",
],
)
with col2:
NOTES = st.text_input("Enter Notes", value="")
NOTES = NOTES.title()
with col3:
altered = st.radio("Altered", ["None", "♯5", "♭5", "7"])
key_y = pd.DataFrame({"Notes": [NOTES], "RomanNumeral": [ROMAN]})
key_prediction = keyPipe.predict(key_y)[0]
if ROMAN in [
"i",
"ii°",
"III",
"iv",
"v",
"VI",
"VII",
]:
key_prediction += " minor"
else:
key_prediction += " major"
if NOTES != "":
chord_y = pd.DataFrame(
{"Key": [key_prediction], "Notes": [NOTES], "RomanNumeral": [ROMAN]}
)
chord_prediction = chordPipe.predict(chord_y)[0]
if altered == "♯5":
ROMAN += "^{\♯5}"
chord_prediction += " ${\♯5}$"
elif altered == "♭5":
ROMAN += "^{ ♭5}"
chord_prediction += " ${ ♭5}$"
elif altered == "7":
ROMAN += "^7"
chord_prediction = chord_prediction.replace("b", "$♭$")
chord_prediction = chord_prediction.replace("#", "$♯$")
key_prediction = key_prediction.replace("b", "$♭$")
key_prediction = key_prediction.replace("#", "$♯$")
if prediction:
f"""
---
## Result:
### Prediction Accuracy: {round(keyScore*100, 2)}%
> ### {chord_prediction} is the ${ROMAN}$ </pre>chord of {key_prediction}
"""
else:
f"""
---
## Result:
> ### {chord_prediction} is the ${ROMAN}$ chord of {key_prediction}
"""
elif predictions == "Notes":
KEY = "C"
colX, colY, colZ = st.columns(3)
with colX:
KEY = st.selectbox("Key", keys, index=1)
with colY:
ROMAN = st.selectbox(
label="Roman Numeral",
options=[
"I",
"ii",
"iii",
"IV",
"V",
"vi",
"vii°",
"i",
"ii°",
"III",
"iv",
"v",
"VI",
"VII",
],
index=0,
)
with colZ:
altered = st.radio("Altered", ["None", "♯5", "♭5", "7"])
if altered == "♯5":
ROMAN += "♯5"
elif altered == "♭5":
ROMAN += "♭5"
elif altered == "7":
ROMAN += "7"
print(ROMAN)
KEY = KEY.replace("♭", "b")
KEY = KEY.replace("♯", "#")
notes_y = pd.DataFrame(
{
"Key": [KEY],
"RomanNumeral": [ROMAN],
}
)
notes_prediction = notesPipe.predict(notes_y)[0]
chord_y = pd.DataFrame({"Key": [KEY], "Notes": [notes_prediction]})
chord_prediction = chordPipe.predict(chord_y)[0]
chord_prediction = chord_prediction.replace("b", "$♭$")
chord_prediction = chord_prediction.replace("#", "$♯$")
notes_prediction = notes_prediction.replace("b", "$♭$")
notes_prediction = notes_prediction.replace("#", "$♯$")
if prediction:
f"""
---
## Result:
### Prediction Accuracy: {round(notesScore*100, 2)}%
> ### Chord: {chord_prediction}
> ### Notes: {notes_prediction}
"""
else:
f"""
---
## Result:
### Chord: {chord_prediction}
### Notes: {notes_prediction}
"""
if page == "Music Tools v1 & v2":
"""
# Chord Solver iOS
[Click here to download for iOS](https://apps.apple.com/us/app/chord-solver/id1564025162)
"""
"# Chord Solver Website "
"[Click here to go to website](http://www.chordsolver.com/) \n"
st.components.v1.iframe(src="http://chordsolver.com", height=550, scrolling=True)
if page == "About":
"""
# What is Music Theory Suite?
> The _**Music Theory Suite**_ is an idea by [Dylan Shade](https://dylan-shade-creations.super.site/) to create a tool kit for those who are interested in working with music theory.
---
# What is this website?
*This website provides a machine learning implimentation of most of the stuff presented in the previous two apps, but with extended functionality. The current data being used was created by me. This is a current limitation of this website. If there is a better data set, the results have the potential to be even more accurate.*
---
# The Future of Music Theory Suite
My goal with Music Theory Suite is to add tools that could help you with any music theory questions. As of right now, the following are in consideration of being added:
- Atonal matrix completion
- Set completion
- Aural skills help
---
# Other tools in the Music Theory Suite
*There are currently two other versions of some basic music theory tools:*\n
1. The [Chord Solver iOS](https://apps.apple.com/us/app/chord-solver/id1564025162) app that helps you build chords by picking the type of chord and entering the note. The iOS app also allows you to build scales in the same manner.\n
2. The [Chord Solver Website](http://www.chordsolver.com/) does the inverse of what the app does. Here you can enter notes into a search bar and it will tell you the type of interval, triad, or seventh chord that it creates. \n
"""
"---"
components.html(
'<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js" data-name="bmc-button" data-slug="dylanshade" data-color="#ffffff" data-emoji="" data-font="Lato" data-text="Buy me a coffee" data-outline-color="#000000" data-font-color="#000000" data-coffee-color="#FFDD00" ></script>'
)