DigitalTransG2 commited on
Commit
58fc54f
Β·
verified Β·
1 Parent(s): fb81701

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -70
app.py CHANGED
@@ -9,51 +9,44 @@ 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
 
@@ -76,40 +69,41 @@ def firebase_put(path, data):
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
 
@@ -123,6 +117,7 @@ if menu == "Professor Panel":
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,
@@ -137,6 +132,7 @@ if menu == "Professor Panel":
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:
@@ -145,19 +141,20 @@ if menu == "Professor Panel":
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()
@@ -166,22 +163,14 @@ elif menu == "Student Evaluation":
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]
@@ -189,7 +178,6 @@ elif menu == "Student Evaluation":
189
  time = qd.get("Time", "")
190
  fb = qd.get("Feedback", "")
191
  fb_status = "Yes" if fb else "No"
192
-
193
  table_data.append({
194
  "Quiz": q,
195
  "Score": score,
@@ -197,14 +185,13 @@ elif menu == "Student Evaluation":
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,7 +201,7 @@ elif menu == "Student Evaluation":
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()
 
9
  FIREBASE_AUTH = st.secrets["firebase_api_key"]
10
 
11
  # ===============================
12
+ # CSS for better UI
13
  # ===============================
14
  st.markdown("""
15
  <style>
16
+ /* Push content down to avoid top bar overlap */
17
+ .block-container {
18
+ padding-top: 80px;
19
+ padding-left: 30px;
20
+ padding-right: 30px;
21
  }
22
 
23
+ /* Style headers */
24
+ h2 {
25
+ color: #2E86AB;
 
 
 
 
 
 
 
 
 
 
26
  }
27
 
28
+ h3 {
29
+ color: #117A65;
 
 
30
  }
31
 
32
+ /* Style buttons */
33
+ .stButton>button {
34
+ background-color: #117A65;
35
+ color: white;
36
+ border-radius: 8px;
37
+ padding: 0.4em 1em;
38
+ font-weight: bold;
39
  }
40
+ .stButton>button:hover {
41
+ background-color: #0D5C48;
 
 
42
  }
43
 
44
+ /* Style text areas */
45
+ textarea {
46
+ border-radius: 8px;
47
+ border: 1px solid #117A65;
48
+ padding: 5px;
49
+ }
50
  </style>
51
  """, unsafe_allow_html=True)
52
 
 
69
  except:
70
  return None
71
 
72
+ # ===================================================
73
+ # GLOBAL LOGIN (applies to all roles)
74
+ # ===================================================
75
  st.sidebar.title("πŸŽ“ Professor Dashboard")
76
 
77
  if "logged_in" not in st.session_state:
78
  st.session_state.logged_in = False
79
 
80
  if not st.session_state.logged_in:
81
+ st.markdown("<h2>πŸ—οΈ Professor Access</h2>", unsafe_allow_html=True)
82
+
83
  username = st.text_input("Username")
84
  password = st.text_input("Password", type="password")
85
 
86
+ if st.button("Login"):
87
  if username == "master" and password == "master":
88
  st.session_state.logged_in = True
89
  st.success("Login successful!")
90
  st.rerun()
91
  else:
92
  st.error("Incorrect username or password")
93
+ st.stop() # stop everything until login is completed
94
 
95
+ # ===================================================
96
+ # After login β†’ Show menu
97
+ # ===================================================
98
  menu = st.sidebar.selectbox("Select Mode", ["Professor Panel", "Student Evaluation"])
99
 
100
+ # ===================================================
101
+ # PROFESSOR PANEL (Quiz Creator)
102
+ # ===================================================
103
  if menu == "Professor Panel":
104
  st.header("🏫 Professor Panel")
105
  st.success("You are logged in as Professor")
106
+ st.subheader("Create New Quiz")
107
 
108
  quiz_name = st.text_input("Quiz Name (Example: Quiz1)")
109
 
 
117
  opt = st.text_input(f"Option {j}", key=f"q{i}_opt{j}")
118
  options.append(opt)
119
 
120
+ # Correct answer chosen by TEXT
121
  correct = st.selectbox(
122
  f"Correct answer for Question {i} (select by text)",
123
  options,
 
132
 
133
  if st.button("πŸ’Ύ Save Quiz"):
134
  valid = all(q["question"] and all(q["options"]) for q in questions)
135
+
136
  if not quiz_name:
137
  st.error("Quiz name is required!")
138
  elif not valid:
 
141
  firebase_put(f"master_quizzes/{quiz_name}", {"questions": questions})
142
  st.success(f"Quiz '{quiz_name}' saved successfully!")
143
 
144
+ # ===================================================
145
  # STUDENT EVALUATION
146
+ # ===================================================
147
  elif menu == "Student Evaluation":
148
  st.header("πŸ“Š Student Evaluation")
149
 
150
  # Refresh button
151
+ if st.button("πŸ”„ Refresh Data"):
152
  st.cache_data.clear()
153
  st.rerun()
154
 
155
  # Load students
156
  students = firebase_get("student_quizzes")
157
+
158
  if not students:
159
  st.warning("No student data found.")
160
  st.stop()
 
163
  selected_id = st.selectbox("Select Student ID", student_ids)
164
  info = students[selected_id]
165
 
 
 
 
166
  st.subheader("Student Information")
167
+ st.write(f"**Name:** {info.get('Name', '')}")
168
+ st.write(f"**Class:** {info.get('Class', '')}")
169
+
170
+ # Identify quizzes
 
 
 
 
 
 
 
171
  quiz_keys = [k for k in info.keys() if k.startswith("Quiz")]
172
+
173
+ # Show overview table
174
  table_data = []
175
  for q in quiz_keys:
176
  qd = info[q]
 
178
  time = qd.get("Time", "")
179
  fb = qd.get("Feedback", "")
180
  fb_status = "Yes" if fb else "No"
 
181
  table_data.append({
182
  "Quiz": q,
183
  "Score": score,
 
185
  "Feedbacked": fb_status
186
  })
187
 
188
+ st.subheader("Quiz Overview")
189
  df = pd.DataFrame(table_data)
190
  st.dataframe(df, use_container_width=True)
191
 
192
+ # Feedback section
193
+ st.subheader("Provide Feedback")
194
+
 
195
  choose_quiz = st.selectbox("Select a quiz to give feedback", quiz_keys)
196
  selected_quiz_data = info[choose_quiz]
197
 
 
201
 
202
  feedback = st.text_area("Enter new feedback")
203
 
204
+ if st.button("πŸ“¨ Send Feedback"):
205
  firebase_put(f"student_quizzes/{selected_id}/{choose_quiz}/Feedback", feedback)
206
  st.success("Feedback sent successfully!")
207
  st.rerun()