RajaThor commited on
Commit
b7759d5
·
verified ·
1 Parent(s): c073564

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -7,6 +7,7 @@ from PIL import Image
7
  import numpy as np
8
  import cv2
9
  import dlib
 
10
 
11
  # Get the current working directory
12
  current_directory = os.path.dirname(os.path.abspath(__file__))
@@ -62,6 +63,7 @@ def create_user(email, password):
62
  return False, None
63
 
64
  # Update load_and_encode function to use the aligned face without normalization
 
65
  def load_and_encode(image_path):
66
  try:
67
  aligned_face = detect_and_align_faces(image_path)
@@ -107,6 +109,7 @@ def detect_and_align_faces(image_path):
107
  return aligned_face
108
 
109
  # Add person to database
 
110
  def add_person(name, image_path, instagram_handle, email=None):
111
  try:
112
  encoding = load_and_encode(image_path)
@@ -135,6 +138,7 @@ def add_person(name, image_path, instagram_handle, email=None):
135
  return f"Failed to add person: {str(e)}"
136
 
137
  # Recognize face from image
 
138
  def recognize_face(image_path):
139
  if not image_path:
140
  return "Please upload an image."
@@ -166,6 +170,7 @@ def recognize_face(image_path):
166
  return f"Failed to recognize face: {str(e)}"
167
 
168
  # Recognize face from image and return optimal or highest matching ID
 
169
  def recognize_face_optimal(image_path):
170
  if not image_path:
171
  return "Please upload an image."
@@ -197,6 +202,7 @@ def recognize_face_optimal(image_path):
197
  return f"Failed to recognize face: {str(e)}"
198
 
199
  # Delete person from database
 
200
  def delete_person(name):
201
  try:
202
  ref.child(name).delete()
@@ -303,6 +309,7 @@ def send_message(sender_email, receiver_email, message_content):
303
  return f"Failed to send message: {str(e)}"
304
 
305
  # Function to retrieve messages for a user
 
306
  def get_messages(user_email):
307
  try:
308
  messages = db_firestore.collection('messages').where('receiver_email', '==', user_email).order_by('timestamp', direction=firestore.Query.DESCENDING).stream()
 
7
  import numpy as np
8
  import cv2
9
  import dlib
10
+ from streamlit import cache as st_cache
11
 
12
  # Get the current working directory
13
  current_directory = os.path.dirname(os.path.abspath(__file__))
 
63
  return False, None
64
 
65
  # Update load_and_encode function to use the aligned face without normalization
66
+ @st_cache
67
  def load_and_encode(image_path):
68
  try:
69
  aligned_face = detect_and_align_faces(image_path)
 
109
  return aligned_face
110
 
111
  # Add person to database
112
+ @st_cache
113
  def add_person(name, image_path, instagram_handle, email=None):
114
  try:
115
  encoding = load_and_encode(image_path)
 
138
  return f"Failed to add person: {str(e)}"
139
 
140
  # Recognize face from image
141
+ @st_cache
142
  def recognize_face(image_path):
143
  if not image_path:
144
  return "Please upload an image."
 
170
  return f"Failed to recognize face: {str(e)}"
171
 
172
  # Recognize face from image and return optimal or highest matching ID
173
+ @st_cache
174
  def recognize_face_optimal(image_path):
175
  if not image_path:
176
  return "Please upload an image."
 
202
  return f"Failed to recognize face: {str(e)}"
203
 
204
  # Delete person from database
205
+ @st_cache
206
  def delete_person(name):
207
  try:
208
  ref.child(name).delete()
 
309
  return f"Failed to send message: {str(e)}"
310
 
311
  # Function to retrieve messages for a user
312
+ @st_cache
313
  def get_messages(user_email):
314
  try:
315
  messages = db_firestore.collection('messages').where('receiver_email', '==', user_email).order_by('timestamp', direction=firestore.Query.DESCENDING).stream()