RajaThor commited on
Commit
75644b0
·
verified ·
1 Parent(s): a0bf13f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -25
app.py CHANGED
@@ -146,7 +146,7 @@ def add_person(name, image_path, instagram_handle, email=None):
146
  except Exception as e:
147
  return f"Failed to add person: {str(e)}"
148
 
149
- # Update recognize_face function to handle multiple face encodings
150
  def recognize_face(image_path):
151
  if not image_path:
152
  return "Please upload an image."
@@ -176,7 +176,8 @@ def recognize_face(image_path):
176
  for name, insta_handle, email in matches:
177
  insta_link = f"https://www.instagram.com/{insta_handle}/"
178
  insta_link_html = f'<a href="{insta_link}" target="_blank"><font color="red">{insta_handle}</font></a>'
179
- results.append(f"- It's a picture of {name}! Insta handle: {insta_link_html}, Email: {email}")
 
180
  log_action(st.session_state.auth_state["user"].email, "Recognized face")
181
  return "\n".join(results)
182
  else:
@@ -266,17 +267,13 @@ def recognize_face_ui():
266
  result = recognize_face(image_path)
267
  st.write(result, unsafe_allow_html=True)
268
 
269
- # Extract email from the result
270
- if "Email" in result:
271
- email_start_index = result.find("Email: ") + len("Email: ")
272
- email_end_index = result.find("</font>", email_start_index)
273
- email = result[email_start_index:email_end_index]
 
274
 
275
- # Add a link to the email
276
- message_ui_url = f"http://localhost:8501/?p=Insta%27s%20EYE&p=Insta%27s%20EYE&p=Insta%27s%20EYE&em={email}"
277
- st.markdown(f"Click [here](<{message_ui_url}>) to message {email}")
278
-
279
- # Streamlit interface for recognizing face optimal
280
  def recognize_face_optimal_ui():
281
  st.title("🔍 Recognize Face (Optimal)")
282
  image_path = st.file_uploader("Upload Image", help="Upload an image for optimal face recognition")
@@ -343,12 +340,12 @@ def get_messages(user_email):
343
  return None
344
 
345
  # Streamlit interface for messaging
346
- def messaging_ui(recipient_email):
347
  st.title("💬 Messaging")
348
 
349
  if st.session_state.auth_state["signed_in"]:
350
  sender_email = st.session_state.auth_state["user"].email
351
- receiver_email = st.text_input("Receiver's Email", value=recipient_email, help="Enter the receiver's email address")
352
  message_content = st.text_area("Message Content")
353
 
354
  if st.button("Send Message"):
@@ -528,7 +525,7 @@ def display_tour_steps(steps):
528
  def main():
529
  st.sidebar.title("Options")
530
  option = st.sidebar.radio("Select Option", ["Add Person", "Recognize Face", "Delete Person", "Recognize Face (Optimal)", "Tour Guide", "Feedback", "Messaging", "History", "Delete User"])
531
-
532
  if option == "Add Person":
533
  add_person_ui()
534
  elif option == "Recognize Face":
@@ -542,20 +539,11 @@ def main():
542
  elif option == "Feedback":
543
  feedback_ui()
544
  elif option == "Messaging":
545
- if "em" in st.session_state and st.session_state["em"]:
546
- messaging_ui(st.session_state["em"])
547
- st.session_state["em"] = None
548
- else:
549
- messaging_ui()
550
  elif option == "History":
551
  display_history(st.session_state.auth_state["user"].email)
552
  elif option == "Delete User":
553
  delete_user_ui()
554
-
555
- # Handle the case when the user clicks on the email link
556
- if "em" in st.session_state and st.session_state["em"]:
557
- messaging_ui(st.session_state["em"])
558
- st.session_state["em"] = None
559
 
560
  # Run the tour guide
561
  if __name__ == "__main__":
 
146
  except Exception as e:
147
  return f"Failed to add person: {str(e)}"
148
 
149
+ # Update recognize_face function to include email in the result
150
  def recognize_face(image_path):
151
  if not image_path:
152
  return "Please upload an image."
 
176
  for name, insta_handle, email in matches:
177
  insta_link = f"https://www.instagram.com/{insta_handle}/"
178
  insta_link_html = f'<a href="{insta_link}" target="_blank"><font color="red">{insta_handle}</font></a>'
179
+ email_link_html = f'<a href="#" onclick="set_recipient_email(\'{email}\')">{email}</a>'
180
+ results.append(f"- It's a picture of {name}! Insta handle: {insta_link_html}, Email: {email_link_html}")
181
  log_action(st.session_state.auth_state["user"].email, "Recognized face")
182
  return "\n".join(results)
183
  else:
 
267
  result = recognize_face(image_path)
268
  st.write(result, unsafe_allow_html=True)
269
 
270
+ # Add JavaScript to set the recipient's email when the email is clicked
271
+ st.write('<script>')
272
+ st.write('function set_recipient_email(email) {')
273
+ st.write('document.getElementById("receiver_email").value = email;')
274
+ st.write('}')
275
+ st.write('</script>')
276
 
 
 
 
 
 
277
  def recognize_face_optimal_ui():
278
  st.title("🔍 Recognize Face (Optimal)")
279
  image_path = st.file_uploader("Upload Image", help="Upload an image for optimal face recognition")
 
340
  return None
341
 
342
  # Streamlit interface for messaging
343
+ def messaging_ui():
344
  st.title("💬 Messaging")
345
 
346
  if st.session_state.auth_state["signed_in"]:
347
  sender_email = st.session_state.auth_state["user"].email
348
+ receiver_email = st.text_input("Receiver's Email", help="Enter the receiver's email address", id="receiver_email")
349
  message_content = st.text_area("Message Content")
350
 
351
  if st.button("Send Message"):
 
525
  def main():
526
  st.sidebar.title("Options")
527
  option = st.sidebar.radio("Select Option", ["Add Person", "Recognize Face", "Delete Person", "Recognize Face (Optimal)", "Tour Guide", "Feedback", "Messaging", "History", "Delete User"])
528
+
529
  if option == "Add Person":
530
  add_person_ui()
531
  elif option == "Recognize Face":
 
539
  elif option == "Feedback":
540
  feedback_ui()
541
  elif option == "Messaging":
542
+ messaging_ui()
 
 
 
 
543
  elif option == "History":
544
  display_history(st.session_state.auth_state["user"].email)
545
  elif option == "Delete User":
546
  delete_user_ui()
 
 
 
 
 
547
 
548
  # Run the tour guide
549
  if __name__ == "__main__":