Spaces:
Sleeping
Sleeping
Commit
·
606e959
1
Parent(s):
6924978
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,6 +16,10 @@ import TMIDIX
|
|
| 16 |
|
| 17 |
import matplotlib.pyplot as plt
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
in_space = os.getenv("SYSTEM") == "spaces"
|
| 20 |
|
| 21 |
|
|
@@ -24,9 +28,13 @@ in_space = os.getenv("SYSTEM") == "spaces"
|
|
| 24 |
@torch.no_grad()
|
| 25 |
def GenerateMIDI(num_tok, idrums, iinstr):
|
| 26 |
print('=' * 70)
|
| 27 |
-
print('Req
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
print('=' * 70)
|
| 31 |
|
| 32 |
if idrums:
|
|
@@ -77,7 +85,7 @@ def GenerateMIDI(num_tok, idrums, iinstr):
|
|
| 77 |
yield output, None, None, [create_msg("visualizer_clear", None)]
|
| 78 |
|
| 79 |
outy = start_tokens
|
| 80 |
-
|
| 81 |
dur = 0
|
| 82 |
vel = 0
|
| 83 |
pitch = 0
|
|
@@ -97,7 +105,7 @@ def GenerateMIDI(num_tok, idrums, iinstr):
|
|
| 97 |
ss1 = int(out0[0])
|
| 98 |
|
| 99 |
if 0 < ss1 < 256:
|
| 100 |
-
|
| 101 |
|
| 102 |
if 256 <= ss1 < 1280:
|
| 103 |
dur = ((ss1 - 256) // 8) * 32
|
|
@@ -106,7 +114,7 @@ def GenerateMIDI(num_tok, idrums, iinstr):
|
|
| 106 |
if 1280 <= ss1 < 2816:
|
| 107 |
channel = (ss1 - 1280) // 128
|
| 108 |
pitch = (ss1 - 1280) % 128
|
| 109 |
-
event = ['note',
|
| 110 |
output[-1].append(event)
|
| 111 |
|
| 112 |
yield output, None, None, [create_msg("visualizer_append", event), create_msg("progress", [i + 1, num_tok])]
|
|
@@ -117,7 +125,13 @@ def GenerateMIDI(num_tok, idrums, iinstr):
|
|
| 117 |
f.write(midi_data)
|
| 118 |
|
| 119 |
audio = synthesis(TMIDIX.score2opus(output), 'SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2')
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
yield output, "Allegro-Music-Transformer-Music-Composition.mid", (44100, audio), [
|
| 122 |
create_msg("visualizer_end", None)]
|
| 123 |
|
|
@@ -176,10 +190,13 @@ def create_msg(name, data):
|
|
| 176 |
|
| 177 |
|
| 178 |
if __name__ == "__main__":
|
|
|
|
| 179 |
parser = argparse.ArgumentParser()
|
| 180 |
parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
|
| 181 |
parser.add_argument("--port", type=int, default=7860, help="gradio server port")
|
| 182 |
opt = parser.parse_args()
|
|
|
|
|
|
|
| 183 |
|
| 184 |
print('Loading model...')
|
| 185 |
|
|
|
|
| 16 |
|
| 17 |
import matplotlib.pyplot as plt
|
| 18 |
|
| 19 |
+
import time
|
| 20 |
+
import datetime
|
| 21 |
+
from pytz import timezone
|
| 22 |
+
|
| 23 |
in_space = os.getenv("SYSTEM") == "spaces"
|
| 24 |
|
| 25 |
|
|
|
|
| 28 |
@torch.no_grad()
|
| 29 |
def GenerateMIDI(num_tok, idrums, iinstr):
|
| 30 |
print('=' * 70)
|
| 31 |
+
print('Req time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
|
| 32 |
+
start_time = time.time()
|
| 33 |
+
|
| 34 |
+
print('=' * 70)
|
| 35 |
+
print('Req num tok:', num_tok)
|
| 36 |
+
print('Req instr:', iinstr)
|
| 37 |
+
print('Drums:', idrums)
|
| 38 |
print('=' * 70)
|
| 39 |
|
| 40 |
if idrums:
|
|
|
|
| 85 |
yield output, None, None, [create_msg("visualizer_clear", None)]
|
| 86 |
|
| 87 |
outy = start_tokens
|
| 88 |
+
ctime = 0
|
| 89 |
dur = 0
|
| 90 |
vel = 0
|
| 91 |
pitch = 0
|
|
|
|
| 105 |
ss1 = int(out0[0])
|
| 106 |
|
| 107 |
if 0 < ss1 < 256:
|
| 108 |
+
ctime += ss1 * 8
|
| 109 |
|
| 110 |
if 256 <= ss1 < 1280:
|
| 111 |
dur = ((ss1 - 256) // 8) * 32
|
|
|
|
| 114 |
if 1280 <= ss1 < 2816:
|
| 115 |
channel = (ss1 - 1280) // 128
|
| 116 |
pitch = (ss1 - 1280) % 128
|
| 117 |
+
event = ['note', ctime, dur, channel, pitch, vel]
|
| 118 |
output[-1].append(event)
|
| 119 |
|
| 120 |
yield output, None, None, [create_msg("visualizer_append", event), create_msg("progress", [i + 1, num_tok])]
|
|
|
|
| 125 |
f.write(midi_data)
|
| 126 |
|
| 127 |
audio = synthesis(TMIDIX.score2opus(output), 'SGM-v2.01-YamahaGrand-Guit-Bass-v2.7.sf2')
|
| 128 |
+
|
| 129 |
+
print('=' * 70)
|
| 130 |
+
print('Sample output INTs', outy[:16])
|
| 131 |
+
print('=' * 70)
|
| 132 |
+
print('Req execution time:', (time.time() - start_time), 'sec')
|
| 133 |
+
print('=' * 70)
|
| 134 |
+
|
| 135 |
yield output, "Allegro-Music-Transformer-Music-Composition.mid", (44100, audio), [
|
| 136 |
create_msg("visualizer_end", None)]
|
| 137 |
|
|
|
|
| 190 |
|
| 191 |
|
| 192 |
if __name__ == "__main__":
|
| 193 |
+
print('=' * 70)
|
| 194 |
parser = argparse.ArgumentParser()
|
| 195 |
parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
|
| 196 |
parser.add_argument("--port", type=int, default=7860, help="gradio server port")
|
| 197 |
opt = parser.parse_args()
|
| 198 |
+
|
| 199 |
+
PDT = timezone('US/Pacific')
|
| 200 |
|
| 201 |
print('Loading model...')
|
| 202 |
|