admin commited on
Commit
9b709d7
·
1 Parent(s): 288d286
Files changed (2) hide show
  1. app.py +1 -14
  2. requirements.txt +4 -3
app.py CHANGED
@@ -30,8 +30,6 @@ def download_audio(url: str, save_path: str):
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):
37
  try:
@@ -43,18 +41,13 @@ def is_url(s: str):
43
 
44
 
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
 
@@ -76,7 +69,6 @@ def get_1st_int(input_string: str):
76
  match = re.search(r"\d+", input_string)
77
  if match:
78
  return str(int(match.group()))
79
-
80
  else:
81
  return ""
82
 
@@ -121,15 +113,10 @@ def url_infer(song: str, cache_dir="./__pycache__/mode2"):
121
  if song_name:
122
  title = song_name
123
 
124
- print("audio2midi OK")
125
  xml = midi2xml(midi, title)
126
- print("midi2xml OK")
127
  abc = xml2abc(xml)
128
- print("xml2abc OK")
129
  mxl = xml2mxl(xml)
130
- print("xml2mxl OK")
131
  pdf, jpg = xml2jpg(xml)
132
- print("xml2jpg OK")
133
  return audio_path, midi, pdf, xml, mxl, abc, jpg
134
 
135
  except Exception as e:
 
30
  for chunk in response.iter_content(chunk_size=8192):
31
  file.write(chunk)
32
 
 
 
33
 
34
  def is_url(s: str):
35
  try:
 
41
 
42
 
43
  def audio2midi(audio_path: str, cache_dir: str):
44
+ audio, _ = load_audio(audio_path, sr=sample_rate)
 
 
45
  transcriptor = PianoTranscription(
46
  device="cuda" if torch.cuda.is_available() else "cpu",
47
  checkpoint_path=WEIGHTS_PATH,
48
  )
 
49
  midi_path = f"{cache_dir}/output.mid"
 
50
  transcriptor.transcribe(audio, midi_path)
 
51
  return midi_path, os.path.basename(audio_path).split(".")[-2].capitalize()
52
 
53
 
 
69
  match = re.search(r"\d+", input_string)
70
  if match:
71
  return str(int(match.group()))
 
72
  else:
73
  return ""
74
 
 
113
  if song_name:
114
  title = song_name
115
 
 
116
  xml = midi2xml(midi, title)
 
117
  abc = xml2abc(xml)
 
118
  mxl = xml2mxl(xml)
 
119
  pdf, jpg = xml2jpg(xml)
 
120
  return audio_path, midi, pdf, xml, mxl, abc, jpg
121
 
122
  except Exception as e:
requirements.txt CHANGED
@@ -1,6 +1,7 @@
1
- torch
2
  pymupdf
3
  music21
4
  piano_transcription_inference
5
- modelscope[framework]==1.18
6
- librosa==0.9.2
 
 
 
 
1
  pymupdf
2
  music21
3
  piano_transcription_inference
4
+ modelscope==1.15
5
+ librosa==0.9.2
6
+ torch==1.12.1
7
+ numpy==1.26.4