from math import log2, pow import os import numpy as np from scipy.fftpack import fft import basic_pitch import basic_pitch.inference from basic_pitch import ICASSP_2022_MODEL_PATH from tempfile import NamedTemporaryFile import gradio as gr def transcribe(audio_path): # model_output, midi_data, note_events = predict("generated_0.wav") model_output, midi_data, note_events = basic_pitch.inference.predict( audio_path=audio_path, model_or_model_path=ICASSP_2022_MODEL_PATH, ) with NamedTemporaryFile("wb", suffix=".mid", delete=False) as file: try: midi_data.write(file) print(f"midi file saved to {file.name}") except Exception as e: print(f"Error while writing midi file: {e}") raise e return gr.DownloadButton( value=file.name, label=f"Download MIDI file {file.name}", visible=True) with gr.Blocks() as demo: transcribe_button = gr.Button("Transcribe") audio = gr.Audio("audio", type="filepath") d = gr.DownloadButton("Download the file", visible=False) transcribe_button.click(transcribe, inputs=[audio], outputs=d) if __name__ == "__main__": demo.launch()