LovnishVerma commited on
Commit
eb8a721
1 Parent(s): 2f8c9c5

Delete app1.py

Browse files
Files changed (1) hide show
  1. app1.py +0 -130
app1.py DELETED
@@ -1,130 +0,0 @@
1
- from PIL import Image
2
- import numpy as np
3
- import cv2
4
- import requests
5
- import face_recognition
6
- import os
7
- import streamlit as st
8
-
9
- # page title and description
10
- st.set_page_config(
11
- page_title="Aadhaar Based Face Recognition Attendance System",
12
- page_icon="📷",
13
- layout="centered",
14
- initial_sidebar_state="collapsed"
15
- )
16
- st.title("Attendance System Using Face Recognition 📷")
17
- st.markdown("This app recognizes faces in an image, verifies Aadhaar card details, and updates attendance records with the current timestamp.")
18
-
19
- # Load images for face recognition
20
- Images = [] # List to store Images
21
- classnames = [] # List to store classnames
22
- aadhar_numbers = [] # List to store Aadhaar numbers
23
-
24
- directory = "photos"
25
- myList = os.listdir(directory)
26
-
27
- for cls in myList:
28
- if os.path.splitext(cls)[1] in [".jpg", ".jpeg"]:
29
- img_path = os.path.join(directory, cls)
30
- curImg = cv2.imread(img_path)
31
- Images.append(curImg)
32
- classnames.append(os.path.splitext(cls)[0])
33
- # Assume Aadhaar number is part of the image filename (e.g., "123456_john.jpg")
34
- aadhar_numbers.append(cls.split('_')[0])
35
-
36
- # Function to validate Aadhaar card number
37
- def validate_aadhaar(aadhaar):
38
- # Implement your Aadhaar card validation logic here
39
- # For simplicity, let's assume any 6-digit number is a valid Aadhaar card
40
- return len(aadhaar) == 6 and aadhaar.isdigit()
41
-
42
- # Function to update Aadhaar data
43
- def update_data(name, aadhaar_number):
44
- url = "https://attendanceviaface.000webhostapp.com"
45
- url1 = "/update.php"
46
- data = {'name': name, 'aadhaar': aadhaar_number}
47
- response = requests.post(url + url1, data=data)
48
-
49
- if response.status_code == 200:
50
- st.success("Data updated on: " + url)
51
- else:
52
- st.warning("Data not updated")
53
-
54
- # Function to display image with overlay
55
- def display_image_with_overlay(image, name):
56
- # Add overlay to the image (e.g., bounding box and name)
57
- # ...
58
-
59
- # Apply styling with CSS
60
- st.markdown('<style>img { animation: pulse 2s infinite; }</style>', unsafe_allow_html=True)
61
- st.image(image, use_column_width=True, output_format="PNG")
62
-
63
- # Take input Aadhaar card details
64
- aadhaar_number = st.text_input("Enter your 4-digits Aadhaar Number:")
65
-
66
- # Take picture using the camera
67
- img_file_buffer = st.camera_input("Take a picture")
68
-
69
- # Load images for face recognition
70
- encodeListknown = [face_recognition.face_encodings(img)[0] for img in Images]
71
-
72
- if img_file_buffer is not None:
73
- # Validate Aadhaar card number
74
- if validate_aadhaar(aadhaar_number):
75
- test_image = Image.open(img_file_buffer)
76
- image = np.asarray(test_image)
77
-
78
- imgS = cv2.resize(image, (0, 0), None, 0.25, 0.25)
79
- imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
80
- facesCurFrame = face_recognition.face_locations(imgS)
81
- encodesCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)
82
-
83
- name = "Unknown" # Default name for unknown faces
84
-
85
- # Checking if faces are detected
86
- if len(encodesCurFrame) > 0:
87
- for encodeFace, faceLoc in zip(encodesCurFrame, facesCurFrame):
88
- # Assuming that encodeListknown is defined and populated in your code
89
- matches = face_recognition.compare_faces(encodeListknown, encodeFace)
90
- faceDis = face_recognition.face_distance(encodeListknown, encodeFace)
91
- matchIndex = np.argmin(faceDis)
92
-
93
- if matches[matchIndex]:
94
- name = classnames[matchIndex].upper()
95
-
96
- # Check if Aadhaar number is found in the database
97
- if aadhaar_number not in aadhar_numbers:
98
- st.error("Face recognized, but Aadhaar number not found in the database.")
99
- else:
100
- # Update data only if a known face is detected and Aadhaar number is valid
101
- update_data(name, aadhaar_number)
102
-
103
- else:
104
- # Face recognized, but not matched with Aadhaar number
105
- st.error("Face recognized, but Aadhaar number does not match.")
106
-
107
- y1, x2, y2, x1 = faceLoc
108
- y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
109
- cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
110
- cv2.rectangle(image, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
111
- cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
112
-
113
- display_image_with_overlay(image, name)
114
-
115
- # Display the name corresponding to the entered Aadhaar number
116
- if name == "Unknown":
117
- # Match Aadhaar number with the list
118
- aadhar_index = aadhar_numbers.index(aadhaar_number) if aadhaar_number in aadhar_numbers else None
119
- if aadhar_index is not None:
120
- st.success(f"Match found: {classnames[aadhar_index]}")
121
- else:
122
- st.warning("Face not detected, and Aadhaar number not found in the database.")
123
- else:
124
- st.success(f"Face recognized: {name}")
125
-
126
- else:
127
- st.warning("No faces detected in the image. Face recognition failed.")
128
-
129
- else:
130
- st.error("Invalid Aadhaar card number. Please enter a valid 6-digit Aadhaar number.")