Deevyankar commited on
Commit
dc27ad9
·
verified ·
1 Parent(s): bd9344d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -413
src/streamlit_app.py CHANGED
@@ -1,220 +1,13 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import os
4
- from io import BytesIO
5
- from datetime import datetime
6
 
7
- st.set_page_config(
8
- page_title="Specialization Allocation System",
9
- layout="wide"
10
- )
11
-
12
- st.markdown("""
13
- <style>
14
- .stApp {
15
- background: linear-gradient(135deg, #f4f8fc 0%, #e8f1f8 100%);
16
- }
17
- .hero {
18
- background: linear-gradient(90deg, #123c7c 0%, #1f5aa6 70%, #f58220 100%);
19
- padding: 30px;
20
- border-radius: 22px;
21
- color: white;
22
- margin-bottom: 28px;
23
- }
24
- .logo-badge {
25
- background: white;
26
- color: #123c7c;
27
- padding: 10px 18px;
28
- border-radius: 14px;
29
- display: inline-block;
30
- font-weight: 800;
31
- font-size: 20px;
32
- margin-bottom: 12px;
33
- }
34
- .main-title {
35
- font-size: 42px;
36
- font-weight: 850;
37
- }
38
- .subtitle {
39
- font-size: 20px;
40
- color: #f4f4f4;
41
- }
42
- .info-box {
43
- background-color: white;
44
- padding: 24px;
45
- border-radius: 18px;
46
- border-left: 8px solid #f58220;
47
- box-shadow: 0px 4px 14px rgba(0,0,0,0.10);
48
- margin-bottom: 20px;
49
- color: #111;
50
- }
51
- .admin-box {
52
- background-color: #123c7c;
53
- color: white;
54
- padding: 22px;
55
- border-radius: 18px;
56
- margin-bottom: 16px;
57
- }
58
- .choice-box {
59
- background-color: white;
60
- padding: 20px;
61
- border-radius: 18px;
62
- border-left: 8px solid #123c7c;
63
- box-shadow: 0px 4px 14px rgba(0,0,0,0.10);
64
- color: #111;
65
- }
66
- h1, h2, h3 {
67
- color: #123c7c !important;
68
- font-weight: 800 !important;
69
- }
70
- label, p, li {
71
- color: #111 !important;
72
- font-size: 16px !important;
73
- }
74
- .stTextInput input {
75
- background-color: white !important;
76
- color: black !important;
77
- border-radius: 10px !important;
78
- }
79
- .stButton>button {
80
- background-color: #f58220;
81
- color: white;
82
- border-radius: 12px;
83
- height: 48px;
84
- font-size: 17px;
85
- font-weight: bold;
86
- border: none;
87
- }
88
- .stButton>button:hover {
89
- background-color: #123c7c;
90
- }
91
- </style>
92
- """, unsafe_allow_html=True)
93
-
94
- BASE_DIR = os.path.dirname(__file__)
95
- excel_path = os.path.join(BASE_DIR, "For Specialisation.xlsx")
96
- csv_file = os.path.join(BASE_DIR, "submissions.csv")
97
-
98
- if os.path.exists(excel_path):
99
- df_students = pd.read_excel(excel_path)
100
- else:
101
- st.error("Excel file not found. Please upload For Specialisation.xlsx")
102
- st.stop()
103
-
104
- all_choices = [
105
- "Civil Engineering (Baccalaureate level)",
106
- "Architectural Engineering (Baccalaureate level)",
107
- "Quantity Surveying & Cost Estimation (Baccalaureate level)",
108
- "Mechanical Engineering (Baccalaureate level)",
109
- "Chemical Engineering (Baccalaureate level)",
110
- "Heating Ventilation & Air Conditioning (Diploma level)",
111
- "Oil and Gas (Diploma level)",
112
- "Electrical Power Engineering (Baccalaureate level)",
113
- "Electronics and Telecommunication Engineering (Baccalaureate level)",
114
- "Computer Engineering (Baccalaureate level)"
115
- ]
116
-
117
- female_choices = [
118
- choice for choice in all_choices
119
- if "Heating Ventilation" not in choice
120
- ]
121
-
122
- def convert_df_to_excel(df):
123
- output = BytesIO()
124
- with pd.ExcelWriter(output, engine="openpyxl") as writer:
125
- df.to_excel(writer, index=False, sheet_name="Student Choices")
126
- output.seek(0)
127
- return output
128
-
129
- def create_acknowledgement_html(student_id, name, advisor, gender, phone, choices):
130
- choice_rows = ""
131
- for i, choice in enumerate(choices, start=1):
132
- choice_rows += f"""
133
- <tr>
134
- <td>Choice {i}</td>
135
- <td>{choice}</td>
136
- </tr>
137
- """
138
-
139
- html = f"""
140
- <!DOCTYPE html>
141
- <html>
142
- <head>
143
- <meta charset="UTF-8">
144
- <title>Specialization Acknowledgement</title>
145
- <style>
146
- body {{
147
- font-family: Arial, sans-serif;
148
- background-color: #f4f8fc;
149
- padding: 30px;
150
- color: #111;
151
- }}
152
- .container {{
153
- background: white;
154
- padding: 30px;
155
- border-radius: 14px;
156
- border-top: 10px solid #123c7c;
157
- max-width: 850px;
158
- margin: auto;
159
- }}
160
- h1 {{
161
- color: #123c7c;
162
- text-align: center;
163
- }}
164
- h3 {{
165
- color: #f58220;
166
- }}
167
- table {{
168
- width: 100%;
169
- border-collapse: collapse;
170
- margin-top: 20px;
171
- }}
172
- td, th {{
173
- border: 1px solid #ccc;
174
- padding: 10px;
175
- }}
176
- th {{
177
- background-color: #123c7c;
178
- color: white;
179
- }}
180
- .note {{
181
- margin-top: 25px;
182
- padding: 15px;
183
- background-color: #fff3e6;
184
- border-left: 6px solid #f58220;
185
- }}
186
- </style>
187
- </head>
188
- <body>
189
- <div class="container">
190
- <h1>Specialization Choice Acknowledgement</h1>
191
- <h3>Engineering Specialization Selection Portal</h3>
192
-
193
- <p><b>Submission Date/Time:</b> {datetime.now().strftime("%d-%m-%Y %H:%M:%S")}</p>
194
- <p><b>Student ID:</b> {student_id}</p>
195
- <p><b>Student Name:</b> {name}</p>
196
- <p><b>Advisor Name:</b> {advisor}</p>
197
- <p><b>Gender:</b> {gender}</p>
198
- <p><b>Phone Number:</b> {phone}</p>
199
-
200
- <table>
201
- <tr>
202
- <th>Priority</th>
203
- <th>Selected Specialization</th>
204
- </tr>
205
- {choice_rows}
206
- </table>
207
-
208
- <div class="note">
209
- This acknowledgement confirms that your specialization preferences have been submitted successfully.
210
- Final allocation will be subject to the rules and approval of the Specialization Committee.
211
- </div>
212
- </div>
213
- </body>
214
- </html>
215
- """
216
-
217
- return html.encode("utf-8")
218
 
