Spaces:
Runtime error
Runtime error
File size: 7,326 Bytes
93a1ece e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f e4f707b 0c8268f 93a1ece 0c8268f e4f707b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | 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("""
<style>
.header {
display: flex;
align-items: center;
justify-content: center;
gap: 15px;
}
.header img {
width: 60px;
}
.header-text {
font-size: 30px;
font-weight: bold;
color: #2c3e50;
}
.sub-text {
text-align: center;
font-size: 16px;
color: gray;
}
.card {
padding: 20px;
border-radius: 12px;
background-color: #f8f9fa;
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
</style>
""", unsafe_allow_html=True)
# ==================================
# π« HEADER
# ==================================
st.markdown("""
<div class="header">
<img src="https://cdn-icons-png.flaticon.com/512/3135/3135755.png">
<div class="header-text">Your College Name</div>
</div>
<div class="sub-text">
Department of Computer Engineering<br>
HTML Lab Digital Evaluation System
</div>
<hr>
""", 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 <html> tag")
if soup.head and soup.title:
score += 1
else:
feedback.append("Missing <head> or <title>")
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) |