Update app.py
Browse files
app.py
CHANGED
|
@@ -191,11 +191,16 @@ def recognize_face_optimal(image_path):
|
|
| 191 |
if matches:
|
| 192 |
best_match = min(matches, key=lambda x: x[1])
|
| 193 |
best_name, best_score = best_match
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
else:
|
| 200 |
return "Face not found in the database."
|
| 201 |
except Exception as e:
|
|
@@ -317,6 +322,7 @@ def send_message(sender_email, receiver_email, message_content):
|
|
| 317 |
return f"Failed to send message: {str(e)}"
|
| 318 |
|
| 319 |
# Function to retrieve messages for a user
|
|
|
|
| 320 |
def get_messages(user_email):
|
| 321 |
try:
|
| 322 |
messages = db_firestore.collection('messages').where('receiver_email', '==', user_email).order_by('timestamp', direction=firestore.Query.DESCENDING).stream()
|
|
@@ -326,7 +332,7 @@ def get_messages(user_email):
|
|
| 326 |
|
| 327 |
# Streamlit interface for messaging
|
| 328 |
def messaging_ui():
|
| 329 |
-
st.title("Messaging")
|
| 330 |
|
| 331 |
if st.session_state.auth_state["signed_in"]:
|
| 332 |
sender_email = st.session_state.auth_state["user"].email
|
|
|
|
| 191 |
if matches:
|
| 192 |
best_match = min(matches, key=lambda x: x[1])
|
| 193 |
best_name, best_score = best_match
|
| 194 |
+
|
| 195 |
+
# Check if the best match is within a reasonable range of similarity scores
|
| 196 |
+
if best_score < 0.6: # Adjust the threshold as needed
|
| 197 |
+
info = ref.child(best_name).child("info").get()
|
| 198 |
+
insta_handle = info["instagram_handle"]
|
| 199 |
+
insta_link = info["instagram_link"]
|
| 200 |
+
insta_link_html = f'<a href="{insta_link}" target="_blank"><font color="red">{insta_handle}</font></a>'
|
| 201 |
+
return f"Best match: {best_name} with a similarity score of {1 - best_score:.2%}. Insta handle: {insta_link_html}"
|
| 202 |
+
else:
|
| 203 |
+
return "No suitable match found."
|
| 204 |
else:
|
| 205 |
return "Face not found in the database."
|
| 206 |
except Exception as e:
|
|
|
|
| 322 |
return f"Failed to send message: {str(e)}"
|
| 323 |
|
| 324 |
# Function to retrieve messages for a user
|
| 325 |
+
@st_cache
|
| 326 |
def get_messages(user_email):
|
| 327 |
try:
|
| 328 |
messages = db_firestore.collection('messages').where('receiver_email', '==', user_email).order_by('timestamp', direction=firestore.Query.DESCENDING).stream()
|
|
|
|
| 332 |
|
| 333 |
# Streamlit interface for messaging
|
| 334 |
def messaging_ui():
|
| 335 |
+
st.title("💬 Messaging")
|
| 336 |
|
| 337 |
if st.session_state.auth_state["signed_in"]:
|
| 338 |
sender_email = st.session_state.auth_state["user"].email
|