Spaces:
Sleeping
Sleeping
Commit
·
9f08f28
1
Parent(s):
272b1a3
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ st.set_page_config(
|
|
| 15 |
initial_sidebar_state="collapsed"
|
| 16 |
)
|
| 17 |
st.title("Attendance System Using Face Recognition 📷")
|
| 18 |
-
st.markdown("This app recognizes faces in an image and updates attendance records with current timestamp & Location.")
|
| 19 |
|
| 20 |
# Load images for face recognition
|
| 21 |
Images = []
|
|
@@ -41,48 +41,61 @@ def findEncodings(Images):
|
|
| 41 |
|
| 42 |
encodeListknown = findEncodings(Images)
|
| 43 |
|
| 44 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
img_file_buffer = st.camera_input("Take a picture")
|
|
|
|
|
|
|
| 46 |
if img_file_buffer is not None:
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
initial_sidebar_state="collapsed"
|
| 16 |
)
|
| 17 |
st.title("Attendance System Using Face Recognition 📷")
|
| 18 |
+
st.markdown("This app recognizes faces in an image, verifies Aadhaar card details, and updates attendance records with the current timestamp & Location.")
|
| 19 |
|
| 20 |
# Load images for face recognition
|
| 21 |
Images = []
|
|
|
|
| 41 |
|
| 42 |
encodeListknown = findEncodings(Images)
|
| 43 |
|
| 44 |
+
# Function to validate Aadhaar card number
|
| 45 |
+
def validate_aadhaar(aadhaar):
|
| 46 |
+
# Implement your Aadhaar card validation logic here
|
| 47 |
+
# For simplicity, let's assume any 4-digit number is a valid Aadhaar card
|
| 48 |
+
return len(aadhaar) == 4 and aadhaar.isdigit()
|
| 49 |
+
|
| 50 |
+
# Take picture using the camera and input Aadhaar card details
|
| 51 |
img_file_buffer = st.camera_input("Take a picture")
|
| 52 |
+
aadhaar_number = st.text_input("Enter Aadhaar Number:")
|
| 53 |
+
|
| 54 |
if img_file_buffer is not None:
|
| 55 |
+
# Validate Aadhaar card number
|
| 56 |
+
if validate_aadhaar(aadhaar_number):
|
| 57 |
+
test_image = Image.open(img_file_buffer)
|
| 58 |
+
image = np.asarray(test_image)
|
| 59 |
+
|
| 60 |
+
imgS = cv2.resize(image, (0, 0), None, 0.25, 0.25)
|
| 61 |
+
imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
|
| 62 |
+
facesCurFrame = face_recognition.face_locations(imgS)
|
| 63 |
+
encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)
|
| 64 |
+
|
| 65 |
+
name = "Unknown" # Default name for unknown faces
|
| 66 |
+
|
| 67 |
+
if len(encodesCurFrame) > 0:
|
| 68 |
+
for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):
|
| 69 |
+
matches = face_recognition.compare_faces(encodeListknown, encodeFace)
|
| 70 |
+
faceDis = face_recognition.face_distance(encodeListknown, encodeFace)
|
| 71 |
+
matchIndex = np.argmin(faceDis)
|
| 72 |
+
|
| 73 |
+
if matches[matchIndex]:
|
| 74 |
+
name = classnames[matchIndex].upper()
|
| 75 |
+
|
| 76 |
+
y1, x2, y2, x1 = faceLoc
|
| 77 |
+
y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
|
| 78 |
+
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 79 |
+
cv2.rectangle(image, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
|
| 80 |
+
cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
|
| 81 |
+
|
| 82 |
+
if name != "Unknown":
|
| 83 |
+
# Update Aadhaar data
|
| 84 |
+
url = "https://attendanceviaface.000webhostapp.com"
|
| 85 |
+
url1 = "/update.php"
|
| 86 |
+
data1 = {'name': name, 'aadhaar': aadhaar_number}
|
| 87 |
+
response = requests.post(url + url1, data=data1)
|
| 88 |
+
|
| 89 |
+
if response.status_code == 200:
|
| 90 |
+
st.success("Data updated on: " + url)
|
| 91 |
+
else:
|
| 92 |
+
st.warning("Data not updated")
|
| 93 |
+
|
| 94 |
+
# Apply styling with CSS
|
| 95 |
+
st.markdown('<style>img { animation: pulse 2s infinite; }</style>', unsafe_allow_html=True)
|
| 96 |
+
st.image(image, use_column_width=True, output_format="PNG")
|
| 97 |
+
|
| 98 |
+
if name == "Unknown":
|
| 99 |
+
st.info("Face not detected. Please try again.")
|
| 100 |
+
else:
|
| 101 |
+
st.error("Invalid Aadhaar card number. Please enter a valid 12-digit Aadhaar number.")
|