Spaces:
Build error
Build error
LovnishVerma
commited on
Commit
•
c9b325d
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,63 @@ def findEncodings(Images):
|
|
41 |
|
42 |
encodeListknown = findEncodings(Images)
|
43 |
|
44 |
-
#
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
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 12-digit number is a valid Aadhaar card
|
48 |
+
return len(aadhaar) == 12 and aadhaar.isdigit()
|
49 |
+
|
50 |
+
# Take picture using the camera and input Aadhaar card details
|
51 |
+
img_file_buffer = st.file_uploader("Upload an image", type=["jpg", "jpeg"])
|
52 |
+
aadhaar_number = st.text_input("Enter Aadhaar Number:")
|
53 |
+
|
54 |
+
# Face recognition code...
|
55 |
+
|
56 |
if img_file_buffer is not None:
|
57 |
+
# Validate Aadhaar card number
|
58 |
+
if validate_aadhaar(aadhaar_number):
|
59 |
+
test_image = Image.open(img_file_buffer)
|
60 |
+
image = np.asarray(test_image)
|
61 |
+
|
62 |
+
imgS = cv2.resize(image, (0, 0), None, 0.25, 0.25)
|
63 |
+
imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
|
64 |
+
facesCurFrame = face_recognition.face_locations(imgS)
|
65 |
+
encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)
|
66 |
+
|
67 |
+
name = "Unknown" # Default name for unknown faces
|
68 |
+
|
69 |
+
if len(encodesCurFrame) > 0:
|
70 |
+
for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):
|
71 |
+
matches = face_recognition.compare_faces(encodeListknown, encodeFace)
|
72 |
+
faceDis = face_recognition.face_distance(encodeListknown, encodeFace)
|
73 |
+
matchIndex = np.argmin(faceDis)
|
74 |
+
|
75 |
+
if matches[matchIndex]:
|
76 |
+
name = classnames[matchIndex].upper()
|
77 |
+
|
78 |
+
y1, x2, y2, x1 = faceLoc
|
79 |
+
y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
|
80 |
+
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
81 |
+
cv2.rectangle(image, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
|
82 |
+
cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
|
83 |
+
|
84 |
+
if name != "Unknown":
|
85 |
+
url = "https://mrvishal7705.000webhostapp.com"
|
86 |
+
url1 = "/update.php"
|
87 |
+
data1 = {'name': name, 'aadhaar': aadhaar_number}
|
88 |
+
response = requests.post(url + url1, data=data1)
|
89 |
+
|
90 |
+
if response.status_code == 200:
|
91 |
+
st.success("Data updated on: " + url)
|
92 |
+
else:
|
93 |
+
st.warning("Data not updated")
|
94 |
+
|
95 |
+
# Display the result
|
96 |
+
st.markdown('<style>img { animation: pulse 2s infinite; }</style>', unsafe_allow_html=True)
|
97 |
+
st.image(image, use_column_width=True, output_format="PNG")
|
98 |
+
|
99 |
+
if name == "Unknown":
|
100 |
+
st.info("Face not detected. Please try again.")
|
101 |
+
else:
|
102 |
+
st.error("Invalid Aadhaar card number. Please enter a valid 12-digit Aadhaar number.")
|
103 |
+
|