Commit db5902be authored by Dhananjaya Jayashanka's avatar Dhananjaya Jayashanka

expressions analyzing changers done

parent 4fcc4668
import moviepy.editor
video = moviepy.editor.VideoFileClip('speech.mp4')
audio = video.audio
audio.write_audiofile("sample.wav")
print("Completed the Separates !")
'afflicted': 'Sad',
'agonized': 'Sad',
'amused': 'Happy',
'angry': 'Angry',
'furious': 'Angry',
'irritated': 'Angry',
'upset': 'Angry',
'sore': 'Angry',
'disturbed': 'Angry',
'incensed': 'Angry',
'infuriated': 'Angry',
'wrathful': 'Angry',
'displeased': 'Angry',
'inflamed': 'Angry',
'outraged': 'Angry',
'ill-tempered': 'Angry',
'irritable': 'Angry',
'berserk': 'Angry',
'hateful': 'Angry',
'oppressed': 'Angry',
'anguished': 'Sad',
'animated': 'Happy',
'annoyed': 'Angry',
'appalled': 'Angry',
'beatific': 'Happy',
'bereaved': 'Sad',
'bitter': 'Angry',
'blissful': 'Happy',
'blithe': 'Happy',
'blue': 'Sad',
'boiling': 'Angry',
'bright': 'Happy',
'brisk': 'Happy',
'cheerful': 'Happy',
'cheerless': 'Sad',
'cheery': 'Happy',
'comfortable': 'Happy',
'contented': 'Happy',
'convivial': 'Happy',
'crestfallen': 'Sad',
'cross': 'Angry',
'crushed': 'Sad',
'dark': 'Sad',
'dejected': 'Sad',
'depressed': 'Sad',
'despondent': 'Sad',
'disconsolate': 'Sad',
'discontented': 'Sad',
'disgusted': 'Angry',
'dismal': 'Sad',
'displeased': 'Sad',
'distressed': 'Sad',
'dolorous': 'Sad',
'down': 'Sad',
'downhearted': 'Sad',
'dreadful': 'Sad',
'dreary': 'Sad',
'dull': 'Sad',
'ecstatic': 'Happy',
'elated': 'Happy',
'enraged': 'Angry',
'enthusiastic': 'Happy',
'excited': 'Happy',
'exhilarated': 'Happy',
'festive': 'Happy',
'flat': 'Sad',
'focused': 'Focused',
'free & easy': 'Happy',
'frisky': 'Happy',
'frustrated': 'Angry',
'fuming': 'Angry',
'funereal': 'Sad',
'furious': 'Angry',
'genial': 'Happy',
'glad': 'Happy',
'gleeful': 'Happy',
'gloomy': 'Sad',
'glum': 'Sad',
'grief-stricken': 'Sad',
'grieved': 'Sad',
'guilt': 'Sad',
'happy': 'Happy',
'heartbroken': 'Sad',
'heavyhearted': 'Sad',
'high-spirited': 'Happy',
'hilarious': 'Happy',
'humiliated': 'Sad',
'humorous': 'Happy',
'hurt': 'Sad',
'ill at ease': 'Sad',
'important': 'Happy',
'in a huff': 'Angry',
'in a stew': 'Angry',
'in pain': 'Sad',
'in the dumps': 'Sad',
'incensed': 'Angry',
'indignant': 'Angry',
'inflamed': 'Angry',
'injured': 'Sad',
'irate': 'Angry',
'irritated': 'Angry',
'jaunty': 'Happy',
'jocular': 'Happy',
'jolly': 'Happy',
'jovial': 'Happy',
'joyful': 'Happy',
'joyless': 'Sad',
'joyous': 'Happy',
'jubilant': 'Happy',
'lighthearted': 'Happy',
'lively': 'Happy',
'livid': 'Angry',
'low': 'Sad',
'lucky': 'Happy',
'lugubrious': 'Sad',
'mad': 'Angry',
'melancholy': 'Sad',
'merry': 'Happy',
'mirthful': 'Happy',
'moody': 'Sad',
'moping': 'Sad',
'mournful': 'Sad',
'offended': 'Angry',
'oppressed': 'Sad',
'out of sorts': 'Sad',
'outraged': 'Angry',
'overjoyed': 'Happy',
'pathetic': 'Sad',
'playful': 'Happy',
'pleased': 'Happy',
'proud': 'Happy',
'provoked': 'Angry',
'rageful': 'Angry',
'rapturous': 'Happy',
'regretful': 'Sad',
'remorse': 'Sad',
'resentful': 'Angry',
'rueful': 'Sad',
'sad': 'Sad',
'satisfied': 'Happy',
'saucy': 'Happy',
'serene': 'Happy',
'shamed': 'Sad',
'somber': 'Sad',
'sparkling': 'Happy',
'spirited': 'Happy',
'spiritless': 'Sad',
'sprightly': 'Happy',
'suffering': 'Sad',
'sulky': 'Sad',
'sullen': 'Angry',
'sunny': 'Happy',
'thankful': 'Happy',
'tortured': 'Sad',
'tragic': 'Sad',
'tranquil': 'Happy',
'transported': 'Happy',
'up in arms': 'Angry',
'victimized': 'Sad',
'virulent': 'Angry',
'vivacious': 'Happy',
'woebegone': 'Sad',
'woeful': 'Sad',
'wrathful': 'Angry',
'wrought up': 'Angry',
'aching': 'Sad',
'acrimonious': 'Angry',
'airy': 'Happy',
'buoyant': 'Happy',
'clouded': 'Sad',
'debonair': 'Happy',
'despairing': 'Sad',
'devastated': 'Angry',
'disheartened': 'Sad',
'downcast': 'Sad',
'exultant': 'Happy',
'frowning': 'Sad',
'great': 'Happy',
'hapless': 'Sad',
'hated': 'Hated',
'hostile': 'Angry',
'in despair': 'Sad',
'infuriated': 'Angry',
'inspired': 'Happy',
'laughting': 'Happy',
'low': 'Sad',
'mumpish': 'Sad',
'peaceful': 'Happy',
'piqued': 'Angry',
'piteous': 'Sad',
'self-satisfied': 'Happy',
'sorrowful': 'Sad',
'spirited': 'Sad',
'terrific': 'Happy',
'unhappy': 'Sad',
'worked up': 'Angry'
\ No newline at end of file
import string
from collections import Counter
def textAnalyze(speech):
text = speech
# converting to lowercase
lower_case = text.lower()
# Removing punctuations of the full text
cleaned_text = lower_case.translate(str.maketrans('', '', string.punctuation))
# splitting text into words
tokenized_words = cleaned_text.split()
stop_words = ["i", "me", "my", "myself", "we", "our", "ours", "ourselves", "you", "your", "yours", "yourself",
"yourselves", "he", "him", "his", "himself", "she", "her", "hers", "herself", "it", "its", "itself",
"they", "them", "their", "theirs", "themselves", "what", "which", "who", "whom", "this", "that",
"these",
"those", "am", "is", "are", "was", "were", "be", "been", "being", "have", "has", "had", "having",
"do",
"does", "did", "doing", "a", "an", "the", "and", "but", "if", "or", "because", "as", "until", "while",
"of", "at", "by", "for", "with", "about", "against", "between", "into", "through", "during", "before",
"after", "above", "below", "to", "from", "up", "down", "in", "out", "on", "off", "over", "under",
"again",
"further", "then", "once", "here", "there", "when", "where", "why", "how", "all", "any", "both",
"each",
"few", "more", "most", "other", "some", "such", "no", "nor", "not", "only", "own", "same", "so",
"than",
"too", "very", "s", "t", "can", "will", "just", "don", "should", "now"]
# Removing stop words from the tokenized words list
final_words = []
for word in tokenized_words:
if word not in stop_words:
final_words.append(word)
emotion_list = []
for i in final_words:
with open('Emotion/emotions.txt', 'r') as file:
for line in file:
clear_line = line.replace("\n", '').replace(",", '').replace("'", '').strip()
word, emotion = clear_line.split(':')
if i in word:
final_emotions = emotion.replace("", '').strip()
emotion_list.append(final_emotions)
print(emotion_list)
w = emotion_list
print(w)
return {
"message": w
}
# from skimage import io
import cv2
import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from keras.preprocessing import image
Savedmodel = tf.keras.models.load_model('emotion_lts.h5')
Savedmodel.summary()
objects = ('Angry', 'Happy', 'Sad', 'Neutral')
vid = cv2.VideoCapture(0)
#
# def run():
# while True:
#
# _, frame = vid.read()
# frame = imutils.resize(frame, width=500)
#
# # result = api(frame)
#
# cv2.imshow("frame",frame)
# # getPrediction(frame)
#
# # cv.waitKey(0)
# if cv2.waitKey(20) & 0XFF == ord('q'):
# break
#
# vid.release()
# cv2.destroyAllWindows()
def emotion_analysis(emotions):
objects = ['Angry', 'Happy', 'Sad', 'Neutral']
y_pos = np.arange(len(objects))
plt.bar(y_pos, emotions, align='center', alpha=0.9)
plt.tick_params(axis='x', which='both', pad=10, width=4, length=10)
plt.xticks(y_pos, objects)
plt.ylabel('percentage')
plt.title('emotion')
def getEmotions(filePath):
cap = cv2.VideoCapture(filePath)
emotions = []
while (cap.isOpened()):
try:
ret, frame = cap.read()
# img = image.load_img(frame,grayscale=True, target_size=(48, 48))
frame = cv2.resize(frame, (48, 48))
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
x = image.img_to_array(frame)
x = np.expand_dims(x, axis=0)
x /= 255
custom = Savedmodel.predict(x)
# print(custom[0])
emotion_analysis(custom[0])
x = np.array(x, 'float32')
x = x.reshape([48, 48]);
m = 0.000000000000000000001
a = custom[0]
for i in range(0, len(a)):
if a[i] > m:
m = a[i]
ind = i
print('Expression Prediction:', objects[ind])
emotions.append(objects[ind])
if cv2.waitKey(20) & 0XFF == ord('q'):
break
except:
print("Damaged frame")
break
return emotions
getEmotions("speech.mp4")
cv2.destroyAllWindows()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment