asigalov61 commited on
Commit
65c585b
1 Parent(s): 09984c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -72
app.py CHANGED
@@ -66,6 +66,7 @@ def GenerateSong(input_melody_seed_number):
66
 
67
  print('Done!')
68
  print('=' * 70)
 
69
  print('Input melody seed number:', input_melody_seed_number)
70
  print('-' * 70)
71
 
@@ -73,61 +74,21 @@ def GenerateSong(input_melody_seed_number):
73
 
74
  print('=' * 70)
75
 
76
- print('Sample output events', melody_chords[:5])
77
  print('=' * 70)
78
  print('Generating...')
79
 
80
- output = []
81
-
82
- max_chords_limit = 8
83
- temperature=0.9
84
- num_memory_tokens=4096
85
 
86
- output = []
87
-
88
- idx = 0
89
-
90
- for c in chords[:input_num_tokens]:
91
-
92
- output.append(c)
93
 
94
- if input_conditioning_type == 'Chords-Times' or input_conditioning_type == 'Chords-Times-Durations':
95
- output.append(times[idx])
96
-
97
- if input_conditioning_type == 'Chords-Times-Durations':
98
- output.append(durs[idx])
99
-
100
- x = torch.tensor([output] * 1, dtype=torch.long, device='cuda')
101
-
102
- o = 0
103
-
104
- ncount = 0
105
-
106
- while o < 384 and ncount < max_chords_limit:
107
- with ctx:
108
- out = model.generate(x[-num_memory_tokens:],
109
- 1,
110
- temperature=temperature,
111
- return_prime=False,
112
- verbose=False)
113
-
114
- o = out.tolist()[0][0]
115
 
116
- if 256 <= o < 384:
117
- ncount += 1
118
-
119
- if o < 384:
120
- x = torch.cat((x, out), 1)
121
-
122
- outy = x.tolist()[0][len(output):]
123
-
124
- output.extend(outy)
125
-
126
- idx += 1
127
-
128
- if idx == len(chords[:input_num_tokens])-1:
129
- break
130
-
131
  print('=' * 70)
132
  print('Done!')
133
  print('=' * 70)
@@ -136,7 +97,7 @@ def GenerateSong(input_melody_seed_number):
136
  print('Rendering results...')
137
 
138
  print('=' * 70)
139
- print('Sample INTs', output[:12])
140
  print('=' * 70)
141
 
142
  out1 = output
@@ -151,33 +112,40 @@ def GenerateSong(input_melody_seed_number):
151
  vel = 90
152
  pitch = 0
153
  channel = 0
154
-
155
  patches = [0] * 16
156
-
157
- channel = 0
158
-
159
  for ss in song:
160
-
161
- if 0 <= ss < 128:
162
-
163
- time += ss * 32
164
-
165
- if 128 <= ss < 256:
166
-
167
- dur = (ss-128) * 32
168
-
169
- if 256 <= ss < 384:
170
-
171
- pitch = (ss-256)
172
-
173
- vel = max(40, pitch)
174
-
175
- song_f.append(['note', time, dur, channel, pitch, vel, 0])
 
 
 
 
 
 
 
 
176
 
177
- fn1 = "Chords-Progressions-Transformer-Composition"
178
 
179
  detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
180
- output_signature = 'Chords Progressions Transformer',
181
  output_file_name = fn1,
182
  track_name='Project Los Angeles',
183
  list_of_MIDI_patches=patches
 
66
 
67
  print('Done!')
68
  print('=' * 70)
69
+ seed_melody = seed_melodies_data[input_melody_seed_number]
70
  print('Input melody seed number:', input_melody_seed_number)
71
  print('-' * 70)
72
 
 
74
 
75
  print('=' * 70)
76
 
77
+ print('Sample output events', seed_melody[:16])
78
  print('=' * 70)
79
  print('Generating...')
80
 
81
+ x = (torch.tensor(melody, dtype=torch.long, device='cuda')[None, ...])
 
 
 
 
82
 
83
+ with ctx:
84
+ out = model.generate(x,
85
+ 1536,
86
+ temperature=0.9,
87
+ return_prime=False,
88
+ verbose=False)
 
89
 
90
+ output = out.tolist()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  print('=' * 70)
93
  print('Done!')
94
  print('=' * 70)
 
97
  print('Rendering results...')
98
 
99
  print('=' * 70)
100
+ print('Sample INTs', output[:15])
101
  print('=' * 70)
102
 
103
  out1 = output
 
112
  vel = 90
113
  pitch = 0
114
  channel = 0
115
+
116
  patches = [0] * 16
117
+ patches[3] = 40
118
+
 
119
  for ss in song:
120
+
121
+ if 0 < ss < 128:
122
+
123
+ time += (ss * 32)
124
+
125
+ if 128 < ss < 256:
126
+
127
+ dur = (ss-128) * 32
128
+
129
+ if 256 < ss < 512:
130
+
131
+ pitch = (ss-256) % 128
132
+
133
+ channel = (ss-256) // 128
134
+
135
+ if channel == 1:
136
+ channel = 3
137
+ vel = 110 + (pitch % 12)
138
+ song_f.append(['note', time, dur, channel, pitch, vel, 40])
139
+
140
+ else:
141
+ vel = 80 + (pitch % 12)
142
+ channel = 0
143
+ song_f.append(['note', time, dur, channel, pitch, vel, 0])
144
 
145
+ fn1 = "Melody2Song-Seq2Seq-Music-Transformer-Composition"
146
 
147
  detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
148
+ output_signature = 'Melody2Song Seq2Seq Music Transformer',
149
  output_file_name = fn1,
150
  track_name='Project Los Angeles',
151
  list_of_MIDI_patches=patches