Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,10 @@ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
|
10 |
os.makedirs(DATABASE_DIR, exist_ok=True)
|
11 |
attendance_system = AttendanceSystem(DATABASE_DIR)
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# Streamlit application
|
14 |
st.title("Attendance System")
|
15 |
|
@@ -33,26 +37,23 @@ st.subheader("Record Attendance")
|
|
33 |
attendance_date = st.date_input("Select Date", key="attendance_date")
|
34 |
image_file = st.file_uploader("Upload Image for Attendance", type=['jpg', 'png', 'jpeg'], key="attendance_image_uploader")
|
35 |
|
36 |
-
# Initialize present_students outside the button condition
|
37 |
-
present_students = []
|
38 |
-
|
39 |
if st.button("Take Attendance"):
|
40 |
if image_file is not None and selected_course and attendance_date:
|
41 |
image_path = os.path.join(UPLOAD_FOLDER, image_file.name)
|
42 |
with open(image_path, "wb") as f:
|
43 |
f.write(image_file.getbuffer())
|
44 |
-
present_students = attendance_system.record_attendance(selected_course, attendance_date, image_path)
|
45 |
-
st.write(present_students)
|
46 |
# Display the count of present students
|
47 |
-
length = len(present_students)
|
48 |
-
ty = type(present_students).__name__ # Get the name of the type as a string
|
49 |
st.success(f"{length} students' attendance completed successfully.")
|
50 |
-
st.json(present_students)
|
51 |
|
52 |
if st.button("Mark Attendance"):
|
53 |
-
if present_students:
|
54 |
# Convert present_students to integers
|
55 |
-
present_students_int = [int(student) for student in present_students]
|
56 |
csv_contents = record_attendance_new(present_students_int, selected_course)
|
57 |
st.success("Attendance marked successfully")
|
58 |
|
|
|
10 |
os.makedirs(DATABASE_DIR, exist_ok=True)
|
11 |
attendance_system = AttendanceSystem(DATABASE_DIR)
|
12 |
|
13 |
+
# Initialize session state
|
14 |
+
if 'present_students' not in st.session_state:
|
15 |
+
st.session_state.present_students = []
|
16 |
+
|
17 |
# Streamlit application
|
18 |
st.title("Attendance System")
|
19 |
|
|
|
37 |
attendance_date = st.date_input("Select Date", key="attendance_date")
|
38 |
image_file = st.file_uploader("Upload Image for Attendance", type=['jpg', 'png', 'jpeg'], key="attendance_image_uploader")
|
39 |
|
|
|
|
|
|
|
40 |
if st.button("Take Attendance"):
|
41 |
if image_file is not None and selected_course and attendance_date:
|
42 |
image_path = os.path.join(UPLOAD_FOLDER, image_file.name)
|
43 |
with open(image_path, "wb") as f:
|
44 |
f.write(image_file.getbuffer())
|
45 |
+
st.session_state.present_students = attendance_system.record_attendance(selected_course, attendance_date, image_path)
|
46 |
+
st.write(st.session_state.present_students)
|
47 |
# Display the count of present students
|
48 |
+
length = len(st.session_state.present_students)
|
49 |
+
ty = type(st.session_state.present_students).__name__ # Get the name of the type as a string
|
50 |
st.success(f"{length} students' attendance completed successfully.")
|
51 |
+
st.json(st.session_state.present_students)
|
52 |
|
53 |
if st.button("Mark Attendance"):
|
54 |
+
if st.session_state.present_students:
|
55 |
# Convert present_students to integers
|
56 |
+
present_students_int = [int(student) for student in st.session_state.present_students]
|
57 |
csv_contents = record_attendance_new(present_students_int, selected_course)
|
58 |
st.success("Attendance marked successfully")
|
59 |
|