LovnishVerma commited on
Commit
b70233f
·
verified ·
1 Parent(s): 156a24b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -5,6 +5,7 @@ import numpy as np
5
  from keras.models import load_model
6
  from PIL import Image
7
  import sqlite3
 
8
  from huggingface_hub import HfApi
9
 
10
  # Constants
@@ -47,7 +48,9 @@ def create_table():
47
  id INTEGER PRIMARY KEY AUTOINCREMENT,
48
  name TEXT NOT NULL,
49
  roll_number TEXT NOT NULL UNIQUE,
50
- image_path TEXT NOT NULL
 
 
51
  )
52
  """)
53
  conn.commit()
@@ -61,6 +64,16 @@ def insert_student(name, roll_number, image_path):
61
  except sqlite3.IntegrityError:
62
  st.warning("Roll number already exists!")
63
 
 
 
 
 
 
 
 
 
 
 
64
  def get_all_students():
65
  with sqlite3.connect(DB_FILE) as conn:
66
  cursor = conn.execute("SELECT * FROM students")
@@ -147,6 +160,14 @@ elif choice == "Face Recognition and Emotion Detection":
147
  emotion_label = detect_faces_and_emotions(img_array)
148
  if emotion_label:
149
  st.success(f"Emotion Detected: {emotion_label}")
 
 
 
 
 
 
 
 
150
  else:
151
  st.warning("No face detected.")
152
  except Exception as e:
@@ -162,6 +183,14 @@ elif choice == "Face Recognition and Emotion Detection":
162
  emotion_label = detect_faces_and_emotions(img_array)
163
  if emotion_label:
164
  st.success(f"Emotion Detected: {emotion_label}")
 
 
 
 
 
 
 
 
165
  else:
166
  st.warning("No face detected.")
167
  except Exception as e:
@@ -173,6 +202,6 @@ elif choice == "View Attendance":
173
  students = get_all_students()
174
  if students:
175
  for student in students:
176
- st.write(f"Name: {student[1]}, Roll Number: {student[2]}")
177
  else:
178
  st.warning("No students registered.")
 
5
  from keras.models import load_model
6
  from PIL import Image
7
  import sqlite3
8
+ from datetime import datetime
9
  from huggingface_hub import HfApi
10
 
11
  # Constants
 
48
  id INTEGER PRIMARY KEY AUTOINCREMENT,
49
  name TEXT NOT NULL,
50
  roll_number TEXT NOT NULL UNIQUE,
51
+ image_path TEXT NOT NULL,
52
+ emotion TEXT,
53
+ timestamp TEXT
54
  )
55
  """)
56
  conn.commit()
 
64
  except sqlite3.IntegrityError:
65
  st.warning("Roll number already exists!")
66
 
67
+ def insert_attendance(roll_number, emotion):
68
+ timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
69
+ with sqlite3.connect(DB_FILE) as conn:
70
+ conn.execute("""
71
+ UPDATE students
72
+ SET emotion = ?, timestamp = ?
73
+ WHERE roll_number = ?
74
+ """, (emotion, timestamp, roll_number))
75
+ conn.commit()
76
+
77
  def get_all_students():
78
  with sqlite3.connect(DB_FILE) as conn:
79
  cursor = conn.execute("SELECT * FROM students")
 
160
  emotion_label = detect_faces_and_emotions(img_array)
161
  if emotion_label:
162
  st.success(f"Emotion Detected: {emotion_label}")
163
+ # Update the attendance
164
+ roll_number = st.text_input("Enter Roll Number for Attendance")
165
+ if st.button("Record Attendance"):
166
+ if roll_number:
167
+ insert_attendance(roll_number, emotion_label)
168
+ st.success(f"Attendance recorded for Roll No: {roll_number}")
169
+ else:
170
+ st.warning("Please enter the roll number.")
171
  else:
172
  st.warning("No face detected.")
173
  except Exception as e:
 
183
  emotion_label = detect_faces_and_emotions(img_array)
184
  if emotion_label:
185
  st.success(f"Emotion Detected: {emotion_label}")
186
+ # Update the attendance
187
+ roll_number = st.text_input("Enter Roll Number for Attendance")
188
+ if st.button("Record Attendance"):
189
+ if roll_number:
190
+ insert_attendance(roll_number, emotion_label)
191
+ st.success(f"Attendance recorded for Roll No: {roll_number}")
192
+ else:
193
+ st.warning("Please enter the roll number.")
194
  else:
195
  st.warning("No face detected.")
196
  except Exception as e:
 
202
  students = get_all_students()
203
  if students:
204
  for student in students:
205
+ st.write(f"Name: {student[1]}, Roll Number: {student[2]}, Emotion: {student[4]}, Timestamp: {student[5]}")
206
  else:
207
  st.warning("No students registered.")