Spaces:
Sleeping
Sleeping
File size: 1,218 Bytes
7dd86da |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
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()
|