Skip to content

Commit

Permalink
Updated utils.py to support latest ChatbotAI
Browse files Browse the repository at this point in the history
  • Loading branch information
PratikSavla authored Jan 3, 2021
1 parent bcc5c5f commit 9625a38
Showing 1 changed file with 9 additions and 87 deletions.
96 changes: 9 additions & 87 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

# In[1]:


from chatbot import Chat,reflections,multiFunctionCall
#from chatbot import Chat,reflections,multiFunctionCall
from chatbot import Chat,register_call
import wikipedia
import os

Expand All @@ -15,7 +15,7 @@

# In[2]:


@register_call("whoIs")
def whoIs(query,sessionID="general"):
try:
return wikipedia.summary(query)
Expand All @@ -38,7 +38,7 @@ def whoIs(query,sessionID="general"):
import cv2
from keras.models import load_model
import numpy as np
import playsound
# import playsound
# parameters for loading data and images
detection_model_path = 'Emotion/haarcascade_files/haarcascade_frontalface_default.xml'
emotion_model_path = 'Emotion/models/_mini_XCEPTION.102-0.66.hdf5'
Expand All @@ -50,6 +50,7 @@ def whoIs(query,sessionID="general"):
EMOTIONS = ["angry" ,"disgust","scared", "happy", "sad", "surprised",
"neutral"]

@register_call("emo")
def emo(query,sessionID="general"):
cv2.namedWindow('your_face')
camera = cv2.VideoCapture(0)
Expand Down Expand Up @@ -92,87 +93,7 @@ def emo(query,sessionID="general"):
return "I cannot see your face."


# # Face Identification Connection

# In[4]:

import cv2
import matplotlib.pyplot as plt
from IPython import display

import face_recognition
import glob
users = glob.glob("Users\*.jpg")
# Load a sample picture and learn how to recognize it.
known_face_encodings = []
known_face_names = []

for user in users:
user_image = face_recognition.load_image_file(user)
known_face_encodings.append(face_recognition.face_encodings(user_image)[0])
known_face_names.append(user.split("\\")[1].split(".")[0])
print(known_face_names)


# In[5]:


import face_recognition

def identifyu(query=0,sessionID="general"):
video_capture = cv2.VideoCapture(0)

# Load a sample picture and learn how to recognize it.


# while True:
# Grab a single frame of video
ret, frame = video_capture.read()

# Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_frame = frame[:, :, ::-1]

# Find all the faces and face enqcodings in the frame of video
face_locations = face_recognition.face_locations(rgb_frame)
face_encodings = face_recognition.face_encodings(rgb_frame, face_locations)
name = "Unknown"
# Loop through each face in this frame of video
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
# See if the face is a match for the known face(s)
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)

name = "Unknown"

# If a match was found in known_face_encodings, just use the first one.
if True in matches:
first_match_index = matches.index(True)
name = known_face_names[first_match_index]

# Draw a box around the face
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

# Draw a label with a name below the face
cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
#webcam_preview = plt.imshow(frame)

# # Hit 'q' on the keyboard to quit!
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
# break

# Release handle to the webcam
video_capture.release()
cv2.destroyAllWindows()
return name


# # User Can make bot learn

# In[50]:


@register_call("learnq")
def learnq(query,sessionID="general"):
print(query)
try:
Expand All @@ -184,6 +105,8 @@ def learnq(query,sessionID="general"):
except:
pass
return "write the question again"

@register_call("learna")
def learna(query,sessionID="general"):
print(query)
try:
Expand Down Expand Up @@ -226,7 +149,7 @@ def decryp(filename):

# In[40]:


@register_call("whathappen")
def whathappen(query,sessionID="general"):
aa = query
nam = identifyu()
Expand All @@ -242,4 +165,3 @@ def sas(sentence):
return "sad"

from datetime import datetime

0 comments on commit 9625a38

Please sign in to comment.