Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -48,15 +48,15 @@ example_prefix = '''pitch duration wait velocity instrument
|
|
48 |
|
49 |
|
50 |
def postprocess(txt, path):
|
51 |
-
|
|
|
52 |
# track = symusic.core.TrackSecond()
|
53 |
tracks = {}
|
54 |
|
55 |
now = 0
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
for line in txt.split('\n')[3:]:
|
60 |
pitch, duration, wait, velocity, instrument = line.split()
|
61 |
pitch, duration, wait, velocity = [int(x) for x in [pitch, duration, wait, velocity]]
|
62 |
if instrument not in tracks:
|
@@ -73,8 +73,8 @@ def postprocess(txt, path):
|
|
73 |
velocity=int(velocity * 4),
|
74 |
))
|
75 |
now += wait
|
76 |
-
|
77 |
-
|
78 |
|
79 |
print(f'Postprocess: Got {sum(len(track.notes) for track in tracks.values())} notes')
|
80 |
|
|
|
48 |
|
49 |
|
50 |
def postprocess(txt, path):
|
51 |
+
# remove prefix
|
52 |
+
txt = txt.split('\n\n')[-1]
|
53 |
# track = symusic.core.TrackSecond()
|
54 |
tracks = {}
|
55 |
|
56 |
now = 0
|
57 |
+
for line in txt.split('\n'):
|
58 |
+
# we need to ignore the invalid output by the model
|
59 |
+
try:
|
|
|
60 |
pitch, duration, wait, velocity, instrument = line.split()
|
61 |
pitch, duration, wait, velocity = [int(x) for x in [pitch, duration, wait, velocity]]
|
62 |
if instrument not in tracks:
|
|
|
73 |
velocity=int(velocity * 4),
|
74 |
))
|
75 |
now += wait
|
76 |
+
except Exception as e:
|
77 |
+
print(f'Postprocess: Ignored line: "{line}" because of error:', e)
|
78 |
|
79 |
print(f'Postprocess: Got {sum(len(track.notes) for track in tracks.values())} notes')
|
80 |
|