Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,55 @@ import pandas as pd
|
|
| 8 |
FIREBASE_URL = st.secrets["firebase_database_url"]
|
| 9 |
FIREBASE_AUTH = st.secrets["firebase_api_key"]
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# ===============================
|
| 12 |
# Helper functions
|
| 13 |
# ===============================
|
|
@@ -19,7 +68,6 @@ def firebase_get(path):
|
|
| 19 |
except:
|
| 20 |
return None
|
| 21 |
|
| 22 |
-
|
| 23 |
def firebase_put(path, data):
|
| 24 |
url = f"{FIREBASE_URL}/{path}.json?auth={FIREBASE_AUTH}"
|
| 25 |
try:
|
|
@@ -28,54 +76,46 @@ def firebase_put(path, data):
|
|
| 28 |
except:
|
| 29 |
return None
|
| 30 |
|
| 31 |
-
|
| 32 |
-
#
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
st.sidebar.title("πProfessor Dashboard")
|
| 36 |
|
| 37 |
if "logged_in" not in st.session_state:
|
| 38 |
st.session_state.logged_in = False
|
| 39 |
|
| 40 |
if not st.session_state.logged_in:
|
| 41 |
-
st.subheader("
|
| 42 |
-
|
| 43 |
username = st.text_input("Username")
|
| 44 |
password = st.text_input("Password", type="password")
|
| 45 |
|
| 46 |
-
if st.button("Login"):
|
| 47 |
if username == "master" and password == "master":
|
| 48 |
st.session_state.logged_in = True
|
| 49 |
st.success("Login successful!")
|
| 50 |
st.rerun()
|
| 51 |
else:
|
| 52 |
st.error("Incorrect username or password")
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# ===================================================
|
| 58 |
-
# After login β Show menu
|
| 59 |
-
# ===================================================
|
| 60 |
menu = st.sidebar.selectbox("Select Mode", ["Professor Panel", "Student Evaluation"])
|
| 61 |
|
| 62 |
-
|
| 63 |
-
#
|
| 64 |
-
#
|
| 65 |
-
# ===================================================
|
| 66 |
if menu == "Professor Panel":
|
| 67 |
-
|
| 68 |
-
st.header("π«Professor Panel")
|
| 69 |
st.success("You are logged in as Professor")
|
| 70 |
-
st.subheader("Create New Quiz")
|
| 71 |
|
| 72 |
quiz_name = st.text_input("Quiz Name (Example: Quiz1)")
|
| 73 |
|
| 74 |
questions = []
|
| 75 |
-
|
| 76 |
for i in range(1, 11):
|
| 77 |
st.markdown(f"### Question {i}")
|
| 78 |
-
|
| 79 |
q_text = st.text_input(f"Question content {i}", key=f"q{i}")
|
| 80 |
|
| 81 |
options = []
|
|
@@ -83,7 +123,6 @@ if menu == "Professor Panel":
|
|
| 83 |
opt = st.text_input(f"Option {j}", key=f"q{i}_opt{j}")
|
| 84 |
options.append(opt)
|
| 85 |
|
| 86 |
-
# Correct answer chosen by TEXT
|
| 87 |
correct = st.selectbox(
|
| 88 |
f"Correct answer for Question {i} (select by text)",
|
| 89 |
options,
|
|
@@ -96,56 +135,56 @@ if menu == "Professor Panel":
|
|
| 96 |
"correct": correct
|
| 97 |
})
|
| 98 |
|
| 99 |
-
if st.button("Save Quiz"):
|
| 100 |
valid = all(q["question"] and all(q["options"]) for q in questions)
|
| 101 |
-
|
| 102 |
if not quiz_name:
|
| 103 |
st.error("Quiz name is required!")
|
| 104 |
-
|
| 105 |
elif not valid:
|
| 106 |
st.error("Please complete all questions and answers!")
|
| 107 |
-
|
| 108 |
else:
|
| 109 |
firebase_put(f"master_quizzes/{quiz_name}", {"questions": questions})
|
| 110 |
st.success(f"Quiz '{quiz_name}' saved successfully!")
|
| 111 |
|
| 112 |
-
|
| 113 |
-
# ===================================================
|
| 114 |
# STUDENT EVALUATION
|
| 115 |
-
# ===============================
|
| 116 |
elif menu == "Student Evaluation":
|
| 117 |
-
|
| 118 |
-
st.header("πStudent Evaluation")
|
| 119 |
|
| 120 |
# Refresh button
|
| 121 |
-
if st.button("
|
| 122 |
st.cache_data.clear()
|
| 123 |
st.rerun()
|
| 124 |
|
| 125 |
# Load students
|
| 126 |
students = firebase_get("student_quizzes")
|
| 127 |
-
|
| 128 |
if not students:
|
| 129 |
st.warning("No student data found.")
|
| 130 |
st.stop()
|
| 131 |
|
| 132 |
student_ids = list(students.keys())
|
| 133 |
selected_id = st.selectbox("Select Student ID", student_ids)
|
| 134 |
-
|
| 135 |
info = students[selected_id]
|
| 136 |
|
|
|
|
|
|
|
|
|
|
| 137 |
st.subheader("Student Information")
|
| 138 |
-
st.
|
| 139 |
-
st.
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
quiz_keys = [k for k in info.keys() if k.startswith("Quiz")]
|
| 143 |
-
|
| 144 |
-
# Show overview table
|
| 145 |
table_data = []
|
| 146 |
for q in quiz_keys:
|
| 147 |
qd = info[q]
|
| 148 |
-
|
| 149 |
score = qd.get("Score", "")
|
| 150 |
time = qd.get("Time", "")
|
| 151 |
fb = qd.get("Feedback", "")
|
|
@@ -158,13 +197,14 @@ elif menu == "Student Evaluation":
|
|
| 158 |
"Feedbacked": fb_status
|
| 159 |
})
|
| 160 |
|
| 161 |
-
st.subheader("Quiz Overview")
|
| 162 |
df = pd.DataFrame(table_data)
|
| 163 |
st.dataframe(df, use_container_width=True)
|
| 164 |
|
| 165 |
-
#
|
| 166 |
-
|
| 167 |
-
|
|
|
|
| 168 |
choose_quiz = st.selectbox("Select a quiz to give feedback", quiz_keys)
|
| 169 |
selected_quiz_data = info[choose_quiz]
|
| 170 |
|
|
@@ -174,7 +214,7 @@ elif menu == "Student Evaluation":
|
|
| 174 |
|
| 175 |
feedback = st.text_area("Enter new feedback")
|
| 176 |
|
| 177 |
-
if st.button("Send Feedback"):
|
| 178 |
firebase_put(f"student_quizzes/{selected_id}/{choose_quiz}/Feedback", feedback)
|
| 179 |
st.success("Feedback sent successfully!")
|
| 180 |
st.rerun()
|
|
|
|
| 8 |
FIREBASE_URL = st.secrets["firebase_database_url"]
|
| 9 |
FIREBASE_AUTH = st.secrets["firebase_api_key"]
|
| 10 |
|
| 11 |
+
# ===============================
|
| 12 |
+
# Custom CSS for UI
|
| 13 |
+
# ===============================
|
| 14 |
+
st.markdown("""
|
| 15 |
+
<style>
|
| 16 |
+
/* Sidebar title */
|
| 17 |
+
.css-1d391kg h1 {
|
| 18 |
+
font-size: 26px !important;
|
| 19 |
+
color: #2E86C1 !important;
|
| 20 |
+
font-weight: 700 !important;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
/* Rounded buttons with hover */
|
| 24 |
+
.stButton > button {
|
| 25 |
+
background-color: #2E86C1;
|
| 26 |
+
color: white;
|
| 27 |
+
border-radius: 8px;
|
| 28 |
+
padding: 10px 20px;
|
| 29 |
+
border: none;
|
| 30 |
+
transition: 0.2s;
|
| 31 |
+
font-size: 16px;
|
| 32 |
+
}
|
| 33 |
+
.stButton > button:hover {
|
| 34 |
+
background-color: #1B4F72;
|
| 35 |
+
transform: scale(1.03);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/* Rounded text inputs */
|
| 39 |
+
.stTextInput input {
|
| 40 |
+
border-radius: 8px !important;
|
| 41 |
+
padding: 8px;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/* Card-style container */
|
| 45 |
+
.card {
|
| 46 |
+
padding:15px;
|
| 47 |
+
border-radius:10px;
|
| 48 |
+
background-color:#F0F6FF;
|
| 49 |
+
margin-bottom:10px;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/* Columns spacing */
|
| 53 |
+
.block-container {
|
| 54 |
+
padding-top: 1.5rem;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
</style>
|
| 58 |
+
""", unsafe_allow_html=True)
|
| 59 |
+
|
| 60 |
# ===============================
|
| 61 |
# Helper functions
|
| 62 |
# ===============================
|
|
|
|
| 68 |
except:
|
| 69 |
return None
|
| 70 |
|
|
|
|
| 71 |
def firebase_put(path, data):
|
| 72 |
url = f"{FIREBASE_URL}/{path}.json?auth={FIREBASE_AUTH}"
|
| 73 |
try:
|
|
|
|
| 76 |
except:
|
| 77 |
return None
|
| 78 |
|
| 79 |
+
# ===============================
|
| 80 |
+
# GLOBAL LOGIN
|
| 81 |
+
# ===============================
|
| 82 |
+
st.sidebar.title("π Professor Dashboard")
|
|
|
|
| 83 |
|
| 84 |
if "logged_in" not in st.session_state:
|
| 85 |
st.session_state.logged_in = False
|
| 86 |
|
| 87 |
if not st.session_state.logged_in:
|
| 88 |
+
st.subheader("ποΈ Professor Access")
|
|
|
|
| 89 |
username = st.text_input("Username")
|
| 90 |
password = st.text_input("Password", type="password")
|
| 91 |
|
| 92 |
+
if st.button("π Login"):
|
| 93 |
if username == "master" and password == "master":
|
| 94 |
st.session_state.logged_in = True
|
| 95 |
st.success("Login successful!")
|
| 96 |
st.rerun()
|
| 97 |
else:
|
| 98 |
st.error("Incorrect username or password")
|
| 99 |
+
st.stop()
|
| 100 |
|
| 101 |
+
# ===============================
|
| 102 |
+
# MENU SELECTION
|
| 103 |
+
# ===============================
|
|
|
|
|
|
|
|
|
|
| 104 |
menu = st.sidebar.selectbox("Select Mode", ["Professor Panel", "Student Evaluation"])
|
| 105 |
|
| 106 |
+
# ===============================
|
| 107 |
+
# PROFESSOR PANEL
|
| 108 |
+
# ===============================
|
|
|
|
| 109 |
if menu == "Professor Panel":
|
| 110 |
+
st.header("π« Professor Panel")
|
|
|
|
| 111 |
st.success("You are logged in as Professor")
|
| 112 |
+
st.subheader("π Create New Quiz")
|
| 113 |
|
| 114 |
quiz_name = st.text_input("Quiz Name (Example: Quiz1)")
|
| 115 |
|
| 116 |
questions = []
|
|
|
|
| 117 |
for i in range(1, 11):
|
| 118 |
st.markdown(f"### Question {i}")
|
|
|
|
| 119 |
q_text = st.text_input(f"Question content {i}", key=f"q{i}")
|
| 120 |
|
| 121 |
options = []
|
|
|
|
| 123 |
opt = st.text_input(f"Option {j}", key=f"q{i}_opt{j}")
|
| 124 |
options.append(opt)
|
| 125 |
|
|
|
|
| 126 |
correct = st.selectbox(
|
| 127 |
f"Correct answer for Question {i} (select by text)",
|
| 128 |
options,
|
|
|
|
| 135 |
"correct": correct
|
| 136 |
})
|
| 137 |
|
| 138 |
+
if st.button("πΎ Save Quiz"):
|
| 139 |
valid = all(q["question"] and all(q["options"]) for q in questions)
|
|
|
|
| 140 |
if not quiz_name:
|
| 141 |
st.error("Quiz name is required!")
|
|
|
|
| 142 |
elif not valid:
|
| 143 |
st.error("Please complete all questions and answers!")
|
|
|
|
| 144 |
else:
|
| 145 |
firebase_put(f"master_quizzes/{quiz_name}", {"questions": questions})
|
| 146 |
st.success(f"Quiz '{quiz_name}' saved successfully!")
|
| 147 |
|
| 148 |
+
# ===============================
|
|
|
|
| 149 |
# STUDENT EVALUATION
|
| 150 |
+
# ===============================
|
| 151 |
elif menu == "Student Evaluation":
|
| 152 |
+
st.header("π Student Evaluation")
|
|
|
|
| 153 |
|
| 154 |
# Refresh button
|
| 155 |
+
if st.button("π Refresh Data"):
|
| 156 |
st.cache_data.clear()
|
| 157 |
st.rerun()
|
| 158 |
|
| 159 |
# Load students
|
| 160 |
students = firebase_get("student_quizzes")
|
|
|
|
| 161 |
if not students:
|
| 162 |
st.warning("No student data found.")
|
| 163 |
st.stop()
|
| 164 |
|
| 165 |
student_ids = list(students.keys())
|
| 166 |
selected_id = st.selectbox("Select Student ID", student_ids)
|
|
|
|
| 167 |
info = students[selected_id]
|
| 168 |
|
| 169 |
+
# ===============================
|
| 170 |
+
# Student Info Card
|
| 171 |
+
# ===============================
|
| 172 |
st.subheader("Student Information")
|
| 173 |
+
st.markdown("<div class='card'>", unsafe_allow_html=True)
|
| 174 |
+
col1, col2 = st.columns(2)
|
| 175 |
+
with col1:
|
| 176 |
+
st.write(f"**Name:** {info.get('Name', '')}")
|
| 177 |
+
with col2:
|
| 178 |
+
st.write(f"**Class:** {info.get('Class', '')}")
|
| 179 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 180 |
+
|
| 181 |
+
# ===============================
|
| 182 |
+
# Quiz Table
|
| 183 |
+
# ===============================
|
| 184 |
quiz_keys = [k for k in info.keys() if k.startswith("Quiz")]
|
|
|
|
|
|
|
| 185 |
table_data = []
|
| 186 |
for q in quiz_keys:
|
| 187 |
qd = info[q]
|
|
|
|
| 188 |
score = qd.get("Score", "")
|
| 189 |
time = qd.get("Time", "")
|
| 190 |
fb = qd.get("Feedback", "")
|
|
|
|
| 197 |
"Feedbacked": fb_status
|
| 198 |
})
|
| 199 |
|
| 200 |
+
st.subheader("π Quiz Overview")
|
| 201 |
df = pd.DataFrame(table_data)
|
| 202 |
st.dataframe(df, use_container_width=True)
|
| 203 |
|
| 204 |
+
# ===============================
|
| 205 |
+
# Feedback Section
|
| 206 |
+
# ===============================
|
| 207 |
+
st.subheader("π¬ Provide Feedback")
|
| 208 |
choose_quiz = st.selectbox("Select a quiz to give feedback", quiz_keys)
|
| 209 |
selected_quiz_data = info[choose_quiz]
|
| 210 |
|
|
|
|
| 214 |
|
| 215 |
feedback = st.text_area("Enter new feedback")
|
| 216 |
|
| 217 |
+
if st.button("π€ Send Feedback"):
|
| 218 |
firebase_put(f"student_quizzes/{selected_id}/{choose_quiz}/Feedback", feedback)
|
| 219 |
st.success("Feedback sent successfully!")
|
| 220 |
st.rerun()
|