Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -34,50 +34,48 @@ st.subheader("Record Attendance")
|
|
34 |
attendance_date = st.date_input("Select Date")
|
35 |
image_file = st.file_uploader("Upload Image for Attendance", type=['jpg', 'png', 'jpeg'])
|
36 |
|
37 |
-
# Initialize present_students outside the button condition
|
38 |
-
present_students = []
|
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 |
-
present_students = attendance_system.record_attendance(selected_course, attendance_date, image_path)
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
# Define the possible roll numbers
|
57 |
-
roll_numbers = [str(i) for i in range(1, 27)] # Roll numbers 1 to 26
|
58 |
-
# Allow user to select roll numbers to add manually
|
59 |
-
selected_roll_numbers = st.multiselect("Select Roll Numbers to Add", options=roll_numbers)
|
60 |
-
|
61 |
-
# Display the selected roll numbers
|
62 |
-
if selected_roll_numbers:
|
63 |
-
st.write("Selected Roll Numbers to Add:", selected_roll_numbers)
|
64 |
-
# Combine the present students with the selected roll numbers
|
65 |
-
present_students_str = [str(student) for student in present_students]
|
66 |
-
length = len(present_students_str)
|
67 |
-
if present_students_str:
|
68 |
-
ty = type(present_students_str[0]).__name__
|
69 |
-
else:
|
70 |
-
ty = "No students present_students_str"
|
71 |
-
st.success(f"{length} students' attendance list is now list of roll number {ty}.")
|
72 |
-
combined_students = [combined_students.append(i) for i in selected_roll_numbers] # Remove duplicates
|
73 |
-
|
74 |
-
# Optionally, show final list of students
|
75 |
-
st.write("Final List of Present Students:", combined_students)
|
76 |
-
|
77 |
-
if st.button("Mark Attendance"):
|
78 |
-
record_attendance_new(combined_students, selected_course)
|
79 |
-
st.success("Attendance marked successfully")
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# Add to database
|
82 |
st.subheader("Add Student to Database")
|
83 |
roll_number = st.text_input("Enter Roll Number")
|
|
|
34 |
attendance_date = st.date_input("Select Date")
|
35 |
image_file = st.file_uploader("Upload Image for Attendance", type=['jpg', 'png', 'jpeg'])
|
36 |
|
37 |
+
# Initialize present_students outside the button condition
|
38 |
+
present_students = []
|
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 |
+
present_students = attendance_system.record_attendance(selected_course, attendance_date, image_path)
|
46 |
+
|
47 |
+
# Display the count of present students
|
48 |
+
length = len(present_students)
|
49 |
+
ty = type(present_students).__name__ # Get the name of the type as a string
|
50 |
+
st.success(f"{length} students' attendance completed successfully. This is a {ty}.")
|
51 |
+
st.json(present_students)
|
52 |
+
|
53 |
+
# Mark attendance section
|
54 |
+
st.subheader("Mark Attendance")
|
55 |
+
|
56 |
+
# Define the possible roll numbers
|
57 |
+
roll_numbers = [str(i) for i in range(1, 27)] # Roll numbers 1 to 26
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
+
# Allow user to select roll numbers to add manually
|
60 |
+
selected_roll_numbers = st.multiselect("Select Roll Numbers to Add", options=roll_numbers)
|
61 |
+
|
62 |
+
# Display the selected roll numbers
|
63 |
+
if selected_roll_numbers:
|
64 |
+
st.write("Selected Roll Numbers to Add:", selected_roll_numbers)
|
65 |
+
|
66 |
+
# Combine the present students with the selected roll numbers
|
67 |
+
present_students_str = [str(student) for student in present_students]
|
68 |
+
combined_students = list(set(present_students_str) | set(selected_roll_numbers))
|
69 |
+
|
70 |
+
# Optionally, show final list of students
|
71 |
+
st.write("Final List of Present Students:", combined_students)
|
72 |
+
st.success(f"{len(combined_students)} students' attendance after combining automatic and manual lists.")
|
73 |
+
|
74 |
+
if st.button("Mark Attendance"):
|
75 |
+
# Convert combined_students back to integers for record_attendance_new function
|
76 |
+
combined_students_int = [int(student) for student in combined_students]
|
77 |
+
record_attendance_new(combined_students_int, selected_course)
|
78 |
+
st.success("Attendance marked successfully")
|
79 |
# Add to database
|
80 |
st.subheader("Add Student to Database")
|
81 |
roll_number = st.text_input("Enter Roll Number")
|