import streamlit as st import os import json import pandas as pd from datetime import datetime import matplotlib.pyplot as plt from bs4 import BeautifulSoup import gspread from google.oauth2.service_account import Credentials # ================================== # ๐Ÿ” GOOGLE SHEETS CONNECTION # ================================== creds_dict = json.loads(os.environ["GOOGLE_CREDENTIALS"]) credentials = Credentials.from_service_account_info( creds_dict, scopes=[ "https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive" ] ) client = gspread.authorize(credentials) sheet = client.open("Student Marks").sheet1 # ================================== # ๐ŸŽจ PREMIUM UI CSS # ================================== st.markdown(""" """, unsafe_allow_html=True) # ================================== # ๐Ÿซ HEADER # ================================== st.markdown("""
Your College Name
Department of Computer Engineering
HTML Lab Digital Evaluation System

""", unsafe_allow_html=True) # ================================== # ๐Ÿง  HTML EVALUATION # ================================== def evaluate_html(content): score = 0 feedback = [] soup = BeautifulSoup(content, 'html.parser') if soup.html: score += 1 else: feedback.append("Missing tag") if soup.head and soup.title: score += 1 else: feedback.append("Missing or ") if soup.body: score += 1 else: feedback.append("Missing <body>") tags = ['p', 'h1', 'img', 'a', 'table'] used = [tag for tag in tags if soup.find(tag)] if len(used) >= 3: score += 1 else: feedback.append("Use at least 3 different HTML tags") if len(soup.text.strip()) > 20: score += 1 else: feedback.append("Content too short") return score, feedback # ================================== # ๐Ÿ“Š GOOGLE SHEET FUNCTIONS # ================================== def get_all_data(): return sheet.get_all_records() def insert_data(data): sheet.append_row(data) # ================================== # ๐ŸŽญ ROLE SELECTION # ================================== st.markdown("### ๐ŸŽญ Select Your Role") role = st.radio("", ["๐Ÿ‘จโ€๐ŸŽ“ Student", "๐Ÿ‘จโ€๐Ÿซ Teacher"], horizontal=True) # ================================== # ๐Ÿ‘จโ€๐ŸŽ“ STUDENT SECTION # ================================== if role == "๐Ÿ‘จโ€๐ŸŽ“ Student": st.markdown('<div class="card">', unsafe_allow_html=True) st.subheader("๐Ÿ“ค Student Submission") col1, col2 = st.columns(2) with col1: name = st.text_input("Student Name") roll = st.text_input("Roll Number") with col2: experiment = st.text_input("Experiment No") uploaded_file = st.file_uploader("Upload HTML File", type=["html"]) if st.button("๐Ÿš€ Submit"): if not (name and roll and experiment and uploaded_file): st.error("Please fill all fields") else: content = uploaded_file.read().decode("utf-8") performance, feedback = evaluate_html(content) submission = 5 attendance = 0 oral = 0 total = submission + performance records = get_all_data() df = pd.DataFrame(records) if not df.empty and ((df["Roll No"] == roll) & (df["Experiment No"] == experiment)).any(): st.error("Already submitted!") else: data = [ name, roll, experiment, attendance, oral, submission, performance, total, str(datetime.now()) ] insert_data(data) st.success("โœ… Submitted Successfully!") if feedback: st.warning("โš  Feedback:") for f in feedback: st.write(f"- {f}") st.markdown('</div>', unsafe_allow_html=True) # ================================== # ๐Ÿ‘จโ€๐Ÿซ TEACHER SECTION # ================================== if role == "๐Ÿ‘จโ€๐Ÿซ Teacher": pwd = st.text_input("๐Ÿ” Enter Password", type="password") if pwd != "admin123": st.warning("Enter correct password") st.stop() st.markdown('<div class="card">', unsafe_allow_html=True) st.subheader("๐Ÿง‘โ€๐Ÿซ Teacher Panel") st.subheader("Update Attendance & Oral") roll_input = st.text_input("Roll No") exp_input = st.text_input("Experiment No") attendance_input = st.slider("Attendance", 0, 5, 0) oral_input = st.slider("Oral", 0, 5, 0) if st.button("Update Marks"): records = sheet.get_all_records() found = False for i, row in enumerate(records, start=2): if str(row["Roll No"]) == roll_input and str(row["Experiment No"]) == exp_input: performance = int(row["Performance"]) submission = int(row["Submission"]) total = attendance_input + oral_input + submission + performance sheet.update_cell(i, 4, attendance_input) sheet.update_cell(i, 5, oral_input) sheet.update_cell(i, 8, total) st.success("โœ… Marks Updated!") found = True break if not found: st.error("Record not found!") st.markdown('</div>', unsafe_allow_html=True) # ================================== # ๐Ÿ“Š DASHBOARD # ================================== st.markdown("### ๐Ÿ“Š Performance Dashboard") data = get_all_data() df = pd.DataFrame(data) if not df.empty: col1, col2 = st.columns(2) with col1: st.info("๐Ÿ“ˆ Average Marks per Experiment") exp_avg = df.groupby("Experiment No")["Total"].mean() st.bar_chart(exp_avg) with col2: st.info("๐Ÿ† Top Students") top_students = df.sort_values(by="Total", ascending=False).head(5) st.dataframe(top_students) st.subheader("๐Ÿ“‰ Marks Distribution") fig, ax = plt.subplots() ax.hist(df["Total"]) ax.set_title("Marks Distribution") st.pyplot(fig) st.subheader("๐Ÿ“‹ All Records") st.dataframe(df) else: st.info("No data available") # ================================== # ๐Ÿงพ FOOTER # ================================== st.markdown(""" <hr> <div style='text-align: center; color: gray;'> Developed by Department of Computer Engineering <br> ยฉ 2026 Your College Name | All Rights Reserved </div> """, unsafe_allow_html=True)