forked from Atharva-D/Moodify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
134 lines (101 loc) · 3.98 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from __future__ import division, print_function
#import sys
import os
import cv2
#import re
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from flask import Flask, request, render_template
from werkzeug.utils import secure_filename
import statistics as st
app = Flask(__name__)
@app.route("/")
def home():
return render_template("index1.html")
@app.route('/camera', methods = ['GET', 'POST'])
def camera():
i=0
GR_dict={0:(0,255,0),1:(0,0,255)}
model = tf.keras.models.load_model('final_model.h5')
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
output=[]
cap = cv2.VideoCapture(0)
while (i<=30):
ret, img = cap.read()
faces = face_cascade.detectMultiScale(img,1.05,5)
for x,y,w,h in faces:
face_img = img[y:y+h,x:x+w]
resized = cv2.resize(face_img,(224,224))
reshaped=resized.reshape(1, 224,224,3)/255
predictions = model.predict(reshaped)
max_index = np.argmax(predictions[0])
emotions = ('angry', 'disgust', 'fear', 'happy', 'sad', 'neutral', 'surprise')
predicted_emotion = emotions[max_index]
output.append(predicted_emotion)
cv2.rectangle(img,(x,y),(x+w,y+h),GR_dict[1],2)
cv2.rectangle(img,(x,y-40),(x+w,y),GR_dict[1],-1)
cv2.putText(img, predicted_emotion, (x, y-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,255,255),2)
i = i+1
cv2.imshow('LIVE', img)
key = cv2.waitKey(1)
if key == 27:
cap.release()
cv2.destroyAllWindows()
break
print(output)
cap.release()
cv2.destroyAllWindows()
final_output1 = st.mode(output)
return render_template("buttons.html",final_output=final_output1)
@app.route('/templates/buttons', methods = ['GET','POST'])
def buttons():
return render_template("buttons.html")
@app.route('/movies/surprise', methods = ['GET', 'POST'])
def moviesSurprise():
return render_template("moviesSurprise.html")
@app.route('/movies/angry', methods = ['GET', 'POST'])
def moviesAngry():
return render_template("moviesAngry.html")
@app.route('/movies/sad', methods = ['GET', 'POST'])
def moviesSad():
return render_template("moviesSad.html")
@app.route('/movies/disgust', methods = ['GET', 'POST'])
def moviesDisgust():
return render_template("moviesDisgust.html")
@app.route('/movies/happy', methods = ['GET', 'POST'])
def moviesHappy():
return render_template("moviesHappy.html")
@app.route('/movies/fear', methods = ['GET', 'POST'])
def moviesFear():
return render_template("moviesFear.html")
@app.route('/movies/neutral', methods = ['GET', 'POST'])
def moviesNeutral():
return render_template("moviesNeutral.html")
@app.route('/songs/surprise', methods = ['GET', 'POST'])
def songsSurprise():
return render_template("songsSurprise.html")
@app.route('/songs/angry', methods = ['GET', 'POST'])
def songsAngry():
return render_template("songsAngry.html")
@app.route('/songs/sad', methods = ['GET', 'POST'])
def songsSad():
return render_template("songsSad.html")
@app.route('/songs/disgust', methods = ['GET', 'POST'])
def songsDisgust():
return render_template("songsDisgust.html")
@app.route('/songs/happy', methods = ['GET', 'POST'])
def songsHappy():
return render_template("songsHappy.html")
@app.route('/songs/fear', methods = ['GET', 'POST'])
def songsFear():
return render_template("songsFear.html")
@app.route('/songs/neutral', methods = ['GET', 'POST'])
def songsNeutral():
return render_template("songsSad.html")
@app.route('/templates/join_page', methods = ['GET', 'POST'])
def join():
return render_template("join_page.html")
if __name__ == "__main__":
app.run(debug=True)