# load json and create model
from __future__ import division
from keras.models import Sequential
from keras.layers import Dense
from keras.models import model_from_json
import os
import numpy as np
import cv2


#loading the model
json_file = open('fer.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("fer.h5")
print("Loaded model from disk")

#setting image resizing parameters
WIDTH = 48
HEIGHT = 48
x=None
y=None
labels = ['Angry', 'Sad', 'Fear', 'Joy', 'Sad', 'Surprised/Happy', 'Neutral']

#loading image
full_size_image = cv2.imread("test.jpeg")
print("Image Loaded")
gray=cv2.cvtColor(full_size_image,cv2.COLOR_RGB2GRAY)
face = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
faces = face.detectMultiScale(gray, 1.3  , 10)

#detecting faces
for (x, y, w, h) in faces:
        roi_gray = gray[y:y + h, x:x + w]
        cropped_img = np.expand_dims(np.expand_dims(cv2.resize(roi_gray, (48, 48)), -1), 0)
        cv2.normalize(cropped_img, cropped_img, alpha=0, beta=1, norm_type=cv2.NORM_L2, dtype=cv2.CV_32F)
        cv2.rectangle(full_size_image, (x, y), (x + w, y + h), (0, 255, 0), 1)
        #predicting the emotion
        yhat= loaded_model.predict(cropped_img)
        cv2.putText(full_size_image, labels[int(np.argmax(yhat))], (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 1, cv2.LINE_AA)
        print("Emotion: "+labels[int(np.argmax(yhat))])


choice=input("Do you want to listen Something:")
if choice=='Y' or choice=='y':
    import googlesearch
    released = {
        "Sad" : 'sad songs youtube',
        "Joy" : 'rock music youtube',
        "Angry" : 'angry mood songs youtube',
        "Surprised/Happy" : 'EDM Songs',
        "Neutral" : 'evergreen songs youtube',
        "Fear" : 'hanuman chalisa youtube',
        }
    #print (released)
    mymood = released.get(labels[int(np.argmax(yhat))], "none")
    mysonglist=[]
    for url in googlesearch.search_videos(mymood,stop=11):
        #url = url.replace("watch","embed")
        mysonglist.append(url)
    
    songnum = np.random.randint(1,10)
    song_name=mysonglist[songnum]
    # open Tab
    import webbrowser
    webbrowser.open(mysonglist[songnum])

elif choice=='N' or choice=='n':
    print("So you have chosen not too listen anything. So have a good Day Byee")

else:
    print("Wrong choice")

663ace09b542ffd480417552fd7a1a191a2bc71f
<mask token>

<mask token>
json_file.close()
<mask token>
loaded_model.load_weights('fer.h5')
print('Loaded model from disk')
<mask token>
print('Image Loaded')
<mask token>
for x, y, w, h in faces:
    roi_gray = gray[y:y + h, x:x + w]
    cropped_img = np.expand_dims(np.expand_dims(cv2.resize(roi_gray, (48, 
        48)), -1), 0)
    cv2.normalize(cropped_img, cropped_img, alpha=0, beta=1, norm_type=cv2.
        NORM_L2, dtype=cv2.CV_32F)
    cv2.rectangle(full_size_image, (x, y), (x + w, y + h), (0, 255, 0), 1)
    yhat = loaded_model.predict(cropped_img)
    cv2.putText(full_size_image, labels[int(np.argmax(yhat))], (x, y), cv2.
        FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 1, cv2.LINE_AA)
    print('Emotion: ' + labels[int(np.argmax(yhat))])
<mask token>
if choice == 'Y' or choice == 'y':
    import googlesearch
    released = {'Sad': 'sad songs youtube', 'Joy': 'rock music youtube',
        'Angry': 'angry mood songs youtube', 'Surprised/Happy': 'EDM Songs',
        'Neutral': 'evergreen songs youtube', 'Fear': 'hanuman chalisa youtube'
        }
    mymood = released.get(labels[int(np.argmax(yhat))], 'none')
    mysonglist = []
    for url in googlesearch.search_videos(mymood, stop=11):
        mysonglist.append(url)
    songnum = np.random.randint(1, 10)
    song_name = mysonglist[songnum]
    import webbrowser
    webbrowser.open(mysonglist[songnum])
elif choice == 'N' or choice == 'n':
    print('So you have chosen not too listen anything. So have a good Day Byee'
        )
else:
    print('Wrong choice')

<mask token>
json_file = open('fer.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
loaded_model.load_weights('fer.h5')
print('Loaded model from disk')
WIDTH = 48
HEIGHT = 48
x = None
y = None
labels = ['Angry', 'Sad', 'Fear', 'Joy', 'Sad', 'Surprised/Happy', 'Neutral']
full_size_image = cv2.imread('test.jpeg')
print('Image Loaded')
gray = cv2.cvtColor(full_size_image, cv2.COLOR_RGB2GRAY)
face = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
faces = face.detectMultiScale(gray, 1.3, 10)
for x, y, w, h in faces:
    roi_gray = gray[y:y + h, x:x + w]
    cropped_img = np.expand_dims(np.expand_dims(cv2.resize(roi_gray, (48, 
        48)), -1), 0)
    cv2.normalize(cropped_img, cropped_img, alpha=0, beta=1, norm_type=cv2.
        NORM_L2, dtype=cv2.CV_32F)
    cv2.rectangle(full_size_image, (x, y), (x + w, y + h), (0, 255, 0), 1)
    yhat = loaded_model.predict(cropped_img)
    cv2.putText(full_size_image, labels[int(np.argmax(yhat))], (x, y), cv2.
        FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 1, cv2.LINE_AA)
    print('Emotion: ' + labels[int(np.argmax(yhat))])
choice = input('Do you want to listen Something:')
if choice == 'Y' or choice == 'y':
    import googlesearch
    released = {'Sad': 'sad songs youtube', 'Joy': 'rock music youtube',
        'Angry': 'angry mood songs youtube', 'Surprised/Happy': 'EDM Songs',
        'Neutral': 'evergreen songs youtube', 'Fear': 'hanuman chalisa youtube'
        }
    mymood = released.get(labels[int(np.argmax(yhat))], 'none')
    mysonglist = []
    for url in googlesearch.search_videos(mymood, stop=11):
        mysonglist.append(url)
    songnum = np.random.randint(1, 10)
    song_name = mysonglist[songnum]
    import webbrowser
    webbrowser.open(mysonglist[songnum])
elif choice == 'N' or choice == 'n':
    print('So you have chosen not too listen anything. So have a good Day Byee'
        )
else:
    print('Wrong choice')

from __future__ import division
from keras.models import Sequential
from keras.layers import Dense
from keras.models import model_from_json
import os
import numpy as np
import cv2
json_file = open('fer.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
loaded_model.load_weights('fer.h5')
print('Loaded model from disk')
WIDTH = 48
HEIGHT = 48
x = None
y = None
labels = ['Angry', 'Sad', 'Fear', 'Joy', 'Sad', 'Surprised/Happy', 'Neutral']
full_size_image = cv2.imread('test.jpeg')
print('Image Loaded')
gray = cv2.cvtColor(full_size_image, cv2.COLOR_RGB2GRAY)
face = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
faces = face.detectMultiScale(gray, 1.3, 10)
for x, y, w, h in faces:
    roi_gray = gray[y:y + h, x:x + w]
    cropped_img = np.expand_dims(np.expand_dims(cv2.resize(roi_gray, (48, 
        48)), -1), 0)
    cv2.normalize(cropped_img, cropped_img, alpha=0, beta=1, norm_type=cv2.
        NORM_L2, dtype=cv2.CV_32F)
    cv2.rectangle(full_size_image, (x, y), (x + w, y + h), (0, 255, 0), 1)
    yhat = loaded_model.predict(cropped_img)
    cv2.putText(full_size_image, labels[int(np.argmax(yhat))], (x, y), cv2.
        FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 1, cv2.LINE_AA)
    print('Emotion: ' + labels[int(np.argmax(yhat))])
choice = input('Do you want to listen Something:')
if choice == 'Y' or choice == 'y':
    import googlesearch
    released = {'Sad': 'sad songs youtube', 'Joy': 'rock music youtube',
        'Angry': 'angry mood songs youtube', 'Surprised/Happy': 'EDM Songs',
        'Neutral': 'evergreen songs youtube', 'Fear': 'hanuman chalisa youtube'
        }
    mymood = released.get(labels[int(np.argmax(yhat))], 'none')
    mysonglist = []
    for url in googlesearch.search_videos(mymood, stop=11):
        mysonglist.append(url)
    songnum = np.random.randint(1, 10)
    song_name = mysonglist[songnum]
    import webbrowser
    webbrowser.open(mysonglist[songnum])
elif choice == 'N' or choice == 'n':
    print('So you have chosen not too listen anything. So have a good Day Byee'
        )
else:
    print('Wrong choice')

# load json and create model
from __future__ import division
from keras.models import Sequential
from keras.layers import Dense
from keras.models import model_from_json
import os
import numpy as np
import cv2


#loading the model
json_file = open('fer.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("fer.h5")
print("Loaded model from disk")

#setting image resizing parameters
WIDTH = 48
HEIGHT = 48
x=None
y=None
labels = ['Angry', 'Sad', 'Fear', 'Joy', 'Sad', 'Surprised/Happy', 'Neutral']

#loading image
full_size_image = cv2.imread("test.jpeg")
print("Image Loaded")
gray=cv2.cvtColor(full_size_image,cv2.COLOR_RGB2GRAY)
face = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
faces = face.detectMultiScale(gray, 1.3  , 10)

#detecting faces
for (x, y, w, h) in faces:
        roi_gray = gray[y:y + h, x:x + w]
        cropped_img = np.expand_dims(np.expand_dims(cv2.resize(roi_gray, (48, 48)), -1), 0)
        cv2.normalize(cropped_img, cropped_img, alpha=0, beta=1, norm_type=cv2.NORM_L2, dtype=cv2.CV_32F)
        cv2.rectangle(full_size_image, (x, y), (x + w, y + h), (0, 255, 0), 1)
        #predicting the emotion
        yhat= loaded_model.predict(cropped_img)
        cv2.putText(full_size_image, labels[int(np.argmax(yhat))], (x, y), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 1, cv2.LINE_AA)
        print("Emotion: "+labels[int(np.argmax(yhat))])


choice=input("Do you want to listen Something:")
if choice=='Y' or choice=='y':
    import googlesearch
    released = {
        "Sad" : 'sad songs youtube',
        "Joy" : 'rock music youtube',
        "Angry" : 'angry mood songs youtube',
        "Surprised/Happy" : 'EDM Songs',
        "Neutral" : 'evergreen songs youtube',
        "Fear" : 'hanuman chalisa youtube',
        }
    #print (released)
    mymood = released.get(labels[int(np.argmax(yhat))], "none")
    mysonglist=[]
    for url in googlesearch.search_videos(mymood,stop=11):
        #url = url.replace("watch","embed")
        mysonglist.append(url)
    
    songnum = np.random.randint(1,10)
    song_name=mysonglist[songnum]
    # open Tab
    import webbrowser
    webbrowser.open(mysonglist[songnum])

elif choice=='N' or choice=='n':
    print("So you have chosen not too listen anything. So have a good Day Byee")

else:
    print("Wrong choice")
