juancopi81 commited on
Commit
1f1f657
1 Parent(s): c0fa1b2

Add piano roll

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -9,7 +9,7 @@ from pytube import YouTube
9
  from pydub import AudioSegment
10
 
11
  from inferencemodel import InferenceModel
12
- from utils import upload_audio
13
 
14
  import nest_asyncio
15
  nest_asyncio.apply()
@@ -24,13 +24,13 @@ current_model = "mt3"
24
  def change_model(model):
25
  global current_model
26
  global inference_model
 
 
27
  checkpoint_path = f"/home/user/app/checkpoints/{model}/"
28
  if model == current_model:
29
  return
30
  inference_model = InferenceModel(checkpoint_path, model)
31
  current_model = model
32
- print("Inferece model", inference_model)
33
- print("Current model", current_model)
34
 
35
  # Credits https://huggingface.co/spaces/rajesh1729/youtube-video-transcription-with-whisper
36
  def get_audio(url):
@@ -69,9 +69,9 @@ def inference(yt_audio_path):
69
  synth = note_seq.midi_synth.fluidsynth
70
  array_of_floats = synth(est_ns, sample_rate=SAMPLE_RATE, sf2_path=SF2_PATH)
71
  int16_data = note_seq.audio_io.float_samples_to_int16(array_of_floats)
72
- # piano_roll = create_image_from_note_sequence(note_sequence)
73
 
74
- return "./transcribed.mid", (SAMPLE_RATE, int16_data)
75
 
76
  title = "Transcribe music from YouTube videos using Transformers."
77
  description = """
@@ -107,7 +107,7 @@ with demo:
107
  img = gr.Image(label="Thumbnail")
108
  with gr.Row():
109
  yt_audio = gr.Audio()
110
- yt_audio_path = gr.Textbox()
111
 
112
  link.change(fn=populate_metadata, inputs=link, outputs=[img, title, yt_audio, yt_audio_path])
113
 
@@ -117,10 +117,12 @@ with demo:
117
  with gr.Row():
118
  midi_file = gr.File()
119
  midi_audio = gr.Audio()
 
 
120
 
121
  btn.click(inference,
122
  inputs=yt_audio_path,
123
- outputs=[midi_file, midi_audio])
124
 
125
  gr.Markdown(article)
126
 
 
9
  from pydub import AudioSegment
10
 
11
  from inferencemodel import InferenceModel
12
+ from utils import upload_audio, create_image_from_note_sequence
13
 
14
  import nest_asyncio
15
  nest_asyncio.apply()
 
24
  def change_model(model):
25
  global current_model
26
  global inference_model
27
+ print("Inferece model", inference_model)
28
+ print("Current model", current_model)
29
  checkpoint_path = f"/home/user/app/checkpoints/{model}/"
30
  if model == current_model:
31
  return
32
  inference_model = InferenceModel(checkpoint_path, model)
33
  current_model = model
 
 
34
 
35
  # Credits https://huggingface.co/spaces/rajesh1729/youtube-video-transcription-with-whisper
36
  def get_audio(url):
 
69
  synth = note_seq.midi_synth.fluidsynth
70
  array_of_floats = synth(est_ns, sample_rate=SAMPLE_RATE, sf2_path=SF2_PATH)
71
  int16_data = note_seq.audio_io.float_samples_to_int16(array_of_floats)
72
+ piano_roll = create_image_from_note_sequence(est_ns)
73
 
74
+ return "./transcribed.mid", (SAMPLE_RATE, int16_data), piano_roll
75
 
76
  title = "Transcribe music from YouTube videos using Transformers."
77
  description = """
 
107
  img = gr.Image(label="Thumbnail")
108
  with gr.Row():
109
  yt_audio = gr.Audio()
110
+ yt_audio_path = gr.Textbox(visible=False)
111
 
112
  link.change(fn=populate_metadata, inputs=link, outputs=[img, title, yt_audio, yt_audio_path])
113
 
 
117
  with gr.Row():
118
  midi_file = gr.File()
119
  midi_audio = gr.Audio()
120
+ with gr.Row():
121
+ piano_roll = gr.Image()
122
 
123
  btn.click(inference,
124
  inputs=yt_audio_path,
125
+ outputs=[midi_file, midi_audio, piano_roll])
126
 
127
  gr.Markdown(article)
128