Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,22 +33,43 @@ present_students = []
|
|
33 |
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 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
#
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
#
|
51 |
-
|
52 |
|
53 |
# Define the possible roll numbers
|
54 |
roll_numbers = [str(i) for i in range(1, 27)] # Roll numbers 1 to 26
|
@@ -59,22 +80,34 @@ selected_roll_numbers = st.multiselect("Select Roll Numbers to Add", options=rol
|
|
59 |
# Display the selected roll numbers
|
60 |
if selected_roll_numbers:
|
61 |
st.write("Selected Roll Numbers to Add:", selected_roll_numbers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
|
|
|
|
63 |
# Combine the present students with the selected roll numbers
|
64 |
-
present_students_str = [str(student) for student in
|
65 |
-
combined_students = list(set(present_students_str) | set(selected_roll_numbers))
|
66 |
-
|
67 |
# Optionally, show final list of students
|
68 |
-
st.write("Final List of Present Students:", combined_students)
|
69 |
-
st.success(f"{len(combined_students)} students' attendance after combining automatic and manual lists.")
|
70 |
|
71 |
-
if st.button("Mark Attendance"):
|
72 |
# Convert combined_students back to integers for record_attendance_new function
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
st.success(f"{len(combined_students_int)} students' roll number is going to record. Students present in combined_student: {combined_students_int}")
|
77 |
-
|
78 |
# Add to database
|
79 |
st.subheader("Add Student to Database")
|
80 |
roll_number = st.text_input("Enter Roll Number")
|
|
|
33 |
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 |
+
import os
|
37 |
+
from attendance_system import AttendanceSystem
|
38 |
+
from record_attendance import record_attendance_new
|
39 |
+
import streamlit as st
|
40 |
|
41 |
+
# Configuration
|
42 |
+
UPLOAD_FOLDER = 'uploads'
|
43 |
+
DATABASE_DIR = 'database'
|
44 |
+
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
45 |
+
os.makedirs(DATABASE_DIR, exist_ok=True)
|
46 |
+
attendance_system = AttendanceSystem(DATABASE_DIR)
|
47 |
+
|
48 |
+
# Streamlit application
|
49 |
+
st.title("Attendance System")
|
50 |
+
|
51 |
+
# Index page
|
52 |
+
st.subheader("Select Course to View or Upload Files")
|
53 |
+
|
54 |
+
# Display available courses
|
55 |
+
courses = ["RL", "OT", "CLOUD"]
|
56 |
+
selected_course = st.selectbox("Choose a Course", courses)
|
57 |
+
|
58 |
+
# File upload section
|
59 |
+
uploaded_file = st.file_uploader("Upload Attendance File", type=['csv'])
|
60 |
+
if uploaded_file is not None:
|
61 |
+
file_path = os.path.join(UPLOAD_FOLDER, f"{selected_course}.csv")
|
62 |
+
with open(file_path, "wb") as f:
|
63 |
+
f.write(uploaded_file.getbuffer())
|
64 |
+
st.success(f"{selected_course}.csv File uploaded successfully")
|
65 |
+
|
66 |
+
# Take Attendance
|
67 |
+
st.subheader("Record Attendance")
|
68 |
+
attendance_date = st.date_input("Select Date")
|
69 |
+
image_file = st.file_uploader("Upload Image for Attendance", type=['jpg', 'png', 'jpeg'])
|
70 |
|
71 |
+
# Initialize present_students outside the button condition
|
72 |
+
present_students = []
|
73 |
|
74 |
# Define the possible roll numbers
|
75 |
roll_numbers = [str(i) for i in range(1, 27)] # Roll numbers 1 to 26
|
|
|
80 |
# Display the selected roll numbers
|
81 |
if selected_roll_numbers:
|
82 |
st.write("Selected Roll Numbers to Add:", selected_roll_numbers)
|
83 |
+
|
84 |
+
if st.button("Take Attendance"):
|
85 |
+
if image_file is not None and selected_course and attendance_date:
|
86 |
+
image_path = os.path.join(UPLOAD_FOLDER, image_file.name)
|
87 |
+
with open(image_path, "wb") as f:
|
88 |
+
f.write(image_file.getbuffer())
|
89 |
+
present_students = attendance_system.record_attendance(selected_course, attendance_date, image_path)
|
90 |
+
st.write(present_students)
|
91 |
+
# Display the count of present students
|
92 |
+
length = len(present_students)
|
93 |
+
ty = type(present_students).__name__ # Get the name of the type as a string
|
94 |
+
st.success(f"{length} students' attendance completed successfully. This is a {ty}.")
|
95 |
+
st.json(present_students)
|
96 |
|
97 |
+
# Mark attendance section
|
98 |
+
st.subheader("Mark Attendance")
|
99 |
# Combine the present students with the selected roll numbers
|
100 |
+
present_students_str = [str(student) for student in present_students]
|
101 |
+
combined_students = list(set(present_students_str) | set(selected_roll_numbers))
|
|
|
102 |
# Optionally, show final list of students
|
103 |
+
st.write("Final List of Present Students:", combined_students)
|
104 |
+
st.success(f"{len(combined_students)} students' attendance after combining automatic and manual lists.")
|
105 |
|
106 |
+
if st.button("Mark Attendance"):
|
107 |
# Convert combined_students back to integers for record_attendance_new function
|
108 |
+
combined_students_int = [int(student) for student in combined_students]
|
109 |
+
record_attendance_new(combined_students_int, selected_course)
|
110 |
+
st.success("Attendance marked successfully")
|
|
|
|
|
111 |
# Add to database
|
112 |
st.subheader("Add Student to Database")
|
113 |
roll_number = st.text_input("Enter Roll Number")
|