Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,11 @@ import requests
|
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
# ===============================
|
| 6 |
-
# Firebase config
|
| 7 |
# ===============================
|
| 8 |
FIREBASE_URL = st.secrets["firebase_database_url"]
|
| 9 |
FIREBASE_AUTH = st.secrets["firebase_api_key"]
|
| 10 |
|
| 11 |
-
|
| 12 |
# ===============================
|
| 13 |
# Helper functions
|
| 14 |
# ===============================
|
|
@@ -30,40 +29,44 @@ def firebase_put(path, data):
|
|
| 30 |
return None
|
| 31 |
|
| 32 |
|
| 33 |
-
# ===============================
|
| 34 |
-
#
|
| 35 |
-
# ===============================
|
| 36 |
-
st.sidebar.title("
|
| 37 |
-
menu = st.sidebar.selectbox("Select Mode", ["Quiz Creator", "Student Evaluation"])
|
| 38 |
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
# ===============================
|
| 43 |
-
if menu == "Quiz Creator":
|
| 44 |
|
| 45 |
-
st.
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
usr = st.text_input("Username")
|
| 53 |
-
pwd = st.text_input("Password", type="password")
|
| 54 |
|
| 55 |
-
if st.button("Login"):
|
| 56 |
-
if usr == "master" and pwd == "master":
|
| 57 |
-
st.session_state.creator_login = True
|
| 58 |
-
st.success("Login successful!")
|
| 59 |
-
st.rerun()
|
| 60 |
-
else:
|
| 61 |
-
st.error("Wrong username or password")
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
st.subheader("Create New Quiz")
|
| 68 |
|
| 69 |
quiz_name = st.text_input("Quiz Name (Example: Quiz1)")
|
|
@@ -73,16 +76,16 @@ if menu == "Quiz Creator":
|
|
| 73 |
for i in range(1, 11):
|
| 74 |
st.markdown(f"### Question {i}")
|
| 75 |
|
| 76 |
-
q_text = st.text_input(f"
|
| 77 |
|
| 78 |
options = []
|
| 79 |
for j in range(1, 5):
|
| 80 |
-
opt = st.text_input(f"
|
| 81 |
options.append(opt)
|
| 82 |
|
| 83 |
# Correct answer chosen by TEXT
|
| 84 |
correct = st.selectbox(
|
| 85 |
-
f"
|
| 86 |
options,
|
| 87 |
key=f"q{i}_correct"
|
| 88 |
)
|
|
@@ -97,25 +100,25 @@ if menu == "Quiz Creator":
|
|
| 97 |
valid = all(q["question"] and all(q["options"]) for q in questions)
|
| 98 |
|
| 99 |
if not quiz_name:
|
| 100 |
-
st.error("Quiz name required!")
|
| 101 |
|
| 102 |
elif not valid:
|
| 103 |
-
st.error("
|
| 104 |
|
| 105 |
else:
|
| 106 |
firebase_put(f"master_quizzes/{quiz_name}", {"questions": questions})
|
| 107 |
st.success(f"Quiz '{quiz_name}' saved successfully!")
|
| 108 |
|
| 109 |
|
| 110 |
-
# ===============================
|
| 111 |
# STUDENT EVALUATION
|
| 112 |
-
# ===============================
|
| 113 |
elif menu == "Student Evaluation":
|
| 114 |
|
| 115 |
-
st.header("Student Evaluation")
|
| 116 |
|
| 117 |
-
#
|
| 118 |
-
if st.button("
|
| 119 |
st.cache_data.clear()
|
| 120 |
st.rerun()
|
| 121 |
|
|
@@ -126,20 +129,19 @@ elif menu == "Student Evaluation":
|
|
| 126 |
st.warning("No student data found.")
|
| 127 |
st.stop()
|
| 128 |
|
| 129 |
-
# List of student IDs
|
| 130 |
student_ids = list(students.keys())
|
| 131 |
-
|
| 132 |
selected_id = st.selectbox("Select Student ID", student_ids)
|
|
|
|
| 133 |
info = students[selected_id]
|
| 134 |
|
| 135 |
st.subheader("Student Information")
|
| 136 |
st.write(f"**Name:** {info.get('Name', '')}")
|
| 137 |
st.write(f"**Class:** {info.get('Class', '')}")
|
| 138 |
|
| 139 |
-
#
|
| 140 |
quiz_keys = [k for k in info.keys() if k.startswith("Quiz")]
|
| 141 |
|
| 142 |
-
#
|
| 143 |
table_data = []
|
| 144 |
for q in quiz_keys:
|
| 145 |
qd = info[q]
|
|
@@ -156,24 +158,23 @@ elif menu == "Student Evaluation":
|
|
| 156 |
"Feedbacked": fb_status
|
| 157 |
})
|
| 158 |
|
| 159 |
-
st.subheader("Quiz Overview
|
| 160 |
df = pd.DataFrame(table_data)
|
| 161 |
st.dataframe(df, use_container_width=True)
|
| 162 |
|
| 163 |
-
#
|
| 164 |
-
st.subheader("Feedback")
|
| 165 |
|
| 166 |
-
choose_quiz = st.selectbox("Select quiz to feedback", quiz_keys)
|
| 167 |
selected_quiz_data = info[choose_quiz]
|
| 168 |
|
| 169 |
-
# Show existing feedback
|
| 170 |
existing_fb = selected_quiz_data.get("Feedback", "")
|
| 171 |
if existing_fb:
|
| 172 |
-
st.info(f"📌 Existing
|
| 173 |
|
| 174 |
feedback = st.text_area("Enter new feedback")
|
| 175 |
|
| 176 |
if st.button("Send Feedback"):
|
| 177 |
firebase_put(f"student_quizzes/{selected_id}/{choose_quiz}/Feedback", feedback)
|
| 178 |
st.success("Feedback sent successfully!")
|
| 179 |
-
st.rerun()
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
# ===============================
|
| 6 |
+
# Firebase config from secrets.toml
|
| 7 |
# ===============================
|
| 8 |
FIREBASE_URL = st.secrets["firebase_database_url"]
|
| 9 |
FIREBASE_AUTH = st.secrets["firebase_api_key"]
|
| 10 |
|
|
|
|
| 11 |
# ===============================
|
| 12 |
# Helper functions
|
| 13 |
# ===============================
|
|
|
|
| 29 |
return None
|
| 30 |
|
| 31 |
|
| 32 |
+
# ===================================================
|
| 33 |
+
# GLOBAL LOGIN (applies to all roles)
|
| 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("🔐 Login Required")
|
|
|
|
|
|
|
| 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 |
+
st.stop() # stop everything until login is completed
|
|
|
|
|
|
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# ===================================================
|
| 58 |
+
# After login → Show menu
|
| 59 |
+
# ===================================================
|
| 60 |
+
menu = st.sidebar.selectbox("Select Mode", ["Professor Panel", "Student Evaluation"])
|
| 61 |
|
| 62 |
+
|
| 63 |
+
# ===================================================
|
| 64 |
+
# PROFESSOR PANEL (Quiz Creator)
|
| 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)")
|
|
|
|
| 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 = []
|
| 82 |
for j in range(1, 5):
|
| 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,
|
| 90 |
key=f"q{i}_correct"
|
| 91 |
)
|
|
|
|
| 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("🌀Refresh Data🌀"):
|
| 122 |
st.cache_data.clear()
|
| 123 |
st.rerun()
|
| 124 |
|
|
|
|
| 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.write(f"**Name:** {info.get('Name', '')}")
|
| 139 |
st.write(f"**Class:** {info.get('Class', '')}")
|
| 140 |
|
| 141 |
+
# Identify quizzes
|
| 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]
|
|
|
|
| 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 |
+
# Feedback section
|
| 166 |
+
st.subheader("Provide Feedback")
|
| 167 |
|
| 168 |
+
choose_quiz = st.selectbox("Select a quiz to give feedback", quiz_keys)
|
| 169 |
selected_quiz_data = info[choose_quiz]
|
| 170 |
|
|
|
|
| 171 |
existing_fb = selected_quiz_data.get("Feedback", "")
|
| 172 |
if existing_fb:
|
| 173 |
+
st.info(f"📌 Existing Feedback:\n\n{existing_fb}")
|
| 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()
|