Spaces:
Build error
Build error
| from flask import Flask, request, render_template | |
| from emotion_detection import detect_emotion | |
| from music_recommender import get_music_recommendations | |
| import csv | |
| import os | |
| from datetime import datetime | |
| # Initialize Flask app | |
| app = Flask(__name__) | |
| UPLOAD_FOLDER = 'static/uploads/' | |
| os.makedirs(UPLOAD_FOLDER, exist_ok=True) | |
| def home(): | |
| return render_template('index.html') | |
| def recommend(): | |
| # Get emotion from image | |
| if len(request.files) > 0: | |
| if 'file' in request.files: | |
| file = request.files['file'] | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| filename = f"uploaded_image_{timestamp}.jpg" | |
| file.save("uploaded_image.jpg") | |
| file.save(os.path.join(UPLOAD_FOLDER, filename)) | |
| emotion = detect_emotion("uploaded_image.jpg") | |
| else: | |
| emotion = request.form['emotion'] | |
| # Get music recommendations | |
| songs = get_music_recommendations(emotion) | |
| # Log the request | |
| return render_template('results.html', emotion=emotion, songs=songs) | |
| def about(): | |
| return render_template('about.html') | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860))) | |