Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -105,6 +105,21 @@ with app_tab:
|
|
| 105 |
match_idx = torch.argmax(prediction)
|
| 106 |
st.subheader("Face Recognition Results")
|
| 107 |
# st.write("Similarity Scores:", prediction.tolist())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
if prediction[match_idx] >= 0.6:
|
| 110 |
pname = image_paths[match_idx].split('/')[-1].split('.')[0]
|
|
|
|
| 105 |
match_idx = torch.argmax(prediction)
|
| 106 |
st.subheader("Face Recognition Results")
|
| 107 |
# st.write("Similarity Scores:", prediction.tolist())
|
| 108 |
+
if prediction[match_idx] >= 0.6:
|
| 109 |
+
name = image_paths[match_idx].split('/')[-1].split('.')[0].upper()
|
| 110 |
+
|
| 111 |
+
# Extract face location from InsightFace result
|
| 112 |
+
face_info = app.get(cv2_webcam, max_num=1)[0]
|
| 113 |
+
faceLoc = face_info.bbox.astype(int) # returns [x1, y1, x2, y2]
|
| 114 |
+
|
| 115 |
+
x1, y1, x2, y2 = faceLoc
|
| 116 |
+
cv2.rectangle(cv2_webcam, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 117 |
+
cv2.rectangle(cv2_webcam, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
|
| 118 |
+
cv2.putText(cv2_webcam, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
|
| 119 |
+
|
| 120 |
+
# Convert BGR to RGB before displaying in Streamlit
|
| 121 |
+
st.image(cv2.cvtColor(cv2_webcam, cv2.COLOR_BGR2RGB), caption=f"Matched: {name}", use_column_width=True)
|
| 122 |
+
|
| 123 |
|
| 124 |
if prediction[match_idx] >= 0.6:
|
| 125 |
pname = image_paths[match_idx].split('/')[-1].split('.')[0]
|