RajaThor commited on
Commit
b9f7106
·
verified ·
1 Parent(s): 0a0f04e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -2
app.py CHANGED
@@ -129,6 +129,7 @@ def add_person(name, image_path, instagram_handle, email=None):
129
 
130
  ref.child(name).set(person_data)
131
 
 
132
  return f"Success: {name} added to the database!"
133
  except Exception as e:
134
  return f"Failed to add person: {str(e)}"
@@ -157,12 +158,13 @@ def recognize_face(image_path):
157
  insta_link = f"https://www.instagram.com/{insta_handle}/"
158
  insta_link_html = f'<a href="{insta_link}" target="_blank"><font color="red">{insta_handle}</font></a>'
159
  results.append(f"- It's a picture of {name}! Insta handle: {insta_link_html}, Email: {email}")
 
160
  return "\n".join(results)
161
  else:
162
  return "Face not found in the database."
163
  except Exception as e:
164
  return f"Failed to recognize face: {str(e)}"
165
-
166
  # Recognize face from image and return optimal or highest matching ID
167
  def recognize_face_optimal(image_path):
168
  if not image_path:
@@ -198,6 +200,7 @@ def recognize_face_optimal(image_path):
198
  def delete_person(name):
199
  try:
200
  ref.child(name).delete()
 
201
  return f"{name} deleted from the database!"
202
  except Exception as e:
203
  return f"Failed to delete person: {str(e)}"
@@ -343,9 +346,36 @@ def messenger_ui():
343
  send_message_ui()
344
  elif selected_tab == "View Messages":
345
  view_messages_ui()
346
-
347
  #end of messaging section
348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  def tour_guide_ui():
350
  st.title("🗺️ Tour Guide")
351
  st.markdown("This tour will guide you through the application.")
 
129
 
130
  ref.child(name).set(person_data)
131
 
132
+ log_action(st.session_state.auth_state["user"].email, "Added person")
133
  return f"Success: {name} added to the database!"
134
  except Exception as e:
135
  return f"Failed to add person: {str(e)}"
 
158
  insta_link = f"https://www.instagram.com/{insta_handle}/"
159
  insta_link_html = f'<a href="{insta_link}" target="_blank"><font color="red">{insta_handle}</font></a>'
160
  results.append(f"- It's a picture of {name}! Insta handle: {insta_link_html}, Email: {email}")
161
+ log_action(st.session_state.auth_state["user"].email, "Recognized face")
162
  return "\n".join(results)
163
  else:
164
  return "Face not found in the database."
165
  except Exception as e:
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:
 
200
  def delete_person(name):
201
  try:
202
  ref.child(name).delete()
203
+ log_action(st.session_state.auth_state["user"].email, "Deleted person")
204
  return f"{name} deleted from the database!"
205
  except Exception as e:
206
  return f"Failed to delete person: {str(e)}"
 
346
  send_message_ui()
347
  elif selected_tab == "View Messages":
348
  view_messages_ui()
349
+
350
  #end of messaging section
351
 
352
+ # History section
353
+ def log_action(user_email, action):
354
+ try:
355
+ db_firestore.collection('history').add({
356
+ 'user_email': user_email,
357
+ 'action': action,
358
+ 'timestamp': firestore.SERVER_TIMESTAMP
359
+ })
360
+ except Exception as e:
361
+ st.error(f"Failed to log action: {str(e)}")
362
+
363
+ # Display history of actions taken by the user
364
+ def display_history(user_email):
365
+ st.title("📜 History")
366
+ st.write("Here is the history of actions taken by you:")
367
+
368
+ try:
369
+ history = db_firestore.collection('history').where('user_email', '==', user_email).order_by('timestamp', direction=firestore.Query.DESCENDING).stream()
370
+ for entry in history:
371
+ entry_data = entry.to_dict()
372
+ action = entry_data['action']
373
+ timestamp = entry_data['timestamp']
374
+ st.write(f"- {action} at {timestamp}")
375
+ except Exception as e:
376
+ st.error(f"Failed to retrieve history: {str(e)}")
377
+ #End of history section
378
+
379
  def tour_guide_ui():
380
  st.title("🗺️ Tour Guide")
381
  st.markdown("This tour will guide you through the application.")