asigalov61 commited on
Commit
f8c0b9d
1 Parent(s): 0219c58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -64
app.py CHANGED
@@ -59,81 +59,81 @@ def Generate_Chords_Progression(total_song_length_in_chords_chunks,
59
  print('Generating...')
60
  print('=' * 70)
61
 
62
- matching_long_chords_chunks = []
63
-
64
- ridx = random.randint(0, len(all_long_chords_tokens_chunks)-1)
65
-
66
- matching_long_chords_chunks.append(ridx)
67
-
68
- max_song_len = 0
69
-
70
- tries = 0
71
-
72
- while len(matching_long_chords_chunks) < minimum_song_length_in_chords_chunks:
73
-
74
  matching_long_chords_chunks = []
75
-
76
  ridx = random.randint(0, len(all_long_chords_tokens_chunks)-1)
77
-
78
  matching_long_chords_chunks.append(ridx)
79
- seen = [ridx]
80
- gseen = [ridx]
81
-
82
- for a in range(minimum_song_length_in_chords_chunks * 10):
83
-
84
- if not matching_long_chords_chunks:
85
- break
86
-
87
- if len(matching_long_chords_chunks) > minimum_song_length_in_chords_chunks:
88
- break
89
-
90
- schunk = all_long_chords_tokens_chunks[matching_long_chords_chunks[-1]]
91
- trg_long_chunk = np.array(schunk[-chunk_size:])
92
- idxs = np.where((src_long_chunks == trg_long_chunk).all(axis=1))[0].tolist()
93
-
94
- if len(idxs) > 1:
95
-
96
- random.shuffle(idxs)
97
-
98
- eidxs = [i for i in idxs if i not in seen]
99
-
100
- if eidxs:
101
- eidx = eidxs[0]
102
- matching_long_chords_chunks.append(eidx)
103
- seen.append(eidx)
104
- gseen.append(eidx)
105
-
106
- if 0 < chords_chunks_memory_ratio < 1:
107
- seen = random.choices(gseen, k=math.ceil(len(gseen) * chords_chunks_memory_ratio))
108
- elif chords_chunks_memory_ratio == 0:
109
- seen = []
110
 
111
- else:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  gseen.pop()
113
  matching_long_chords_chunks.pop()
114
-
115
- else:
116
- gseen.pop()
117
- matching_long_chords_chunks.pop()
118
-
 
 
 
 
 
 
 
 
 
119
 
120
  if len(matching_long_chords_chunks) > max_song_len:
121
  print('Current song length:', len(matching_long_chords_chunks), 'chords chunks')
122
  print('=' * 70)
123
  final_song = matching_long_chords_chunks
124
-
125
- max_song_len = max(max_song_len, len(matching_long_chords_chunks))
126
-
127
- tries += 1
128
-
129
- if tries % 500 == 0:
130
- print('Number of passed tries:', tries)
131
- print('=' * 70)
132
-
133
-
134
- if len(matching_long_chords_chunks) > max_song_len:
135
- print(len(matching_long_chords_chunks))
136
- final_song = matching_long_chords_chunks
137
 
138
  f_song = []
139
 
 
59
  print('Generating...')
60
  print('=' * 70)
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  matching_long_chords_chunks = []
63
+
64
  ridx = random.randint(0, len(all_long_chords_tokens_chunks)-1)
65
+
66
  matching_long_chords_chunks.append(ridx)
67
+
68
+ max_song_len = 0
69
+
70
+ tries = 0
71
+
72
+ while len(matching_long_chords_chunks) < minimum_song_length_in_chords_chunks:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
+ matching_long_chords_chunks = []
75
+
76
+ ridx = random.randint(0, len(all_long_chords_tokens_chunks)-1)
77
+
78
+ matching_long_chords_chunks.append(ridx)
79
+ seen = [ridx]
80
+ gseen = [ridx]
81
+
82
+ for a in range(minimum_song_length_in_chords_chunks * 10):
83
+
84
+ if not matching_long_chords_chunks:
85
+ break
86
+
87
+ if len(matching_long_chords_chunks) > minimum_song_length_in_chords_chunks:
88
+ break
89
+
90
+ schunk = all_long_chords_tokens_chunks[matching_long_chords_chunks[-1]]
91
+ trg_long_chunk = np.array(schunk[-chunk_size:])
92
+ idxs = np.where((src_long_chunks == trg_long_chunk).all(axis=1))[0].tolist()
93
+
94
+ if len(idxs) > 1:
95
+
96
+ random.shuffle(idxs)
97
+
98
+ eidxs = [i for i in idxs if i not in seen]
99
+
100
+ if eidxs:
101
+ eidx = eidxs[0]
102
+ matching_long_chords_chunks.append(eidx)
103
+ seen.append(eidx)
104
+ gseen.append(eidx)
105
+
106
+ if 0 < chords_chunks_memory_ratio < 1:
107
+ seen = random.choices(gseen, k=math.ceil(len(gseen) * chords_chunks_memory_ratio))
108
+ elif chords_chunks_memory_ratio == 0:
109
+ seen = []
110
+
111
+ else:
112
+ gseen.pop()
113
+ matching_long_chords_chunks.pop()
114
+
115
+ else:
116
  gseen.pop()
117
  matching_long_chords_chunks.pop()
118
+
119
+
120
+ if len(matching_long_chords_chunks) > max_song_len:
121
+ print('Current song length:', len(matching_long_chords_chunks), 'chords chunks')
122
+ print('=' * 70)
123
+ final_song = matching_long_chords_chunks
124
+
125
+ max_song_len = max(max_song_len, len(matching_long_chords_chunks))
126
+
127
+ tries += 1
128
+
129
+ if tries % 500 == 0:
130
+ print('Number of passed tries:', tries)
131
+ print('=' * 70)
132
 
133
  if len(matching_long_chords_chunks) > max_song_len:
134
  print('Current song length:', len(matching_long_chords_chunks), 'chords chunks')
135
  print('=' * 70)
136
  final_song = matching_long_chords_chunks
 
 
 
 
 
 
 
 
 
 
 
 
 
137
 
138
  f_song = []
139