asigalov61 commited on
Commit
a9f6060
1 Parent(s): 877f868

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -52
app.py CHANGED
@@ -263,16 +263,20 @@ def ClassifyMIDI(input_midi):
263
  all_artists_labels = []
264
 
265
  for i, res in enumerate(results):
266
- result_toks = [res[0]-512, res[1]-512]
267
- song_artist = song_artist_tokens_to_song_artist(result_toks)
268
- gidx = genre_labels_fnames.index(song_artist)
269
- genre = genre_labels[gidx][1]
270
- classification_summary_string += 'Notes ' + str(i*samples_overlap) + '-' + str((i*samples_overlap)+340) + ' === ' + str(genre) + ' --- ' + str(song_artist))
271
-
272
- artist_label = str_strip_artist(song_artist.split(' --- ')[1])
273
-
274
- all_artists_labels.append(artist_label)
275
-
 
 
 
 
276
  print('=' * 70)
277
 
278
  mode_artist_label = mode(all_artists_labels)
@@ -280,31 +284,8 @@ def ClassifyMIDI(input_midi):
280
 
281
  print('Aggregated artist classification label:', mode_artist_label)
282
  print('Aggregated artist classification label ratio:', mode_artist_label_count / len(all_artists_labels))
283
-
284
- print('=' * 70)
285
- print('Done!')
286
- print('=' * 70)
287
-
288
-
289
-
290
-
291
-
292
-
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
301
- print('All classification labels summary:')
302
- print('=' * 70)
303
-
304
- for i, a in enumerate(all_results_labels):
305
- print('Notes', i*85, '-', (i*85)+340, '===', a)
306
- classification_summary_string += 'Notes ' + str(i*85) + ' - ' + str((i*85)+340) + ' === ' + str(a) + '\n'
307
-
308
  classification_summary_string += '=' * 70
309
  classification_summary_string += '\n'
310
 
@@ -312,18 +293,6 @@ def ClassifyMIDI(input_midi):
312
  print('Done!')
313
  print('=' * 70)
314
 
315
- #===============================================================================
316
-
317
- #========================================================
318
-
319
- output_midi_title = str(fn1)
320
- output_midi_summary = classification_summary_string
321
-
322
- print('Output MIDI file name:', mc_song_artist)
323
- print('Output MIDI title:', output_midi_title)
324
- print('=' * 70)
325
-
326
-
327
  #========================================================
328
 
329
  print('-' * 70)
@@ -397,12 +366,12 @@ if __name__ == "__main__":
397
 
398
  app = gr.Blocks()
399
  with app:
400
- gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Advanced MIDI Classifier</h1>")
401
- gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Detailed MIDI classification with transformers</h1>")
402
  gr.Markdown(
403
- "![Visitors](https://api.visitorbadge.io/api/visitors?path=asigalov61.Advanced-MIDI-Classifier&style=flat)\n\n"
404
- "This is a demo for Annotated MIDI Dataset\n\n"
405
- "Check out [Annotated MIDI Dataset](https://huggingface.co/datasets/asigalov61/Annotated-MIDI-Dataset) on Hugging Face!\n\n"
406
  )
407
 
408
  input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])
 
263
  all_artists_labels = []
264
 
265
  for i, res in enumerate(results):
266
+ result_toks = [res[0]-512, res[1]-512]
267
+ song_artist = song_artist_tokens_to_song_artist(result_toks)
268
+ gidx = genre_labels_fnames.index(song_artist)
269
+ genre = genre_labels[gidx][1]
270
+
271
+ print('Notes', i*samples_overlap, '-', (i*samples_overlap)+340, '===', genre, '---', song_artist)
272
+ classification_summary_string += 'Notes ' + str(i*samples_overlap) + ' - ' + str((i*samples_overlap)+340) + ' === ' + str(genre) + ' --- ' + str(song_artist)) + '\n'
273
+
274
+ artist_label = str_strip_artist(song_artist.split(' --- ')[1])
275
+
276
+ all_artists_labels.append(artist_label)
277
+
278
+ classification_summary_string += '=' * 70
279
+ classification_summary_string += '\n'
280
  print('=' * 70)
281
 
282
  mode_artist_label = mode(all_artists_labels)
 
284
 
285
  print('Aggregated artist classification label:', mode_artist_label)
286
  print('Aggregated artist classification label ratio:', mode_artist_label_count / len(all_artists_labels))
287
+ classification_summary_string += 'Aggregated artist classification label: ' + str(mode_artist_label) + '\n'
288
+ classification_summary_string += 'Aggregated artist classification label ratio: ' + str(mode_artist_label_count / len(all_artists_labels)) + '\n'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  classification_summary_string += '=' * 70
290
  classification_summary_string += '\n'
291
 
 
293
  print('Done!')
294
  print('=' * 70)
295
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  #========================================================
297
 
298
  print('-' * 70)
 
366
 
367
  app = gr.Blocks()
368
  with app:
369
+ gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Ultimate MIDI Classifier</h1>")
370
+ gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Classify absolutely any MIDI by genre, song and artist</h1>")
371
  gr.Markdown(
372
+ "![Visitors](https://api.visitorbadge.io/api/visitors?path=asigalov61.Ultimate-MIDI-Classifier&style=flat)\n\n"
373
+ "This is a demo for Ultimate MIDI Classifier\n\n"
374
+ "Check out [Ultimate MIDI Classifier](https://github.com/asigalov61/Ultimate-MIDI-Classifier) on GitHub!\n\n"
375
  )
376
 
377
  input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"])