Spaces:
Runtime error
Runtime error
| # app.py | |
| import streamlit as st | |
| import pandas as pd | |
| import os | |
| from io import BytesIO | |
| st.set_page_config( | |
| page_title="Specialization Selection System", | |
| layout="wide" | |
| ) | |
| st.markdown(""" | |
| <style> | |
| .title { | |
| font-size: 38px; | |
| font-weight: bold; | |
| color: #003366; | |
| text-align: center; | |
| } | |
| .sub { | |
| font-size: 20px; | |
| color: #444; | |
| text-align: center; | |
| margin-bottom: 25px; | |
| } | |
| .stButton>button { | |
| background-color: #003366; | |
| color: white; | |
| border-radius: 10px; | |
| height: 45px; | |
| width: 100%; | |
| font-size: 18px; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| st.image("logo.png", width=450) | |
| st.markdown('<div class="title">Specialization Priority Selection System</div>', unsafe_allow_html=True) | |
| st.markdown('<div class="sub">University Engineering Specialization Selection Portal</div>', unsafe_allow_html=True) | |
| excel_file = "For Specialisation.xlsx" | |
| df_students = pd.read_excel(excel_file) | |
| all_choices = [ | |
| "Civil Engineering (Baccalaureate level)", | |
| "Architectural Engineering (Baccalaureate level)", | |
| "Quantity Surveying & Cost Estimation (Baccalaureate level)", | |
| "Mechanical Engineering (Baccalaureate level)", | |
| "Chemical Engineering (Baccalaureate level)", | |
| "Heating Ventilation & Air Conditioning (Diploma level)", | |
| "Oil and Gas (Diploma level)", | |
| "Electrical Power Engineering (Baccalaureate level)", | |
| "Electronics and Telecommunication Engineering (Baccalaureate level)", | |
| "Computer Engineering (Baccalaureate level)" | |
| ] | |
| female_choices = [ | |
| "Civil Engineering (Baccalaureate level)", | |
| "Architectural Engineering (Baccalaureate level)", | |
| "Quantity Surveying & Cost Estimation (Baccalaureate level)", | |
| "Mechanical Engineering (Baccalaureate level)", | |
| "Chemical Engineering (Baccalaureate level)", | |
| "Oil and Gas (Diploma level)", | |
| "Electrical Power Engineering (Baccalaureate level)", | |
| "Electronics and Telecommunication Engineering (Baccalaureate level)", | |
| "Computer Engineering (Baccalaureate level)" | |
| ] | |
| def convert_df_to_excel(df): | |
| output = BytesIO() | |
| with pd.ExcelWriter(output, engine="openpyxl") as writer: | |
| df.to_excel(writer, index=False, sheet_name="Student Choices") | |
| output.seek(0) | |
| return output | |
| student_id = st.text_input("Enter Student ID") | |
| if student_id: | |
| matched = df_students[df_students["Student No"].astype(str) == student_id] | |
| if not matched.empty: | |
| row = matched.iloc[0] | |
| st.success("Student ID Verified Successfully") | |
| st.write(f"### Student Name: {row['Student Name']}") | |
| st.write(f"### Advisor Name: {row['Advisor Name']}") | |
| gender = st.radio("Select Gender", ["Male", "Female"]) | |
| phone = st.text_input("Enter Phone Number") | |
| st.markdown("---") | |
| st.subheader("Select Your Prioritized Choices") | |
| if gender == "Male": | |
| choices_available = all_choices | |
| required_choices = 10 | |
| else: | |
| choices_available = female_choices | |
| required_choices = 9 | |
| selected_choices = [] | |
| for i in range(required_choices): | |
| remaining = [x for x in choices_available if x not in selected_choices] | |
| choice = st.selectbox( | |
| f"Choice {i + 1}", | |
| remaining, | |
| key=f"choice_{i}" | |
| ) | |
| selected_choices.append(choice) | |
| if st.button("Submit Choices"): | |
| if phone.strip() == "": | |
| st.error("Please enter phone number before submitting.") | |
| else: | |
| submission = { | |
| "Student ID": student_id, | |
| "Student Name": row["Student Name"], | |
| "Advisor Name": row["Advisor Name"], | |
| "Gender": gender, | |
| "Phone Number": phone | |
| } | |
| for i, c in enumerate(selected_choices): | |
| submission[f"Choice {i + 1}"] = c | |
| submit_df = pd.DataFrame([submission]) | |
| csv_file = "submissions.csv" | |
| if os.path.exists(csv_file): | |
| old_df = pd.read_csv(csv_file) | |
| old_df = old_df[old_df["Student ID"].astype(str) != student_id] | |
| final_df = pd.concat([old_df, submit_df], ignore_index=True) | |
| else: | |
| final_df = submit_df | |
| final_df.to_csv(csv_file, index=False) | |
| st.success("Choices Submitted Successfully") | |
| else: | |
| st.error("Invalid Student ID") | |
| st.markdown("---") | |
| st.header("Admin Dashboard and Report Download") | |
| admin_password = st.text_input("Enter Admin Password", type="password") | |
| if admin_password == "admin123": | |
| if os.path.exists("submissions.csv"): | |
| report_df = pd.read_csv("submissions.csv") | |
| st.subheader("Submitted Student Choices") | |
| st.dataframe(report_df, use_container_width=True) | |
| st.subheader("Choice Analytics") | |
| choice_columns = [col for col in report_df.columns if col.startswith("Choice")] | |
| selected_choice_column = st.selectbox( | |
| "Select Choice Level for Analytics", | |
| choice_columns | |
| ) | |
| chart_data = report_df[selected_choice_column].value_counts().reset_index() | |
| chart_data.columns = ["Specialization", "Number of Students"] | |
| st.bar_chart(chart_data.set_index("Specialization")) | |
| st.subheader("Overall Specialization Demand Across All Choices") | |
| all_selected_choices = report_df[choice_columns].melt(value_name="Specialization") | |
| overall_chart_data = all_selected_choices["Specialization"].value_counts().reset_index() | |
| overall_chart_data.columns = ["Specialization", "Total Times Selected"] | |
| st.bar_chart(overall_chart_data.set_index("Specialization")) | |
| excel_data = convert_df_to_excel(report_df) | |
| st.download_button( | |
| label="Download Report Excel", | |
| data=excel_data, | |
| file_name="specialization_report.xlsx", | |
| mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | |
| ) | |
| else: | |
| st.warning("No submissions available yet") |