Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import datetime
|
| 4 |
|
| 5 |
-
# Initialize
|
| 6 |
if 'attendance_df' not in st.session_state:
|
| 7 |
st.session_state.attendance_df = pd.DataFrame(columns=["Student ID", "Name", "Date", "Time"])
|
| 8 |
|
|
@@ -19,19 +19,25 @@ with st.sidebar.form("attendance_form"):
|
|
| 19 |
submit_button = st.form_submit_button("Mark Attendance")
|
| 20 |
|
| 21 |
# If the form is submitted, log attendance
|
| 22 |
-
if submit_button
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
# Admin Section to view attendance records
|
| 37 |
if st.sidebar.checkbox("Show Attendance Records"):
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import datetime
|
| 4 |
|
| 5 |
+
# Initialize session state if not already initialized
|
| 6 |
if 'attendance_df' not in st.session_state:
|
| 7 |
st.session_state.attendance_df = pd.DataFrame(columns=["Student ID", "Name", "Date", "Time"])
|
| 8 |
|
|
|
|
| 19 |
submit_button = st.form_submit_button("Mark Attendance")
|
| 20 |
|
| 21 |
# If the form is submitted, log attendance
|
| 22 |
+
if submit_button:
|
| 23 |
+
if student_id and student_name:
|
| 24 |
+
current_time = datetime.datetime.now().strftime("%H:%M:%S")
|
| 25 |
+
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
|
| 26 |
+
|
| 27 |
+
# Create a DataFrame for the new attendance entry
|
| 28 |
+
new_data = pd.DataFrame({
|
| 29 |
+
"Student ID": [student_id],
|
| 30 |
+
"Name": [student_name],
|
| 31 |
+
"Date": [current_date],
|
| 32 |
+
"Time": [current_time]
|
| 33 |
+
})
|
| 34 |
+
|
| 35 |
+
# Concatenate the new data to the existing attendance DataFrame
|
| 36 |
+
st.session_state.attendance_df = pd.concat([st.session_state.attendance_df, new_data], ignore_index=True)
|
| 37 |
+
|
| 38 |
+
st.sidebar.success(f"Attendance marked for {student_name} ({student_id}) at {current_time}")
|
| 39 |
+
else:
|
| 40 |
+
st.sidebar.warning("Please enter both Student ID and Name.")
|
| 41 |
|
| 42 |
# Admin Section to view attendance records
|
| 43 |
if st.sidebar.checkbox("Show Attendance Records"):
|