|
from flask import Flask, request, send_file |
|
import os |
|
import requests |
|
import subprocess |
|
|
|
app = Flask(__name__) |
|
|
|
@app.route('/', methods=['GET']) |
|
def hello(): |
|
return "Hello! This is an api server, and it is running successfully. For usage, please contact the person who hosted this api server." |
|
|
|
@app.route('/api/audio_separation', methods=['GET']) |
|
def audio_separation(): |
|
|
|
mp3_url = request.args.get('url') |
|
if not mp3_url: |
|
return "Error: URL parameter is required", 400 |
|
|
|
|
|
response = requests.get(mp3_url) |
|
mp3_filename = mp3_url.split('/')[-1] |
|
with open("/tmp/" + mp3_filename, 'wb') as f: |
|
f.write(response.content) |
|
|
|
|
|
subprocess.run(['python', 'separate.py', '/tmp/' + mp3_filename, '-o', '/tmp', '-m', './models/MDX_Net_Models/UVR-MDX-NET-Inst_HQ_3.onnx']) |
|
|
|
|
|
vocals_filename = f"{os.path.splitext(mp3_filename)[0]}_vocals.wav" |
|
no_vocals_filename = f"{os.path.splitext(mp3_filename)[0]}_no_vocals.wav" |
|
|
|
|
|
vocals_url = f"/download/{os.path.basename(vocals_filename)}" |
|
no_vocals_url = f"/download/{os.path.basename(no_vocals_filename)}" |
|
|
|
|
|
result = { |
|
"vocals_url": vocals_url, |
|
"no_vocals_url": no_vocals_url |
|
} |
|
return result |
|
|
|
@app.route('/download/<filename>', methods=['GET']) |
|
def download(filename): |
|
return send_file("/tmp/" + filename, as_attachment=True) |
|
|
|
if __name__ == '__main__': |
|
app.run(debug=False) |
|
|