admin commited on
Commit
288d286
·
1 Parent(s): e9738fb

add print more

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -5,7 +5,6 @@ import torch
5
  import shutil
6
  import requests
7
  import gradio as gr
8
- from tqdm import tqdm
9
  from piano_transcription_inference import PianoTranscription, load_audio, sample_rate
10
  from modelscope import snapshot_download
11
  from urllib.parse import urlparse
@@ -31,7 +30,7 @@ def download_audio(url: str, save_path: str):
31
  for chunk in response.iter_content(chunk_size=8192):
32
  file.write(chunk)
33
 
34
- return os.path.abspath(save_path)
35
 
36
 
37
  def is_url(s: str):
@@ -46,15 +45,16 @@ def is_url(s: str):
46
  def audio2midi(audio_path: str, cache_dir: str):
47
  # Load audio
48
  audio, _ = load_audio(audio_path, sr=sample_rate, mono=True)
49
- # Transcriptor
50
  transcriptor = PianoTranscription(
51
  device="cuda" if torch.cuda.is_available() else "cpu",
52
  checkpoint_path=WEIGHTS_PATH,
53
  )
54
- # device: 'cuda' | 'cpu' Transcribe and write out to MIDI file
55
  midi_path = f"{cache_dir}/output.mid"
56
  # midi_path = audio_path.replace(audio_path.split(".")[-1], "mid")
57
  transcriptor.transcribe(audio, midi_path)
 
58
  return midi_path, os.path.basename(audio_path).split(".")[-2].capitalize()
59
 
60
 
@@ -115,7 +115,7 @@ def url_infer(song: str, cache_dir="./__pycache__/mode2"):
115
  if not free:
116
  raise AttributeError("Unable to parse VIP songs")
117
 
118
- audio_path = download_audio(song_url, audio_path)
119
 
120
  midi, title = audio2midi(audio_path, cache_dir)
121
  if song_name:
 
5
  import shutil
6
  import requests
7
  import gradio as gr
 
8
  from piano_transcription_inference import PianoTranscription, load_audio, sample_rate
9
  from modelscope import snapshot_download
10
  from urllib.parse import urlparse
 
30
  for chunk in response.iter_content(chunk_size=8192):
31
  file.write(chunk)
32
 
33
+ print(f"{url} has been downloded to {save_path}")
34
 
35
 
36
  def is_url(s: str):
 
45
  def audio2midi(audio_path: str, cache_dir: str):
46
  # Load audio
47
  audio, _ = load_audio(audio_path, sr=sample_rate, mono=True)
48
+ print("load_audio OK")
49
  transcriptor = PianoTranscription(
50
  device="cuda" if torch.cuda.is_available() else "cpu",
51
  checkpoint_path=WEIGHTS_PATH,
52
  )
53
+ print("PianoTranscription OK")
54
  midi_path = f"{cache_dir}/output.mid"
55
  # midi_path = audio_path.replace(audio_path.split(".")[-1], "mid")
56
  transcriptor.transcribe(audio, midi_path)
57
+ print("transcribe OK")
58
  return midi_path, os.path.basename(audio_path).split(".")[-2].capitalize()
59
 
60
 
 
115
  if not free:
116
  raise AttributeError("Unable to parse VIP songs")
117
 
118
+ download_audio(song_url, audio_path)
119
 
120
  midi, title = audio2midi(audio_path, cache_dir)
121
  if song_name: