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("""
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 ")
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('', 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('
', 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('', 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('
', 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("""
Developed by Department of Computer Engineering
ยฉ 2026 Your College Name | All Rights Reserved
""", unsafe_allow_html=True)