Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import os
|
|
| 2 |
import torch
|
| 3 |
import shutil
|
| 4 |
import gradio as gr
|
| 5 |
-
import traceback
|
| 6 |
from mutagen.mp3 import MP3
|
| 7 |
from mutagen.flac import FLAC
|
| 8 |
from piano_transcription_inference import PianoTranscription, load_audio, sample_rate
|
|
@@ -58,6 +57,7 @@ def extract_meta(audio_path: str):
|
|
| 58 |
raise ValueError("文件路径为空!")
|
| 59 |
|
| 60 |
artist = None
|
|
|
|
| 61 |
name, ext = os.path.splitext(os.path.basename(audio_path))
|
| 62 |
ext == ext.lower()
|
| 63 |
if ext == ".mp3":
|
|
@@ -80,16 +80,14 @@ def extract_meta(audio_path: str):
|
|
| 80 |
|
| 81 |
if not title:
|
| 82 |
title = name.strip().capitalize()
|
|
|
|
|
|
|
| 83 |
|
| 84 |
return title, artist
|
| 85 |
|
| 86 |
|
| 87 |
def audio2midi(audio_path: str, cache_dir: str):
|
| 88 |
title, artist = extract_meta(audio_path)
|
| 89 |
-
if not title:
|
| 90 |
-
title = "Unknown title"
|
| 91 |
-
if not artist:
|
| 92 |
-
artist = "Unknown artist"
|
| 93 |
audio, _ = load_audio(audio_path, sr=sample_rate, mono=True)
|
| 94 |
transcriptor = PianoTranscription(
|
| 95 |
device="cuda" if torch.cuda.is_available() else "cpu",
|
|
@@ -112,8 +110,7 @@ def upl_infer(audio_path: str, cache_dir=f"{TMP_DIR}/cache"):
|
|
| 112 |
pdf, jpg = xml2jpg(xml)
|
| 113 |
|
| 114 |
except Exception as e:
|
| 115 |
-
|
| 116 |
-
status = f"{tb} (audio_path = {audio_path}, cache_dir={cache_dir})"
|
| 117 |
|
| 118 |
return status, midi, pdf, xml, mxl, abc, jpg
|
| 119 |
|
|
|
|
| 2 |
import torch
|
| 3 |
import shutil
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
from mutagen.mp3 import MP3
|
| 6 |
from mutagen.flac import FLAC
|
| 7 |
from piano_transcription_inference import PianoTranscription, load_audio, sample_rate
|
|
|
|
| 57 |
raise ValueError("文件路径为空!")
|
| 58 |
|
| 59 |
artist = None
|
| 60 |
+
title = None
|
| 61 |
name, ext = os.path.splitext(os.path.basename(audio_path))
|
| 62 |
ext == ext.lower()
|
| 63 |
if ext == ".mp3":
|
|
|
|
| 80 |
|
| 81 |
if not title:
|
| 82 |
title = name.strip().capitalize()
|
| 83 |
+
if not artist:
|
| 84 |
+
artist = "Unknown artist"
|
| 85 |
|
| 86 |
return title, artist
|
| 87 |
|
| 88 |
|
| 89 |
def audio2midi(audio_path: str, cache_dir: str):
|
| 90 |
title, artist = extract_meta(audio_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
audio, _ = load_audio(audio_path, sr=sample_rate, mono=True)
|
| 92 |
transcriptor = PianoTranscription(
|
| 93 |
device="cuda" if torch.cuda.is_available() else "cpu",
|
|
|
|
| 110 |
pdf, jpg = xml2jpg(xml)
|
| 111 |
|
| 112 |
except Exception as e:
|
| 113 |
+
status = f"{e}"
|
|
|
|
| 114 |
|
| 115 |
return status, midi, pdf, xml, mxl, abc, jpg
|
| 116 |
|