humtrans / app.py
hayaton0005's picture
Upload 2 files
d4b96ca verified
raw
history blame
988 Bytes
import gradio as gr
import os
from infer import infer_midi_from_wav
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
# 推論関数(MIDI生成のみ)
def transcribe(audio_path):
midi_path = infer_midi_from_wav(audio_path)
return midi_path
# HTML再生用(replay.htmlを読み込む)
replay_html = open(os.path.join(BASE_DIR, "replay.html")).read()
# Gradio インターフェース
with gr.Blocks() as demo:
gr.Markdown("## 鼻歌からのMIDI変換デモ")
gr.Markdown("録音した音声をMIDIに変換し、ブラウザで再生できます。")
with gr.Row():
audio_input = gr.Audio(type="filepath", label="マイク録音")
midi_output = gr.File(label="変換されたMIDI")
run_btn = gr.Button("▶️ 変換")
# MIDI変換ボタンを押すとMIDIファイルを出力
run_btn.click(fn=transcribe, inputs=audio_input, outputs=midi_output)
# HTMLによるMIDI再生UI
gr.HTML(replay_html)
demo.launch()