Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import os | |
| from attendance_system import AttendanceSystem | |
| from record_attendance import record_attendance_new | |
| # Configuration | |
| UPLOAD_FOLDER = 'uploads' | |
| DATABASE_DIR = 'database' | |
| os.makedirs(UPLOAD_FOLDER, exist_ok=True) | |
| os.makedirs(DATABASE_DIR, exist_ok=True) | |
| attendance_system = AttendanceSystem(DATABASE_DIR) | |
| # Streamlit application | |
| st.title("Attendance System") | |
| # Index page | |
| st.subheader("Select Course to View or Upload Files") | |
| # Display available courses | |
| courses = ["RL", "OT", "CLOUD", "NLP"] | |
| selected_course = st.selectbox("Choose a Course", courses) | |
| # File upload section | |
| uploaded_file = st.file_uploader("Upload Attendance File", type=['csv']) | |
| if uploaded_file is not None: | |
| file_path = os.path.join(UPLOAD_FOLDER, f"{selected_course}.csv") | |
| with open(file_path, "wb") as f: | |
| f.write(uploaded_file.getbuffer()) | |
| st.success(f"{selected_course}.csv File uploaded successfully") | |
| # Take Attendance | |
| st.subheader("Record Attendance") | |
| attendance_date = st.date_input("Select Date") | |
| image_file = st.file_uploader("Upload Image for Attendance", type=['jpg', 'png', 'jpeg']) | |
| # Initialize present_students outside the button condition | |
| present_students = [] | |
| if st.button("Take Attendance"): | |
| if image_file is not None and selected_course and attendance_date: | |
| image_path = os.path.join(UPLOAD_FOLDER, image_file.name) | |
| with open(image_path, "wb") as f: | |
| f.write(image_file.getbuffer()) | |
| present_students = attendance_system.record_attendance(selected_course, attendance_date, image_path) | |
| # Display the count of present students | |
| length = len(present_students) | |
| ty = type(present_students).__name__ # Get the name of the type as a string | |
| st.success(f"{length} students' attendance completed successfully. This is a {ty}.") | |
| st.json(present_students) | |
| # Mark attendance section | |
| st.subheader("Mark Attendance") | |
| # Define the possible roll numbers | |
| roll_numbers = [str(i) for i in range(1, 27)] # Roll numbers 1 to 26 | |
| # Allow user to select roll numbers to add manually | |
| selected_roll_numbers = st.multiselect("Select Roll Numbers to Add", options=roll_numbers) | |
| # Display the selected roll numbers | |
| if selected_roll_numbers: | |
| st.write("Selected Roll Numbers to Add:", selected_roll_numbers) | |
| # Combine the present students with the selected roll numbers | |
| combined_students = list(set(present_students) | set(selected_roll_numbers)) # Remove duplicates | |
| # Optionally, show final list of students | |
| st.write("Final List of Present Students:", combined_students) | |
| if st.button("Mark Attendance"): | |
| record_attendance_new(combined_students, selected_course) | |
| st.success("Attendance marked successfully") | |
| # Add to database | |
| st.subheader("Add Student to Database") | |
| roll_number = st.text_input("Enter Roll Number") | |
| database_file = st.file_uploader("Upload Student Image", type=['jpg', 'png']) | |
| if st.button("Add to Database"): | |
| if database_file is not None and roll_number: | |
| db_image_path = os.path.join(DATABASE_DIR, f"{roll_number}.jpg") | |
| with open(db_image_path, "wb") as f: | |
| f.write(database_file.getbuffer()) | |
| attendance_system.add_to_database(roll_number, db_image_path) | |
| st.success("Image added to database successfully") | |