Spaces:
Sleeping
Sleeping
File size: 1,152 Bytes
93e79dc 8cfb35c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import os
# Set up the folder where audio files will be saved
UPLOAD_FOLDER = 'uploads/'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Allowed file extensions
ALLOWED_EXTENSIONS = {'wav', 'mp3', 'ogg'}
# Check if the file is allowed
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload', methods=['POST'])
def upload_audio():
if 'file' not in request.files:
return jsonify({"message": "No file part"}), 400
file = request.files['file']
if file.filename == '':
return jsonify({"message": "No selected file"}), 400
if file and allowed_file(file.filename):
filename = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(filename)
return jsonify({"message": "File uploaded successfully", "filename": file.filename}), 200
else:
return jsonify({"message": "Invalid file type. Only WAV, MP3, and OGG are allowed."}), 400
if __name__ == "__main__":
app.run(debug=True)
|