219
  st.markdown("""
220
  <div class="hero">
@@ -222,200 +15,4 @@ st.markdown("""
222
  <div class="main-title">Specialization Priority Selection System</div>
223
  <div class="subtitle">Engineering Specialization Selection Portal</div>
224
  </div>
225
- """, unsafe_allow_html=True)
226
-
227
- left_col, right_col = st.columns([3, 1])
228
-
229
- with left_col:
230
- st.markdown("""
231
- <div class="info-box">
232
- <h3>Student Instructions</h3>
233
- <ol>
234
- <li>Enter your Student ID.</li>
235
- <li>After verification, enter your gender and phone number.</li>
236
- <li>Your specialization choices will appear only after completing basic details.</li>
237
- <li>Male students must prioritize 10 choices.</li>
238
- <li>Female students must prioritize 9 choices because HVAC is not applicable.</li>
239
- <li>After submission, download your acknowledgement report.</li>
240
- </ol>
241
- </div>
242
- """, unsafe_allow_html=True)
243
-
244
- st.subheader("Step 1: Student Verification")
245
- student_id = st.text_input("Enter your Student ID")
246
-
247
- if student_id:
248
- matched = df_students[df_students["Student No"].astype(str) == student_id]
249
-
250
- if not matched.empty:
251
- row = matched.iloc[0]
252
- st.success("Student ID verified successfully.")
253
-
254
- st.markdown(f"""
255
- <div class="choice-box">
256
- <b>Student Name:</b> {row['Student Name']}<br>
257
- <b>Advisor Name:</b> {row['Advisor Name']}
258
- </div>
259
- """, unsafe_allow_html=True)
260
-
261
- st.subheader("Step 2: Basic Information")
262
- gender = st.radio("Select Gender", ["Male", "Female"], horizontal=True)
263
- phone = st.text_input("Enter Phone Number")
264
-
265
- if phone.strip() != "":
266
- if gender == "Male":
267
- choices_available = all_choices
268
- required_choices = 10
269
- else:
270
- choices_available = female_choices
271
- required_choices = 9
272
-
273
- st.subheader(f"Step 3: Prioritize Your {required_choices} Choices")
274
-
275
- with st.expander("View Available Specializations", expanded=True):
276
- for i, item in enumerate(choices_available, start=1):
277
- st.write(f"{i}. {item}")
278
-
279
- selected_choices = []
280
-
281
- for i in range(required_choices):
282
- remaining = [x for x in choices_available if x not in selected_choices]
283
- choice = st.selectbox(
284
- f"Choice {i+1}",
285
- remaining,
286
- key=f"choice_{i}"
287
- )
288
- selected_choices.append(choice)
289
-
290
- if st.button("Submit Choices"):
291
- submission = {
292
- "Student ID": student_id,
293
- "Student Name": row["Student Name"],
294
- "Advisor Name": row["Advisor Name"],
295
- "Gender": gender,
296
- "Phone Number": phone
297
- }
298
-
299
- for i, c in enumerate(selected_choices):
300
- submission[f"Choice {i+1}"] = c
301
-
302
- submit_df = pd.DataFrame([submission])
303
-
304
- if os.path.exists(csv_file):
305
- old_df = pd.read_csv(csv_file)
306
- old_df = old_df[old_df["Student ID"].astype(str) != student_id]
307
- final_df = pd.concat([old_df, submit_df], ignore_index=True)
308
- else:
309
- final_df = submit_df
310
-
311
- final_df.to_csv(csv_file, index=False)
312
-
313
- st.success("Your choices have been submitted successfully.")
314
-
315
- ack_html = create_acknowledgement_html(
316
- student_id,
317
- row["Student Name"],
318
- row["Advisor Name"],
319
- gender,
320
- phone,
321
- selected_choices
322
- )
323
-
324
- st.download_button(
325
- label="Download Acknowledgement Report",
326
- data=ack_html,
327
- file_name=f"acknowledgement_{student_id}.html",
328
- mime="text/html"
329
- )
330
- else:
331
- st.info("Please enter your phone number to continue to specialization choices.")
332
-
333
- else:
334
- st.error("Invalid Student ID. Please check and try again.")
335
-
336
- with right_col:
337
- st.markdown("""
338
- <div class="admin-box">
339
- <h3 style="color:white !important;">Admin Panel</h3>
340
- <p style="color:white !important;"><b>For Specialization Committee Members only.</b></p>
341
- </div>
342
- """, unsafe_allow_html=True)
343
-
344
- admin_password = st.text_input("Enter Admin Password", type="password")
345
-
346
- if admin_password == "admin123":
347
- st.success("Admin access granted.")
348
-
349
- if os.path.exists(csv_file):
350
- report_df = pd.read_csv(csv_file)
351
- st.metric("Total Submissions", len(report_df))
352
-
353
- excel_data = convert_df_to_excel(report_df)
354
-
355
- st.download_button(
356
- label="Download Excel Report",
357
- data=excel_data,
358
- file_name="specialization_report.xlsx",
359
- mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
360
- )
361
- else:
362
- st.warning("No submissions available yet.")
363
-
364
- st.markdown("---")
365
-
366
- if os.path.exists(csv_file):
367
- report_df = pd.read_csv(csv_file)
368
-
369
- if not report_df.empty:
370
- st.header("Admin Analytics")
371
-
372
- analytics_password = st.text_input(
373
- "Re-enter Admin Password to View Analytics",
374
- type="password",
375
- key="analytics_pass"
376
- )
377
-
378
- if analytics_password == "admin123":
379
- st.subheader("Submitted Student Choices")
380
- st.dataframe(report_df, use_container_width=True)
381
-
382
- choice_columns = [
383
- col for col in report_df.columns
384
- if col.startswith("Choice")
385
- ]
386
-
387
- st.subheader("Choice-Level Analytics")
388
-
389
- selected_choice_column = st.selectbox(
390
- "Select Choice Level",
391
- choice_columns
392
- )
393
-
394
- chart_data = (
395
- report_df[selected_choice_column]
396
- .value_counts()
397
- .reset_index()
398
- )
399
-
400
- chart_data.columns = ["Specialization", "Number of Students"]
401
-
402
- st.bar_chart(chart_data.set_index("Specialization"))
403
-
404
- st.subheader("Overall Specialization Demand")
405
-
406
- all_selected_choices = report_df[choice_columns].melt(
407
- value_name="Specialization"
408
- )
409
-
410
- overall_chart_data = (
411
- all_selected_choices["Specialization"]
412
- .value_counts()
413
- .reset_index()
414
- )
415
-
416
- overall_chart_data.columns = [
417
- "Specialization",
418
- "Total Times Selected"
419
- ]
420
-
421
- st.bar_chart(overall_chart_data.set_index("Specialization"))
 
1
+ # ---------------------------------------------------
2
+ # LOGO PATH
3
+ # ---------------------------------------------------
4
+ logo_path = os.path.join(BASE_DIR, "logo.png")
 
5
 
6
+ # ---------------------------------------------------
7
+ # HEADER WITH LOGO
8
+ # ---------------------------------------------------
9
+ if os.path.exists(logo_path):
10
+ st.image(logo_path, width=420)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  st.markdown("""
13
  <div class="hero">
 
15
  <div class="main-title">Specialization Priority Selection System</div>
16
  <div class="subtitle">Engineering Specialization Selection Portal</div>
17
  </div>
18
+ """, unsafe_allow_html=True)