Spaces:
Running
Running
visakh7843
commited on
Commit
•
61aa7f2
1
Parent(s):
c9dbbbe
Bug fixes and minor UI changes
Browse files- MC/__pycache__/markov_chain.cpython-39.pyc +0 -0
- MC/markov_chain.py +3 -3
- __pycache__/markov.cpython-39.pyc +0 -0
- __pycache__/music.cpython-39.pyc +0 -0
- app.py +8 -6
- markov.py +3 -3
- music.py +6 -4
MC/__pycache__/markov_chain.cpython-39.pyc
CHANGED
Binary files a/MC/__pycache__/markov_chain.cpython-39.pyc and b/MC/__pycache__/markov_chain.cpython-39.pyc differ
|
|
MC/markov_chain.py
CHANGED
@@ -95,8 +95,8 @@ def generate_notes(csv_file):
|
|
95 |
gen_notes.append(int(next_note))
|
96 |
gen_durations.append(next_duration)
|
97 |
|
98 |
-
start_notes.pop()
|
99 |
-
start_durations.pop()
|
100 |
|
101 |
start_notes.append(next_note)
|
102 |
start_durations.append(next_duration)
|
@@ -218,7 +218,7 @@ def main_markov(time_sign):
|
|
218 |
|
219 |
mid.tracks.append(track)
|
220 |
print(mid)
|
221 |
-
track.append((MetaMessage('time_signature', numerator=
|
222 |
# https://mido.readthedocs.io/en/latest/midi_files.html
|
223 |
for i in range(num_notes):
|
224 |
track.append(Message('note_on', channel=0, note=gen_notes[i], velocity=60, time=0))
|
|
|
95 |
gen_notes.append(int(next_note))
|
96 |
gen_durations.append(next_duration)
|
97 |
|
98 |
+
start_notes.pop(0)
|
99 |
+
start_durations.pop(0)
|
100 |
|
101 |
start_notes.append(next_note)
|
102 |
start_durations.append(next_duration)
|
|
|
218 |
|
219 |
mid.tracks.append(track)
|
220 |
print(mid)
|
221 |
+
track.append((MetaMessage('time_signature', numerator=int(time_signature[0]), denominator=int(time_signature[1]))))
|
222 |
# https://mido.readthedocs.io/en/latest/midi_files.html
|
223 |
for i in range(num_notes):
|
224 |
track.append(Message('note_on', channel=0, note=gen_notes[i], velocity=60, time=0))
|
__pycache__/markov.cpython-39.pyc
CHANGED
Binary files a/__pycache__/markov.cpython-39.pyc and b/__pycache__/markov.cpython-39.pyc differ
|
|
__pycache__/music.cpython-39.pyc
CHANGED
Binary files a/__pycache__/music.cpython-39.pyc and b/__pycache__/music.cpython-39.pyc differ
|
|
app.py
CHANGED
@@ -5,9 +5,9 @@ import gradio as gr
|
|
5 |
import os
|
6 |
from MC.markov_chain import main_markov #Function to generate music based on midi files
|
7 |
|
8 |
-
keysignature = ["C","G","D","No selection"]
|
9 |
difficulty = ["beginner","intermediate","expert"]
|
10 |
-
timesignature = ['3/4','4/4','
|
11 |
|
12 |
# output = gr.Gallery() if GlobalUIGallery else "image"
|
13 |
|
@@ -23,11 +23,13 @@ timesignature = ['3/4','4/4','1/8','6/8']
|
|
23 |
with gr.Blocks() as demo:
|
24 |
|
25 |
gr.Markdown("""
|
26 |
-
##
|
|
|
|
|
27 |
""")
|
28 |
with gr.Tabs():
|
29 |
with gr.TabItem("ABC Model"):
|
30 |
-
gr.Markdown("ABC
|
31 |
with gr.Row():
|
32 |
with gr.Column():
|
33 |
difficulty_input_abc = gr.Radio(difficulty,label="Difficulty") #input
|
@@ -39,8 +41,8 @@ with gr.Blocks() as demo:
|
|
39 |
with gr.Column():
|
40 |
output_gallery_abc = gr.Gallery(label="Sheet Music")
|
41 |
output_audio_abc = gr.Audio(label="Audio")
|
42 |
-
with gr.TabItem("
|
43 |
-
gr.Markdown("
|
44 |
with gr.Row():
|
45 |
with gr.Column():
|
46 |
# difficulty_input_midi = gr.Radio(difficulty,label="Difficulty") #input
|
|
|
5 |
import os
|
6 |
from MC.markov_chain import main_markov #Function to generate music based on midi files
|
7 |
|
8 |
+
keysignature = ["C","G","D","A","No selection"]
|
9 |
difficulty = ["beginner","intermediate","expert"]
|
10 |
+
timesignature = ['3/4','4/4','2/2','2/4']
|
11 |
|
12 |
# output = gr.Gallery() if GlobalUIGallery else "image"
|
13 |
|
|
|
23 |
with gr.Blocks() as demo:
|
24 |
|
25 |
gr.Markdown("""
|
26 |
+
## Sight-reading generator for sheet music.
|
27 |
+
Markov models which generate sheet music based on different input
|
28 |
+
parameters given by the user.
|
29 |
""")
|
30 |
with gr.Tabs():
|
31 |
with gr.TabItem("ABC Model"):
|
32 |
+
gr.Markdown("N-grams model using ABC data as training data.")
|
33 |
with gr.Row():
|
34 |
with gr.Column():
|
35 |
difficulty_input_abc = gr.Radio(difficulty,label="Difficulty") #input
|
|
|
41 |
with gr.Column():
|
42 |
output_gallery_abc = gr.Gallery(label="Sheet Music")
|
43 |
output_audio_abc = gr.Audio(label="Audio")
|
44 |
+
with gr.TabItem("MIDI Model"):
|
45 |
+
gr.Markdown("Markov model using MIDI fata as training data.")
|
46 |
with gr.Row():
|
47 |
with gr.Column():
|
48 |
# difficulty_input_midi = gr.Radio(difficulty,label="Difficulty") #input
|
markov.py
CHANGED
@@ -105,11 +105,11 @@ def generate_model_from_token_lists(token_lines, n, count=14, max_iterations=100
|
|
105 |
It also builds a separate Markov model for each line, and then merges
|
106 |
those models together, to ensure that lines end with n-grams statistically
|
107 |
likely to end lines in the original text."""
|
108 |
-
beginnings = list()
|
109 |
models = list()
|
110 |
for token_line in token_lines:
|
111 |
-
beginning = token_line[:n]
|
112 |
-
beginnings.append(beginning)
|
113 |
line_model = build_model(token_line, n)
|
114 |
models.append(line_model)
|
115 |
combined_model = merge_models(models)
|
|
|
105 |
It also builds a separate Markov model for each line, and then merges
|
106 |
those models together, to ensure that lines end with n-grams statistically
|
107 |
likely to end lines in the original text."""
|
108 |
+
# beginnings = list()
|
109 |
models = list()
|
110 |
for token_line in token_lines:
|
111 |
+
# beginning = token_line[:n]
|
112 |
+
# beginnings.append(beginning)
|
113 |
line_model = build_model(token_line, n)
|
114 |
models.append(line_model)
|
115 |
combined_model = merge_models(models)
|
music.py
CHANGED
@@ -55,6 +55,10 @@ def time_sigFinder(time_Signature):
|
|
55 |
return 'M:2/4',2
|
56 |
elif time_Signature == "1/8":
|
57 |
pass
|
|
|
|
|
|
|
|
|
58 |
# def get_pngs(path):
|
59 |
# filelist=os.listdir(path)
|
60 |
# for fichier in filelist[:]: # filelist[:] makes a copy of filelist.
|
@@ -100,6 +104,7 @@ def music_gen(difficulty,time_Signature, Key_Signature):
|
|
100 |
last = index
|
101 |
elif "M:" in line:
|
102 |
#time signature
|
|
|
103 |
if selected_timeSign == "4/4":
|
104 |
if "4/4" in line or "C|" in line:
|
105 |
accepted = True
|
@@ -107,6 +112,7 @@ def music_gen(difficulty,time_Signature, Key_Signature):
|
|
107 |
accepted = True
|
108 |
elif line.find("K:") and key_enforced:
|
109 |
#key signature
|
|
|
110 |
if selected_keySign in line:
|
111 |
key_accepted = True
|
112 |
|
@@ -207,8 +213,4 @@ def music_gen(difficulty,time_Signature, Key_Signature):
|
|
207 |
#Introduces this wait time as we were returning file path even before lilypond converted the abc file
|
208 |
# final_path = os.path.abspath(song_path+".png")
|
209 |
png_list = get_pngs(path)
|
210 |
-
# if len(png_list)>1:
|
211 |
-
# print("In HereEEEEEEEEEEEE")
|
212 |
-
# GlobalUIGallery = True
|
213 |
-
# return png_list,song_path+".wav"
|
214 |
return png_list,song_path+".wav"
|
|
|
55 |
return 'M:2/4',2
|
56 |
elif time_Signature == "1/8":
|
57 |
pass
|
58 |
+
elif time_Signature == "2/4":
|
59 |
+
return 'M:2/4',2
|
60 |
+
elif time_Signature == "2/2":
|
61 |
+
return 'M:2/2',2
|
62 |
# def get_pngs(path):
|
63 |
# filelist=os.listdir(path)
|
64 |
# for fichier in filelist[:]: # filelist[:] makes a copy of filelist.
|
|
|
104 |
last = index
|
105 |
elif "M:" in line:
|
106 |
#time signature
|
107 |
+
print(line)
|
108 |
if selected_timeSign == "4/4":
|
109 |
if "4/4" in line or "C|" in line:
|
110 |
accepted = True
|
|
|
112 |
accepted = True
|
113 |
elif line.find("K:") and key_enforced:
|
114 |
#key signature
|
115 |
+
print(line)
|
116 |
if selected_keySign in line:
|
117 |
key_accepted = True
|
118 |
|
|
|
213 |
#Introduces this wait time as we were returning file path even before lilypond converted the abc file
|
214 |
# final_path = os.path.abspath(song_path+".png")
|
215 |
png_list = get_pngs(path)
|
|
|
|
|
|
|
|
|
216 |
return png_list,song_path+".wav"
|