dx2102 commited on
Commit
040724b
·
verified ·
1 Parent(s): 2e8cca4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
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
- # we need to ignore the invalid output by the model
57
- try:
58
- # Remove the first three lines. 1: Score title, 2: The "pitch duration..." hint, 3: Empty line
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
- except Exception as e:
77
- print('Postprocess: Ignored error:', e)
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