suric commited on
Commit
7dd86da
·
1 Parent(s): 4336e0a

test on test app

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. test_app.py +42 -0
README.md CHANGED
@@ -7,7 +7,7 @@ sdk: gradio
7
  sdk_version: 4.21.0
8
  python_version: 3.9
9
  suggested_hardware: "a10g-large"
10
- app_file: app.py
11
  pinned: false
12
  tags: ["MusicAI", "MultiModal", "Audio", "Text", "Image"]
13
  license: mit
 
7
  sdk_version: 4.21.0
8
  python_version: 3.9
9
  suggested_hardware: "a10g-large"
10
+ app_file: test_app.py
11
  pinned: false
12
  tags: ["MusicAI", "MultiModal", "Audio", "Text", "Image"]
13
  license: mit
test_app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from math import log2, pow
2
+ import os
3
+
4
+ import numpy as np
5
+ from scipy.fftpack import fft
6
+ import basic_pitch
7
+ import basic_pitch.inference
8
+ from basic_pitch import ICASSP_2022_MODEL_PATH
9
+ from tempfile import NamedTemporaryFile
10
+
11
+ import gradio as gr
12
+
13
+ def transcribe(audio_path):
14
+ # model_output, midi_data, note_events = predict("generated_0.wav")
15
+ model_output, midi_data, note_events = basic_pitch.inference.predict(
16
+ audio_path=audio_path,
17
+ model_or_model_path=ICASSP_2022_MODEL_PATH,
18
+ )
19
+
20
+ with NamedTemporaryFile("wb", suffix=".mid", delete=False) as file:
21
+ try:
22
+ midi_data.write(file)
23
+ print(f"midi file saved to {file.name}")
24
+ except Exception as e:
25
+ print(f"Error while writing midi file: {e}")
26
+ raise e
27
+
28
+ return gr.DownloadButton(
29
+ value=file.name,
30
+ label=f"Download MIDI file {file.name}",
31
+ visible=True)
32
+
33
+
34
+ with gr.Blocks() as demo:
35
+ transcribe_button = gr.Button("Transcribe")
36
+ audio = gr.Audio("audio", type="filepath")
37
+
38
+ d = gr.DownloadButton("Download the file", visible=False)
39
+ transcribe_button.click(transcribe, inputs=[audio], outputs=d)
40
+ if __name__ == "__main__":
41
+ demo.launch()
42
+