asigalov61 commited on
Commit
f025921
1 Parent(s): 980027a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -28,7 +28,7 @@ in_space = os.getenv("SYSTEM") == "spaces"
28
 
29
  #==========================================================================================================
30
 
31
- def render_midi(input_midi, render_options):
32
 
33
  print('*' * 70)
34
  print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
@@ -46,7 +46,7 @@ def render_midi(input_midi, render_options):
46
  print('=' * 70)
47
  print('Input MIDI file name:', fn)
48
  print('Input MIDI md5 hash', input_midi_md5hash)
49
- print('Render options:', render_options)
50
 
51
  print('=' * 70)
52
  print('Processing MIDI...Please wait...')
@@ -80,17 +80,18 @@ def render_midi(input_midi, render_options):
80
  print('=' * 70)
81
  print('Processing...Please wait...')
82
 
83
- if not render_options:
84
- output_score = escore
85
 
86
- elif "Render as-is" in render_options:
87
- output_score = escore
88
-
89
- elif "Extract melody" in render_options:
90
- output_score = [c[0] for c in cscore if c[0][3] != 9]
91
  for e in output_score:
92
  e[3] = 0
93
  e[6] = 40
 
 
 
94
 
95
  print('Done processing!')
96
  print('=' * 70)
@@ -207,8 +208,8 @@ if __name__ == "__main__":
207
  input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"], type="filepath")
208
 
209
  gr.Markdown("## Select desired render options")
210
-
211
- render_options = gr.CheckboxGroup(["Render as-is", "Extract melody", "Transform"], value="Render as-is")
212
 
213
  submit = gr.Button()
214
 
@@ -221,7 +222,7 @@ if __name__ == "__main__":
221
  output_plot = gr.Plot(label="Output MIDI score plot")
222
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
223
 
224
- run_event = submit.click(render_midi, [input_midi, render_options],
225
  [output_midi_md5, output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
226
 
227
  app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)
 
28
 
29
  #==========================================================================================================
30
 
31
+ def render_midi(input_midi, render_type):
32
 
33
  print('*' * 70)
34
  print('Req start time: {:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now(PDT)))
 
46
  print('=' * 70)
47
  print('Input MIDI file name:', fn)
48
  print('Input MIDI md5 hash', input_midi_md5hash)
49
+ print('Render type:', render_type)
50
 
51
  print('=' * 70)
52
  print('Processing MIDI...Please wait...')
 
80
  print('=' * 70)
81
  print('Processing...Please wait...')
82
 
83
+ if render_type == "Render as-is" or not render_type:
84
+ output_score = copy.deepcopy(escore)
85
 
86
+ elif render_type == "Extract melody":
87
+ output_score = copy.deepcopy([c[0] for c in cscore if c[0][3] != 9])
88
+
 
 
89
  for e in output_score:
90
  e[3] = 0
91
  e[6] = 40
92
+
93
+ if e[4] < 60:
94
+ e[4] = (e[4] % 12) + 60
95
 
96
  print('Done processing!')
97
  print('=' * 70)
 
208
  input_midi = gr.File(label="Input MIDI", file_types=[".midi", ".mid", ".kar"], type="filepath")
209
 
210
  gr.Markdown("## Select desired render options")
211
+
212
+ render_type = gr.Radio(["Render as-is", "Extract melody", "Transform"], label="Render type", value="Render as-is")
213
 
214
  submit = gr.Button()
215
 
 
222
  output_plot = gr.Plot(label="Output MIDI score plot")
223
  output_midi = gr.File(label="Output MIDI file", file_types=[".mid"])
224
 
225
+ run_event = submit.click(render_midi, [input_midi, render_type],
226
  [output_midi_md5, output_midi_title, output_midi_summary, output_midi, output_audio, output_plot])
227
 
228
  app.queue(1).launch(server_port=opt.port, share=opt.share, inbrowser=True)