Update app.py
Browse files
app.py
CHANGED
@@ -52,62 +52,92 @@ def Generate_Chords_Progression(total_song_length_in_chords_chunks,
|
|
52 |
print('Pitches Chords Progressions Generator')
|
53 |
print('=' * 70)
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
|
57 |
-
mc_song_artist = song_artist_tokens_to_song_artist(result_toks)
|
58 |
-
gidx = genre_labels_fnames.index(mc_song_artist)
|
59 |
-
mc_genre = genre_labels[gidx][1]
|
60 |
|
61 |
-
|
62 |
-
print('Most common classification song-artist label:', mc_song_artist)
|
63 |
-
print('Most common song-artist classification label ratio:' , results.count(final_result) / len(results))
|
64 |
-
print('=' * 70)
|
65 |
|
66 |
-
|
67 |
-
classification_summary_string += 'Most common classification song-artist label: ' + str(mc_song_artist) + '\n'
|
68 |
-
classification_summary_string += 'Most common song-artist classification label ratio: '+ str(results.count(final_result) / len(results)) + '\n'
|
69 |
-
classification_summary_string += '=' * 70
|
70 |
-
classification_summary_string += '\n'
|
71 |
|
72 |
-
|
73 |
-
print('=' * 70)
|
74 |
|
75 |
-
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
classification_summary_string += '\n'
|
92 |
-
print('=' * 70)
|
93 |
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
|
98 |
-
print('Aggregated artist classification label ratio:', mode_artist_label_count / len(all_artists_labels))
|
99 |
-
classification_summary_string += 'Aggregated artist classification label: ' + str(mode_artist_label) + '\n'
|
100 |
-
classification_summary_string += 'Aggregated artist classification label ratio: ' + str(mode_artist_label_count / len(all_artists_labels)) + '\n'
|
101 |
-
classification_summary_string += '=' * 70
|
102 |
-
classification_summary_string += '\n'
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
print('=' * 70)
|
|
|
105 |
print('Done!')
|
106 |
print('=' * 70)
|
107 |
|
108 |
#===============================================================================
|
109 |
-
print('Rendering results...')
|
110 |
|
|
|
111 |
print('=' * 70)
|
112 |
|
113 |
fn1 = "Melody2Song-Seq2Seq-Music-Transformer-Composition"
|
|
|
52 |
print('Pitches Chords Progressions Generator')
|
53 |
print('=' * 70)
|
54 |
|
55 |
+
print('=' * 70)
|
56 |
+
print('Chunk-by-chunk generation')
|
57 |
+
print('=' * 70)
|
58 |
+
print('Generating...')
|
59 |
+
print('=' * 70)
|
60 |
|
61 |
+
matching_long_chords_chunks = []
|
|
|
|
|
|
|
62 |
|
63 |
+
ridx = random.randint(0, len(all_long_chords_tokens_chunks)-1)
|
|
|
|
|
|
|
64 |
|
65 |
+
matching_long_chords_chunks.append(ridx)
|
|
|
|
|
|
|
|
|
66 |
|
67 |
+
max_song_len = 0
|
|
|
68 |
|
69 |
+
tries = 0
|
70 |
|
71 |
+
while len(matching_long_chords_chunks) < total_song_length_in_chords_chunks:
|
72 |
+
|
73 |
+
matching_long_chords_chunks = []
|
74 |
+
|
75 |
+
ridx = random.randint(0, len(all_long_chords_tokens_chunks)-1)
|
76 |
+
|
77 |
+
matching_long_chords_chunks.append(ridx)
|
78 |
+
seen = [ridx]
|
79 |
+
|
80 |
+
for a in range(16):
|
81 |
+
|
82 |
+
schunk = all_long_chords_tokens_chunks[matching_long_chords_chunks[-1]]
|
83 |
+
trg_long_chunk = np.array(schunk[-chunk_size:])
|
84 |
+
idxs = np.where((src_long_chunks == trg_long_chunk).all(axis=1))[0].tolist()
|
|
|
|
|
85 |
|
86 |
+
if len(idxs) > 1:
|
87 |
+
eidx = random.choice(idxs)
|
88 |
+
tr = 0
|
89 |
+
while eidx in seen and tr < 5:
|
90 |
+
eidx = random.choice(idxs)
|
91 |
+
tr += 1
|
92 |
|
93 |
+
if eidx not in seen:
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
+
matching_long_chords_chunks.append(eidx)
|
96 |
+
seen.append(eidx)
|
97 |
+
|
98 |
+
if chords_chunks_memory_length > 0:
|
99 |
+
seen = seen[-chords_chunks_memory_length:]
|
100 |
+
elif chords_chunks_memory_length == 0:
|
101 |
+
seen = []
|
102 |
+
|
103 |
+
else:
|
104 |
+
break
|
105 |
+
|
106 |
+
else:
|
107 |
+
break
|
108 |
+
|
109 |
+
if len(matching_long_chords_chunks) > max_song_len:
|
110 |
+
print('Current song length:', len(matching_long_chords_chunks), 'chords chunks')
|
111 |
+
print('=' * 70)
|
112 |
+
final_song = matching_long_chords_chunks
|
113 |
+
|
114 |
+
max_song_len = max(max_song_len, len(matching_long_chords_chunks))
|
115 |
+
|
116 |
+
tries += 1
|
117 |
+
|
118 |
+
if tries % 500 == 0:
|
119 |
+
print('Number of passed tries:', tries)
|
120 |
+
print('=' * 70)
|
121 |
+
|
122 |
+
if len(matching_long_chords_chunks) > max_song_len:
|
123 |
+
print(len(matching_long_chords_chunks))
|
124 |
+
final_song = matching_long_chords_chunks
|
125 |
+
|
126 |
+
f_song = []
|
127 |
+
|
128 |
+
for mat in final_song:
|
129 |
+
f_song.extend(all_long_good_chords_chunks[mat][:-chunk_size])
|
130 |
+
f_song.extend(all_long_good_chords_chunks[mat][-chunk_size:])
|
131 |
+
|
132 |
+
print('Generated final song after', tries, 'tries with', len(final_song), 'chords chunks and', len(f_song), 'chords')
|
133 |
print('=' * 70)
|
134 |
+
|
135 |
print('Done!')
|
136 |
print('=' * 70)
|
137 |
|
138 |
#===============================================================================
|
|
|
139 |
|
140 |
+
print('Rendering results...')
|
141 |
print('=' * 70)
|
142 |
|
143 |
fn1 = "Melody2Song-Seq2Seq-Music-Transformer-Composition"
|