Hmjz100 commited on
Commit
d938c89
·
verified ·
1 Parent(s): afc549f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
app.py CHANGED
@@ -291,33 +291,37 @@ class InferenceModel(object):
291
  tokens = tokens[:np.argmax(tokens == vocabularies.DECODED_EOS_ID)]
292
  return tokens
293
 
294
-
295
  inference_model = InferenceModel('/home/user/app/checkpoints/mt3/', 'mt3')
296
 
297
-
298
  def inference(audio):
299
- filename = os.path.basename(audio) # 获取输入文件的文件名
300
  print(f"[{current_time()}] 运行:输入文件: {filename}")
301
  with open(audio, 'rb') as fd:
302
  contents = fd.read()
303
- audio = upload_audio(contents,sample_rate=16000)
304
- est_ns = inference_model(audio)
305
  note_seq.sequence_proto_to_midi_file(est_ns, './transcribed.mid')
306
  return './transcribed.mid'
307
 
308
- title = "MT3"
309
- description = "MT3:多任务多音轨音乐转录的 Gradio 演示。要使用它,只需上传音频文件,或点击示例以查看效果。更多信息请参阅下面的链接。"
310
-
311
- article = "<p style='text-align: center'>出错了?试试把文件转换为WAV后再上传吧~</p><p style='text-align: center'><a href='https://arxiv.org/abs/2111.03017' target='_blank'>MT3: 多任务多音轨音乐转录</a> | <a href='https://github.com/hmjz100/mt3' target='_blank'>Github 仓库</a></p>"
312
-
313
- examples=[['canon.flac'], ['download.wav']]
314
-
315
- gr.Interface(
316
- inference,
317
- gr.Audio(type="filepath", label="输入"),
318
- outputs=gr.File(label="输出"),
319
- title=title,
320
- description=description,
321
- article=article,
322
- examples=examples
323
- ).launch()
 
 
 
 
 
 
 
291
  tokens = tokens[:np.argmax(tokens == vocabularies.DECODED_EOS_ID)]
292
  return tokens
293
 
 
294
  inference_model = InferenceModel('/home/user/app/checkpoints/mt3/', 'mt3')
295
 
 
296
  def inference(audio):
297
+ filename = os.path.basename(audio)
298
  print(f"[{current_time()}] 运行:输入文件: {filename}")
299
  with open(audio, 'rb') as fd:
300
  contents = fd.read()
301
+ audio_data = upload_audio(contents, sample_rate=16000)
302
+ est_ns = inference_model(audio_data)
303
  note_seq.sequence_proto_to_midi_file(est_ns, './transcribed.mid')
304
  return './transcribed.mid'
305
 
306
+ with gr.Blocks(title="MT3", theme=gr.themes.Soft()) as demo:
307
+ gr.HTML("<p>MT3:多任务多音轨音乐转录的 Gradio 演示。要使用它,只需上传音频文件,或点击示例以查看效果。更多信息请参阅下面的链接。</p>")
308
+
309
+ with gr.Row():
310
+ with gr.Column():
311
+ audio_input = gr.Audio(type="filepath", label="输入", interactive=True)
312
+ gr.Examples(examples=[['canon.flac'], ['download.wav']], label="示例", inputs=audio_input)
313
+ midi_output = gr.File(label="输出")
314
+
315
+ submit_btn = gr.Button("开始", variant="primary")
316
+ submit_btn.click(
317
+ fn=inference,
318
+ inputs=audio_input,
319
+ outputs=midi_output
320
+ )
321
+
322
+ gr.HTML('''<div class="footer">
323
+ <p style='text-align: center'>出错了?试试把文件转换为WAV后再上传吧~</p>
324
+ <p style='text-align: center'><a href='https://arxiv.org/abs/2111.03017' target='_blank'>MT3: 多任务多音轨音乐转录</a> | <a href='https://github.com/hmjz100/mt3' target='_blank'>Github 仓库</a></p>
325
+ </div>''')
326
+
327
+ demo.launch(server_name="0.0.0.0", share=True)