Spaces:
Build error
Build error
Shivam Prasad commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,46 @@
|
|
| 1 |
-
from flask import Flask,
|
| 2 |
-
import os
|
| 3 |
from emotion_detection import detect_emotion
|
| 4 |
from music_recommender import get_music_recommendations
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
@app.route('/')
|
| 9 |
-
def
|
| 10 |
return render_template('index.html')
|
| 11 |
|
| 12 |
@app.route('/recommend', methods=['POST'])
|
| 13 |
def recommend():
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
else:
|
| 20 |
-
emotion = request.form
|
| 21 |
|
|
|
|
| 22 |
songs = get_music_recommendations(emotion)
|
|
|
|
|
|
|
|
|
|
| 23 |
return render_template('results.html', emotion=emotion, songs=songs)
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
if __name__ == '__main__':
|
| 26 |
-
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template
|
|
|
|
| 2 |
from emotion_detection import detect_emotion
|
| 3 |
from music_recommender import get_music_recommendations
|
| 4 |
+
import csv
|
| 5 |
+
import os
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
# Initialize Flask app
|
| 8 |
+
app = Flask(__name__)
|
| 9 |
+
|
| 10 |
+
UPLOAD_FOLDER = 'static/uploads/'
|
| 11 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
| 12 |
|
| 13 |
@app.route('/')
|
| 14 |
+
def home():
|
| 15 |
return render_template('index.html')
|
| 16 |
|
| 17 |
@app.route('/recommend', methods=['POST'])
|
| 18 |
def recommend():
|
| 19 |
+
# Get emotion from image
|
| 20 |
+
if len(request.files) > 0:
|
| 21 |
+
if 'file' in request.files:
|
| 22 |
+
file = request.files['file']
|
| 23 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 24 |
+
filename = f"uploaded_image_{timestamp}.jpg"
|
| 25 |
+
|
| 26 |
+
file.save("uploaded_image.jpg")
|
| 27 |
+
file.save(os.path.join(UPLOAD_FOLDER, filename))
|
| 28 |
+
emotion = detect_emotion("uploaded_image.jpg")
|
| 29 |
else:
|
| 30 |
+
emotion = request.form['emotion']
|
| 31 |
|
| 32 |
+
# Get music recommendations
|
| 33 |
songs = get_music_recommendations(emotion)
|
| 34 |
+
|
| 35 |
+
# Log the request
|
| 36 |
+
|
| 37 |
return render_template('results.html', emotion=emotion, songs=songs)
|
| 38 |
|
| 39 |
+
@app.route('/about')
|
| 40 |
+
def about():
|
| 41 |
+
return render_template('about.html')
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
if __name__ == '__main__':
|
| 46 |
+
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|