awacke1 commited on
Commit
a529401
·
verified ·
1 Parent(s): 04beada

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+
5
+ # Define the key map
6
+ KEY_MAP = {
7
+ 'C': 0, 'C#': 1, 'D': 2, 'D#': 3, 'E': 4, 'F': 5, 'F#': 6, 'G': 7, 'G#': 8, 'A': 9, 'A#': 10, 'B': 11
8
+ }
9
+
10
+ # Define the octave range
11
+ OCTAVE_RANGE = range(-1, 8)
12
+
13
+ # Define the key colors
14
+ WHITE_KEY_COLOR = 'white'
15
+ BLACK_KEY_COLOR = 'black'
16
+
17
+ # Define the key labels
18
+ KEY_LABELS = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
19
+
20
+ # Define the chord annotations
21
+ CHORD_ANNOTATIONS = [
22
+ "Chord players, sing lyrics while reading music chords",
23
+ "Pace in 12 or 3/4 steps with rhythm"
24
+ ]
25
+
26
+ def draw_keyboard():
27
+ fig, ax = plt.subplots(figsize=(16, 4))
28
+ ax.set_facecolor('black')
29
+ ax.set_xticks([])
30
+ ax.set_yticks([])
31
+
32
+ key_width = 0.8
33
+ key_height = 3
34
+ key_spacing = 0.2
35
+
36
+ for octave in OCTAVE_RANGE:
37
+ for i, key in enumerate(KEY_LABELS):
38
+ x = (i + (octave * 12)) * (key_width + key_spacing)
39
+ y = 0
40
+
41
+ if i in [1, 3, 6, 8, 10]:
42
+ rect = plt.Rectangle((x, y), key_width, key_height * 0.6, facecolor=BLACK_KEY_COLOR)
43
+ ax.add_patch(rect)
44
+ else:
45
+ rect = plt.Rectangle((x, y), key_width, key_height, facecolor=WHITE_KEY_COLOR, edgecolor='black')
46
+ ax.add_patch(rect)
47
+
48
+ if octave >= 0:
49
+ ax.text(x + 0.2, 0.5, f"{key}{octave}", fontsize=12, fontweight='bold')
50
+
51
+ for i, annotation in enumerate(CHORD_ANNOTATIONS):
52
+ ax.text(1, key_height * (1.2 + i * 0.3), annotation, fontsize=12, fontweight='bold', color='white')
53
+
54
+ ax.set_aspect('equal')
55
+ st.pyplot(fig)
56
+
57
+ st.title("88-Key Keyboard Model")
58
+ draw_keyboard()