Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import cv2
|
|
4 |
import datetime
|
5 |
import pandas as pd
|
6 |
from PIL import Image
|
7 |
-
import io
|
8 |
import os
|
9 |
|
10 |
# Create a directory for storing photos
|
@@ -19,24 +18,36 @@ def create_database():
|
|
19 |
rollno TEXT,
|
20 |
name TEXT,
|
21 |
photo_path TEXT,
|
|
|
22 |
timestamp TEXT
|
23 |
)''')
|
24 |
conn.commit()
|
25 |
conn.close()
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
def mark_attendance(rollno, name, frame):
|
28 |
"""Marks attendance for the user."""
|
29 |
conn = sqlite3.connect('attendance.db')
|
30 |
c = conn.cursor()
|
31 |
-
timestamp = datetime.datetime.now()
|
|
|
|
|
32 |
|
33 |
# Save the captured photo
|
34 |
photo_path = f"photos/{rollno}_{name.replace(' ', '_')}.jpg"
|
35 |
photo = Image.fromarray(frame)
|
36 |
photo.save(photo_path)
|
37 |
|
|
|
|
|
|
|
38 |
# Insert record into the database
|
39 |
-
c.execute("INSERT INTO attendance (rollno, name, photo_path, timestamp) VALUES (?, ?, ?, ?)",
|
|
|
40 |
conn.commit()
|
41 |
conn.close()
|
42 |
|
@@ -44,7 +55,7 @@ def get_attendance_records():
|
|
44 |
"""Fetches all attendance records."""
|
45 |
conn = sqlite3.connect('attendance.db')
|
46 |
c = conn.cursor()
|
47 |
-
c.execute("SELECT rollno, name, photo_path, timestamp FROM attendance")
|
48 |
records = c.fetchall()
|
49 |
conn.close()
|
50 |
return records
|
@@ -91,14 +102,14 @@ elif menu == "Database":
|
|
91 |
st.header("Attendance Records")
|
92 |
records = get_attendance_records()
|
93 |
data = []
|
94 |
-
for rollno, name, photo_path, timestamp in records:
|
95 |
photo = Image.open(photo_path) if os.path.exists(photo_path) else None
|
96 |
-
|
|
|
97 |
|
98 |
-
df = pd.DataFrame(data, columns=["Roll No", "Name", "
|
99 |
st.write("### Attendance Records")
|
100 |
-
st.dataframe(df.drop(columns=["Photo"])) # Display text columns
|
101 |
-
|
102 |
for idx, row in df.iterrows():
|
103 |
-
|
104 |
-
|
|
|
|
4 |
import datetime
|
5 |
import pandas as pd
|
6 |
from PIL import Image
|
|
|
7 |
import os
|
8 |
|
9 |
# Create a directory for storing photos
|
|
|
18 |
rollno TEXT,
|
19 |
name TEXT,
|
20 |
photo_path TEXT,
|
21 |
+
emotion TEXT,
|
22 |
timestamp TEXT
|
23 |
)''')
|
24 |
conn.commit()
|
25 |
conn.close()
|
26 |
|
27 |
+
def detect_emotion(frame):
|
28 |
+
"""Dummy emotion detection function."""
|
29 |
+
# Placeholder for actual emotion detection logic
|
30 |
+
return "Happy"
|
31 |
+
|
32 |
def mark_attendance(rollno, name, frame):
|
33 |
"""Marks attendance for the user."""
|
34 |
conn = sqlite3.connect('attendance.db')
|
35 |
c = conn.cursor()
|
36 |
+
timestamp = datetime.datetime.now()
|
37 |
+
date_str = timestamp.strftime("%Y-%m-%d")
|
38 |
+
time_str = timestamp.strftime("%H:%M:%S")
|
39 |
|
40 |
# Save the captured photo
|
41 |
photo_path = f"photos/{rollno}_{name.replace(' ', '_')}.jpg"
|
42 |
photo = Image.fromarray(frame)
|
43 |
photo.save(photo_path)
|
44 |
|
45 |
+
# Detect emotion (dummy function)
|
46 |
+
emotion = detect_emotion(frame)
|
47 |
+
|
48 |
# Insert record into the database
|
49 |
+
c.execute("INSERT INTO attendance (rollno, name, photo_path, emotion, timestamp) VALUES (?, ?, ?, ?, ?)",
|
50 |
+
(rollno, name, photo_path, emotion, timestamp))
|
51 |
conn.commit()
|
52 |
conn.close()
|
53 |
|
|
|
55 |
"""Fetches all attendance records."""
|
56 |
conn = sqlite3.connect('attendance.db')
|
57 |
c = conn.cursor()
|
58 |
+
c.execute("SELECT rollno, name, photo_path, emotion, timestamp FROM attendance")
|
59 |
records = c.fetchall()
|
60 |
conn.close()
|
61 |
return records
|
|
|
102 |
st.header("Attendance Records")
|
103 |
records = get_attendance_records()
|
104 |
data = []
|
105 |
+
for rollno, name, photo_path, emotion, timestamp in records:
|
106 |
photo = Image.open(photo_path) if os.path.exists(photo_path) else None
|
107 |
+
date, time = timestamp.split(" ")
|
108 |
+
data.append((rollno, photo, name, emotion, date, time))
|
109 |
|
110 |
+
df = pd.DataFrame(data, columns=["Roll No", "Photo", "Name", "Emotion", "Date", "Time"])
|
111 |
st.write("### Attendance Records")
|
|
|
|
|
112 |
for idx, row in df.iterrows():
|
113 |
+
st.image(row["Photo"], caption=f"Roll No: {row['Roll No']} - Name: {row['Name']} - Emotion: {row['Emotion']}")
|
114 |
+
st.table(df.drop(columns=["Photo"])) # Exclude photo for table display
|
115 |
+
|