Spaces:
Sleeping
Sleeping
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 | |
def index(): | |
return render_template('index.html') | |
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) | |