-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_app.py
142 lines (127 loc) · 5.65 KB
/
main_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
from init_import import *
def intro():
# Get database connection
db = get_database()
users_collection = db['login']
col1, col2 = st.columns([5,1])
with col1:
with st.popover("Sign Up"):
if not ss.logged:
register = sign_up(users_collection)
if register:
ss.logged = True
st.rerun()
elif ss.logged:
st.success("You are already logged in")
with col2:
if not ss.logged:
with st.popover("Log In"):
login = login_form()
if login:
ss.logged = True
st.rerun()
elif login==False:
st.error("Incorrect username or password")
else:
if st.button("Log Out"):
ss.logged = False
st.rerun()
em = random.choice(fun_emoji_list)
st.title(f"{em}Welcome to Music Cluster!{em}")
st.write(f"A music theory app that you can practice your ABRSM grade 5 theory! {random.choice(fun_emoji_list)}")
st.subheader("❗️Try out the new Note Reading Exercise Generator❗️")
login_greeting()
ss.demo_name = "—"
# Rhythm-related container
with st.expander("Rhythm-related", expanded=True):
col1, col2 = st.columns(2)
with col1:
if st.button("Grouping and beaming"): ss.demo_name = "Grouping and beaming"
if st.button("Duration calculation"): ss.demo_name = "Duration calculation"
with col2:
if st.button("Simple-compound Modulation"): ss.demo_name = "Simple-compound Modulation"
if st.button("Calculation for time signature"): ss.demo_name = "Calculation for time signature"
# Pitch-related container
with st.expander("Pitch-related", expanded=True):
col1, col2 = st.columns(2)
with col1:
if st.button("Pitch Identification"): ss.demo_name = "Pitch Identification"
if st.button("Chromatic scale"): ss.demo_name = "Chromatic scale"
if st.button("Same pitches with different clefs"): ss.demo_name = "Same pitches with different clefs"
with col2:
if st.button("Interval"): ss.demo_name = "Interval"
if st.button("Transposing"): ss.demo_name = "Transposing"
# Key-related container
with st.expander("Key-related", expanded=True):
col1, col2 = st.columns(2)
with col1:
if st.button("Identifying Key in a Melody"): ss.demo_name = "Identifying Key in a Melody"
if st.button("Chord Inversion"): ss.demo_name = "Inversion"
with col2:
if st.button("Chord Progression"): ss.demo_name = "Chord Progression"
if st.button("Identify clef from minor scale"): ss.demo_name = "Identify clef from minor scale"
# Music knowledge container
with st.expander("Music Knowledge", expanded=True):
col1, col2 = st.columns(2)
with col1:
st.write(" ")
if st.button("Instrumental Knowledge"): ss.demo_name = "Instrumental Knowledge"
with col2:
st.markdown(button_style, unsafe_allow_html=True)
st.markdown('<a href="https://music-glossary.streamlit.app" class="button" target="_blank">Music Dictionary</a>', unsafe_allow_html=True)
with st.expander("Music Supplement", expanded=True):
col1, col2 = st.columns(2)
with col1:
if st.button("Note Reading Exercise Generator"): ss.demo_name = "Note Reading Exercise Generator"
if st.button("Key finder"): ss.demo_name = "Key Finder"
with col2:
if st.button("Interval Calculator"): ss.demo_name = "Interval Calculator"
with st.expander("Learn more", expanded=True):
col1, col2 = st.columns(2)
with col1:
if st.button("Support me"):
st.markdown('<meta http-equiv="refresh" content="0; url=/support_me">', unsafe_allow_html=True)
with col2:
if st.button("About me"):
st.markdown('<meta http-equiv="refresh" content="0; url=/about_me">', unsafe_allow_html=True)
if ss.demo_name != "—":
st.rerun()
page_names_to_funcs = {
"—": intro,
"Grouping and beaming": grouping_quiz_main,
"Simple-compound Modulation": compound_simple_main,
"Duration calculation": duration_cal_main,
"Calculation for time signature": main_ts,
"Pitch Identification": pitch_main,
"Interval": interval_main,
"Chromatic scale": chr_main,
"Transposing": transposing_main,
"Same pitches with different clefs": main_sp,
"Identifying Key in a Melody": melody_key_main,
"Chord Progression": chord_progression_main,
"Identify clef from minor scale": clef_main,
"Inversion": main_inversion,
"Instrumental Knowledge": knowledgemain,
"Note Reading Exercise Generator":story_main,
"Interval Calculator":in_calculator_main, "Key Finder": find_key_main,
}
def main():
st.set_page_config(page_title="Music Theory App", page_icon="🎵")
if 'demo_name' not in ss:
ss.demo_name = "—"
if "logged" not in ss:
ss.logged = None
ss.last_ai_greeting = None
page_selected = st.sidebar.radio("Choose a page", page_names_to_funcs.keys(), index=list(page_names_to_funcs.keys()).index(ss.demo_name))
if page_selected != ss.demo_name:
ss.demo_name = page_selected
st.rerun()
if page_selected != "—":
if ss.logged:
st.success("You are logged in")
else:
st.warning("You are not logged in")
back_home()
page_names_to_funcs[page_selected]()
if __name__ == "__main__":
main()