LovnishVerma commited on
Commit
7dbbc1f
·
1 Parent(s): eab1c41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -2
app.py CHANGED
@@ -6,6 +6,7 @@ import face_recognition
6
  import os
7
  from datetime import datetime
8
  import streamlit as st
 
9
 
10
  # Set page title and description
11
  st.set_page_config(
@@ -17,6 +18,20 @@ st.set_page_config(
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 = []
22
  classnames = []
@@ -48,9 +63,10 @@ def validate_aadhaar(aadhaar):
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):
@@ -91,6 +107,11 @@ if img_file_buffer is not None:
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")
@@ -98,4 +119,7 @@ if img_file_buffer is not None:
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.")
 
 
 
 
6
  import os
7
  from datetime import datetime
8
  import streamlit as st
9
+ import sqlite3
10
 
11
  # Set page title and description
12
  st.set_page_config(
 
18
  st.title("Attendance System Using Face Recognition 📷")
19
  st.markdown("This app recognizes faces in an image, verifies Aadhaar card details, and updates attendance records with the current timestamp & Location.")
20
 
21
+ # Create or connect to the SQLite database
22
+ conn = sqlite3.connect("attendance_database.db")
23
+ cursor = conn.cursor()
24
+
25
+ # Check if the 'faces' table exists, create it if not
26
+ cursor.execute('''
27
+ CREATE TABLE IF NOT EXISTS faces (
28
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
29
+ aadhaar TEXT,
30
+ encoding BLOB
31
+ )
32
+ ''')
33
+ conn.commit()
34
+
35
  # Load images for face recognition
36
  Images = []
37
  classnames = []
 
63
  return len(aadhaar) == 4 and aadhaar.isdigit()
64
 
65
  # Take picture using the camera and input Aadhaar card details
66
+ img_file_buffer = st.file_uploader("Upload an image", type=["jpg", "jpeg"])
67
  aadhaar_number = st.text_input("Enter Aadhaar Number:")
68
 
69
+ # Face recognition code...
70
  if img_file_buffer is not None:
71
  # Validate Aadhaar card number
72
  if validate_aadhaar(aadhaar_number):
 
107
  else:
108
  st.warning("Data not updated")
109
 
110
+ # Store face encoding and Aadhaar number in the database
111
+ face_encoding_bytes = pickle.dumps(encodeFace)
112
+ cursor.execute("INSERT INTO faces (aadhaar, encoding) VALUES (?, ?)", (aadhaar_number, face_encoding_bytes))
113
+ conn.commit()
114
+
115
  # Apply styling with CSS
116
  st.markdown('<style>img { animation: pulse 2s infinite; }</style>', unsafe_allow_html=True)
117
  st.image(image, use_column_width=True, output_format="PNG")
 
119
  if name == "Unknown":
120
  st.info("Face not detected. Please try again.")
121
  else:
122
+ st.error("Invalid Aadhaar card number. Please enter a valid 4-digit Aadhaar number.")
123
+
124
+ # Close the database connection
125
+ conn.close()