Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
#==================================================================================
|
| 2 |
-
# https://huggingface.co/spaces/asigalov61/
|
| 3 |
#==================================================================================
|
| 4 |
|
| 5 |
print('=' * 70)
|
| 6 |
-
print('
|
| 7 |
|
| 8 |
print('=' * 70)
|
| 9 |
-
print('Loading core
|
| 10 |
|
| 11 |
import os
|
| 12 |
import copy
|
|
@@ -16,7 +16,7 @@ import datetime
|
|
| 16 |
from pytz import timezone
|
| 17 |
|
| 18 |
print('=' * 70)
|
| 19 |
-
print('Loading main
|
| 20 |
|
| 21 |
os.environ['USE_FLASH_ATTENTION'] = '1'
|
| 22 |
|
|
@@ -30,6 +30,8 @@ torch.backends.cuda.enable_math_sdp(True)
|
|
| 30 |
torch.backends.cuda.enable_flash_sdp(True)
|
| 31 |
torch.backends.cuda.enable_cudnn_sdp(True)
|
| 32 |
|
|
|
|
|
|
|
| 33 |
from huggingface_hub import hf_hub_download
|
| 34 |
|
| 35 |
import TMIDIX
|
|
@@ -43,7 +45,7 @@ import random
|
|
| 43 |
import tqdm
|
| 44 |
|
| 45 |
print('=' * 70)
|
| 46 |
-
print('Loading aux
|
| 47 |
|
| 48 |
import matplotlib.pyplot as plt
|
| 49 |
|
|
@@ -59,7 +61,7 @@ print('=' * 70)
|
|
| 59 |
|
| 60 |
#==================================================================================
|
| 61 |
|
| 62 |
-
MODEL_CHECKPOINT = '
|
| 63 |
|
| 64 |
SOUDFONT_PATH = 'SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2'
|
| 65 |
|
|
@@ -72,7 +74,7 @@ MAX_GEN_TOKS = 3072
|
|
| 72 |
print('=' * 70)
|
| 73 |
print('Loading popular hook melodies dataset...')
|
| 74 |
|
| 75 |
-
popular_hook_melodies_pickle = hf_hub_download(repo_id='asigalov61/
|
| 76 |
filename='popular_hook_melodies_24_64_CC_BY_NC_SA.pickle'
|
| 77 |
)
|
| 78 |
|
|
@@ -112,7 +114,7 @@ model = AutoregressiveWrapper(model, ignore_index=PAD_IDX, pad_value=PAD_IDX)
|
|
| 112 |
print('=' * 70)
|
| 113 |
print('Loading model checkpoint...')
|
| 114 |
|
| 115 |
-
model_checkpoint = hf_hub_download(repo_id='asigalov61/
|
| 116 |
|
| 117 |
model.load_state_dict(torch.load(model_checkpoint, map_location='cpu', weights_only=True))
|
| 118 |
|
|
@@ -348,10 +350,10 @@ def Generate_Accompaniment(input_midi,
|
|
| 348 |
|
| 349 |
song_f.append(['note', time, dur, channel, pitch, vel, patch])
|
| 350 |
|
| 351 |
-
fn1 = "
|
| 352 |
|
| 353 |
detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
|
| 354 |
-
output_signature = '
|
| 355 |
output_file_name = fn1,
|
| 356 |
track_name='Project Los Angeles',
|
| 357 |
list_of_MIDI_patches=patches_map
|
|
@@ -405,11 +407,11 @@ with gr.Blocks() as demo:
|
|
| 405 |
|
| 406 |
#==================================================================================
|
| 407 |
|
| 408 |
-
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>
|
| 409 |
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Guided melody accompaniment generation with transformers</h1>")
|
| 410 |
gr.HTML("""
|
| 411 |
<p>
|
| 412 |
-
<a href="https://huggingface.co/spaces/asigalov61/
|
| 413 |
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-md.svg" alt="Duplicate in Hugging Face">
|
| 414 |
</a>
|
| 415 |
</p>
|
|
|
|
| 1 |
#==================================================================================
|
| 2 |
+
# https://huggingface.co/spaces/asigalov61/MIDI-Genre-Classifier
|
| 3 |
#==================================================================================
|
| 4 |
|
| 5 |
print('=' * 70)
|
| 6 |
+
print('MIDI Genre Classifier Gradio App')
|
| 7 |
|
| 8 |
print('=' * 70)
|
| 9 |
+
print('Loading core MIDI Genre Classifier modules...')
|
| 10 |
|
| 11 |
import os
|
| 12 |
import copy
|
|
|
|
| 16 |
from pytz import timezone
|
| 17 |
|
| 18 |
print('=' * 70)
|
| 19 |
+
print('Loading main MIDI Genre Classifier modules...')
|
| 20 |
|
| 21 |
os.environ['USE_FLASH_ATTENTION'] = '1'
|
| 22 |
|
|
|
|
| 30 |
torch.backends.cuda.enable_flash_sdp(True)
|
| 31 |
torch.backends.cuda.enable_cudnn_sdp(True)
|
| 32 |
|
| 33 |
+
import numpy as np
|
| 34 |
+
|
| 35 |
from huggingface_hub import hf_hub_download
|
| 36 |
|
| 37 |
import TMIDIX
|
|
|
|
| 45 |
import tqdm
|
| 46 |
|
| 47 |
print('=' * 70)
|
| 48 |
+
print('Loading aux MIDI Genre Classifier modules...')
|
| 49 |
|
| 50 |
import matplotlib.pyplot as plt
|
| 51 |
|
|
|
|
| 61 |
|
| 62 |
#==================================================================================
|
| 63 |
|
| 64 |
+
MODEL_CHECKPOINT = 'MIDI_Genre_Classifier_Trained_Model_36457_steps_0.5384_loss_0.8417_acc.pth'
|
| 65 |
|
| 66 |
SOUDFONT_PATH = 'SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2'
|
| 67 |
|
|
|
|
| 74 |
print('=' * 70)
|
| 75 |
print('Loading popular hook melodies dataset...')
|
| 76 |
|
| 77 |
+
popular_hook_melodies_pickle = hf_hub_download(repo_id='asigalov61/MIDI-Genre-Classifier',
|
| 78 |
filename='popular_hook_melodies_24_64_CC_BY_NC_SA.pickle'
|
| 79 |
)
|
| 80 |
|
|
|
|
| 114 |
print('=' * 70)
|
| 115 |
print('Loading model checkpoint...')
|
| 116 |
|
| 117 |
+
model_checkpoint = hf_hub_download(repo_id='asigalov61/MIDI-Genre-Classifier', filename=MODEL_CHECKPOINT)
|
| 118 |
|
| 119 |
model.load_state_dict(torch.load(model_checkpoint, map_location='cpu', weights_only=True))
|
| 120 |
|
|
|
|
| 350 |
|
| 351 |
song_f.append(['note', time, dur, channel, pitch, vel, patch])
|
| 352 |
|
| 353 |
+
fn1 = "MIDI-Genre-Classifier-Composition"
|
| 354 |
|
| 355 |
detailed_stats = TMIDIX.Tegridy_ms_SONG_to_MIDI_Converter(song_f,
|
| 356 |
+
output_signature = 'MIDI Genre Classifier',
|
| 357 |
output_file_name = fn1,
|
| 358 |
track_name='Project Los Angeles',
|
| 359 |
list_of_MIDI_patches=patches_map
|
|
|
|
| 407 |
|
| 408 |
#==================================================================================
|
| 409 |
|
| 410 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>MIDI Genre Classifier</h1>")
|
| 411 |
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Guided melody accompaniment generation with transformers</h1>")
|
| 412 |
gr.HTML("""
|
| 413 |
<p>
|
| 414 |
+
<a href="https://huggingface.co/spaces/asigalov61/MIDI-Genre-Classifier?duplicate=true">
|
| 415 |
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-md.svg" alt="Duplicate in Hugging Face">
|
| 416 |
</a>
|
| 417 |
</p>
|