Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import os
|
|
| 7 |
import sqlite3
|
| 8 |
from datetime import datetime
|
| 9 |
|
| 10 |
-
|
| 11 |
conn = sqlite3.connect('attendance.db')
|
| 12 |
c = conn.cursor()
|
| 13 |
|
|
@@ -15,7 +15,6 @@ c = conn.cursor()
|
|
| 15 |
c.execute('''CREATE TABLE IF NOT EXISTS attendance
|
| 16 |
(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, time TEXT)''')
|
| 17 |
|
| 18 |
-
|
| 19 |
st.title("AIMLJan24 - Face Recognition")
|
| 20 |
|
| 21 |
# Load images for face recognition
|
|
@@ -24,11 +23,6 @@ classnames = []
|
|
| 24 |
directory = "photos"
|
| 25 |
myList = os.listdir(directory)
|
| 26 |
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 27 |
-
if not os.path.isdir('Attendance'):
|
| 28 |
-
os.makedirs('Attendance')
|
| 29 |
-
if f'Attendance-{current_datetime}.csv' not in os.listdir('Attendance'):
|
| 30 |
-
with open(f'Attendance/Attendance-{current_datetime}.csv', 'w') as f:
|
| 31 |
-
f.write('Name,Time')
|
| 32 |
|
| 33 |
st.write("Photographs found in folder : ")
|
| 34 |
for cls in myList:
|
|
@@ -47,13 +41,8 @@ file_name = st.camera_input("Upload image")
|
|
| 47 |
|
| 48 |
def add_attendance(name):
|
| 49 |
username = name
|
| 50 |
-
|
| 51 |
-
print(current_datetime)
|
| 52 |
-
|
| 53 |
-
# Insert data into the attendance table
|
| 54 |
c.execute("INSERT INTO attendance (name, time) VALUES (?, ?)", (username, current_datetime))
|
| 55 |
conn.commit()
|
| 56 |
-
|
| 57 |
|
| 58 |
if file_name is not None:
|
| 59 |
col1, col2 = st.columns(2)
|
|
@@ -94,6 +83,9 @@ if file_name is not None:
|
|
| 94 |
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 95 |
cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
|
| 96 |
|
|
|
|
|
|
|
|
|
|
| 97 |
# Display the image with recognized faces
|
| 98 |
st.image(image, use_column_width=True, output_format="PNG")
|
| 99 |
|
|
@@ -101,7 +93,5 @@ if file_name is not None:
|
|
| 101 |
st.write("Recognized Names:")
|
| 102 |
for i, name in enumerate(recognized_names):
|
| 103 |
st.write(f"Face {i+1}: {name}")
|
| 104 |
-
if len(recognized_names) > 0:
|
| 105 |
-
add_attendance(recognized_names)
|
| 106 |
else:
|
| 107 |
-
st.warning("No faces detected in the image. Face recognition failed.")
|
|
|
|
| 7 |
import sqlite3
|
| 8 |
from datetime import datetime
|
| 9 |
|
| 10 |
+
# Establish connection to SQLite database
|
| 11 |
conn = sqlite3.connect('attendance.db')
|
| 12 |
c = conn.cursor()
|
| 13 |
|
|
|
|
| 15 |
c.execute('''CREATE TABLE IF NOT EXISTS attendance
|
| 16 |
(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, time TEXT)''')
|
| 17 |
|
|
|
|
| 18 |
st.title("AIMLJan24 - Face Recognition")
|
| 19 |
|
| 20 |
# Load images for face recognition
|
|
|
|
| 23 |
directory = "photos"
|
| 24 |
myList = os.listdir(directory)
|
| 25 |
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
st.write("Photographs found in folder : ")
|
| 28 |
for cls in myList:
|
|
|
|
| 41 |
|
| 42 |
def add_attendance(name):
|
| 43 |
username = name
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
c.execute("INSERT INTO attendance (name, time) VALUES (?, ?)", (username, current_datetime))
|
| 45 |
conn.commit()
|
|
|
|
| 46 |
|
| 47 |
if file_name is not None:
|
| 48 |
col1, col2 = st.columns(2)
|
|
|
|
| 83 |
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
| 84 |
cv2.putText(image, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
|
| 85 |
|
| 86 |
+
# Store attendance in SQLite database
|
| 87 |
+
add_attendance(name)
|
| 88 |
+
|
| 89 |
# Display the image with recognized faces
|
| 90 |
st.image(image, use_column_width=True, output_format="PNG")
|
| 91 |
|
|
|
|
| 93 |
st.write("Recognized Names:")
|
| 94 |
for i, name in enumerate(recognized_names):
|
| 95 |
st.write(f"Face {i+1}: {name}")
|
|
|
|
|
|
|
| 96 |
else:
|
| 97 |
+
st.warning("No faces detected in the image. Face recognition failed.")
|