Update app.py
Browse files
app.py
CHANGED
|
@@ -14,34 +14,34 @@ def hello():
|
|
| 14 |
def audio_separation():
|
| 15 |
try:
|
| 16 |
# 获取MP3文件的直链地址
|
| 17 |
-
|
| 18 |
-
|
| 19 |
return "Error: URL parameter is required", 400
|
| 20 |
|
| 21 |
# 下载MP3文件到本地
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
f.write(response.content)
|
| 26 |
|
| 27 |
-
|
| 28 |
separate.Predictor(output=Path("/tmp"), model_path=Path("./models/MDX_Net_Models/UVR-MDX-NET-Inst_HQ_3.onnx")).process_file(Path(mp3_filename))
|
| 29 |
-
|
| 30 |
|
| 31 |
# 生成分离后的文件名
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
# 提供文件的永久直链
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
# 返回结果
|
| 40 |
-
|
| 41 |
"vocals_url": vocals_url,
|
| 42 |
"no_vocals_url": no_vocals_url
|
| 43 |
}
|
| 44 |
-
|
| 45 |
except Exception as e:
|
| 46 |
return "Error: " + str(e), 500
|
| 47 |
|
|
@@ -50,4 +50,4 @@ def download(filename):
|
|
| 50 |
return send_file("/tmp/" + filename, as_attachment=True)
|
| 51 |
|
| 52 |
if __name__ == '__main__':
|
| 53 |
-
app.run(debug=False)
|
|
|
|
| 14 |
def audio_separation():
|
| 15 |
try:
|
| 16 |
# 获取MP3文件的直链地址
|
| 17 |
+
mp3_url = request.args.get('url')
|
| 18 |
+
if not mp3_url:
|
| 19 |
return "Error: URL parameter is required", 400
|
| 20 |
|
| 21 |
# 下载MP3文件到本地
|
| 22 |
+
response = requests.get(mp3_url)
|
| 23 |
+
mp3_filename = mp3_url.split('/')[-1] # 使用下载的文件名
|
| 24 |
+
with open("/tmp/" + mp3_filename, 'wb') as f:
|
| 25 |
f.write(response.content)
|
| 26 |
|
| 27 |
+
# 执行音频分离操作
|
| 28 |
separate.Predictor(output=Path("/tmp"), model_path=Path("./models/MDX_Net_Models/UVR-MDX-NET-Inst_HQ_3.onnx")).process_file(Path(mp3_filename))
|
| 29 |
+
subprocess.run(['python', 'separate.py', '/tmp/' + mp3_filename, '-o', '/tmp', '-m', './models/MDX_Net_Models/UVR-MDX-NET-Inst_HQ_3.onnx'])
|
| 30 |
|
| 31 |
# 生成分离后的文件名
|
| 32 |
+
vocals_filename = f"{os.path.splitext(mp3_filename)[0]}_vocals.wav"
|
| 33 |
+
no_vocals_filename = f"{os.path.splitext(mp3_filename)[0]}_no_vocals.wav"
|
| 34 |
|
| 35 |
# 提供文件的永久直链
|
| 36 |
+
vocals_url = f"/download/{os.path.basename(vocals_filename)}"
|
| 37 |
+
no_vocals_url = f"/download/{os.path.basename(no_vocals_filename)}"
|
| 38 |
|
| 39 |
# 返回结果
|
| 40 |
+
result = {
|
| 41 |
"vocals_url": vocals_url,
|
| 42 |
"no_vocals_url": no_vocals_url
|
| 43 |
}
|
| 44 |
+
return result
|
| 45 |
except Exception as e:
|
| 46 |
return "Error: " + str(e), 500
|
| 47 |
|
|
|
|
| 50 |
return send_file("/tmp/" + filename, as_attachment=True)
|
| 51 |
|
| 52 |
if __name__ == '__main__':
|
| 53 |
+
app.run(debug=False)
|