forked from aakzsh/moodifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
63 lines (48 loc) · 1.78 KB
/
app.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from flask import Flask, render_template, request
import cv2
import numpy as np
from keras.models import load_model
import os
UPLOAD_FOLDER = 'uploadFile'
app = Flask(__name__)
app.config["DEBUG"] = True
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload', methods=['GET', 'POST'])
def after():
if request.method == 'POST':
if 'file' not in request.files:
return print('Nothing to see homie')
file = request.files['file']
file.filename = "file"
path = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
file.save(path)
print('file uploaded')
image = cv2.imread('uploadFile/file', 0)
image = cv2.resize(image, (48, 48))
image = np.reshape(image, (1, 48, 48, 1))
model = load_model('model.h5')
prediction = model.predict(image)
label_map = ['Angry', 'Neutral', 'Scared', 'Happy', 'Sad', 'Surprised']
prediction = np.argmax(prediction)
print(f"{prediction} this is your prediction")
os.remove('uploadFile/file')
final_prediction = label_map[prediction]
if (final_prediction == 'Angry'):
return render_template('anger.html')
elif (final_prediction == 'Neutral'):
return render_template('neutral.html')
elif (final_prediction == 'Scared'):
return render_template('fear.html')
elif (final_prediction == 'Happy'):
return render_template('happiness.html')
elif (final_prediction == 'Sad'):
return render_template('sadness.html')
elif (final_prediction == 'Surprised'):
return print('there is nothing for you here')
return render_template('after.html', data=final_prediction)
#should be working
if __name__ == "__main__":
app.run(debug=True)