Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +180 -46
src/streamlit_app.py
CHANGED
|
@@ -1,53 +1,168 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
|
| 4 |
import pandas as pd
|
| 5 |
from datetime import datetime
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
-
import
|
| 8 |
-
import
|
| 9 |
from google.oauth2.service_account import Credentials
|
| 10 |
|
| 11 |
-
#
|
|
|
|
|
|
|
| 12 |
creds_dict = json.loads(os.environ["GOOGLE_CREDENTIALS"])
|
| 13 |
|
| 14 |
-
credentials = Credentials.from_service_account_info(
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
st.title("π HTML Lab Digital Evaluation System")
|
| 18 |
|
| 19 |
# ==================================
|
| 20 |
-
# ROLE SELECTION
|
| 21 |
# ==================================
|
| 22 |
-
|
|
|
|
|
|
|
| 23 |
|
| 24 |
# ==================================
|
| 25 |
# π¨βπ STUDENT SECTION
|
| 26 |
# ==================================
|
| 27 |
-
if role == "Student":
|
| 28 |
|
| 29 |
-
st.
|
| 30 |
|
| 31 |
-
|
| 32 |
-
roll = st.text_input("Roll Number")
|
| 33 |
-
experiment = st.text_input("Experiment No")
|
| 34 |
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
if not (name and roll and experiment and uploaded_file):
|
| 40 |
st.error("Please fill all fields")
|
| 41 |
else:
|
| 42 |
content = uploaded_file.read().decode("utf-8")
|
| 43 |
|
| 44 |
-
performance,
|
| 45 |
submission = 5
|
| 46 |
-
|
| 47 |
-
# Teacher will fill later
|
| 48 |
attendance = 0
|
| 49 |
oral = 0
|
| 50 |
-
|
| 51 |
total = submission + performance
|
| 52 |
|
| 53 |
records = get_all_data()
|
|
@@ -57,33 +172,38 @@ if role == "Student":
|
|
| 57 |
st.error("Already submitted!")
|
| 58 |
else:
|
| 59 |
data = [
|
| 60 |
-
name,
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
oral,
|
| 65 |
-
submission,
|
| 66 |
-
performance,
|
| 67 |
-
total,
|
| 68 |
-
str(datetime.now())
|
| 69 |
]
|
| 70 |
|
| 71 |
insert_data(data)
|
| 72 |
|
| 73 |
st.success("β
Submitted Successfully!")
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
# ==================================
|
| 77 |
# π¨βπ« TEACHER SECTION
|
| 78 |
# ==================================
|
| 79 |
-
if role == "Teacher":
|
| 80 |
-
|
| 81 |
-
pwd = st.text_input("Enter Password", type="password")
|
| 82 |
if pwd != "admin123":
|
|
|
|
| 83 |
st.stop()
|
| 84 |
-
st.header("π§βπ« Teacher Panel")
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
st.subheader("Update Attendance & Oral")
|
| 88 |
|
| 89 |
roll_input = st.text_input("Roll No")
|
|
@@ -94,10 +214,7 @@ if role == "Teacher":
|
|
| 94 |
|
| 95 |
if st.button("Update Marks"):
|
| 96 |
|
| 97 |
-
from gsheet import connect_sheet
|
| 98 |
-
sheet = connect_sheet()
|
| 99 |
records = sheet.get_all_records()
|
| 100 |
-
|
| 101 |
found = False
|
| 102 |
|
| 103 |
for i, row in enumerate(records, start=2):
|
|
@@ -120,8 +237,12 @@ if role == "Teacher":
|
|
| 120 |
if not found:
|
| 121 |
st.error("Record not found!")
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
data = get_all_data()
|
| 127 |
df = pd.DataFrame(data)
|
|
@@ -131,22 +252,35 @@ if role == "Teacher":
|
|
| 131 |
col1, col2 = st.columns(2)
|
| 132 |
|
| 133 |
with col1:
|
| 134 |
-
st.
|
| 135 |
exp_avg = df.groupby("Experiment No")["Total"].mean()
|
| 136 |
st.bar_chart(exp_avg)
|
| 137 |
|
| 138 |
with col2:
|
| 139 |
-
st.
|
| 140 |
top_students = df.sort_values(by="Total", ascending=False).head(5)
|
| 141 |
st.dataframe(top_students)
|
| 142 |
|
| 143 |
-
st.subheader("Distribution")
|
| 144 |
fig, ax = plt.subplots()
|
| 145 |
ax.hist(df["Total"])
|
|
|
|
| 146 |
st.pyplot(fig)
|
| 147 |
|
| 148 |
-
st.subheader("All Records")
|
| 149 |
st.dataframe(df)
|
| 150 |
|
| 151 |
else:
|
| 152 |
-
st.info("No data available")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
import pandas as pd
|
| 5 |
from datetime import datetime
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
+
from bs4 import BeautifulSoup
|
| 8 |
+
import gspread
|
| 9 |
from google.oauth2.service_account import Credentials
|
| 10 |
|
| 11 |
+
# ==================================
|
| 12 |
+
# π GOOGLE SHEETS CONNECTION
|
| 13 |
+
# ==================================
|
| 14 |
creds_dict = json.loads(os.environ["GOOGLE_CREDENTIALS"])
|
| 15 |
|
| 16 |
+
credentials = Credentials.from_service_account_info(
|
| 17 |
+
creds_dict,
|
| 18 |
+
scopes=[
|
| 19 |
+
"https://www.googleapis.com/auth/spreadsheets",
|
| 20 |
+
"https://www.googleapis.com/auth/drive"
|
| 21 |
+
]
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
client = gspread.authorize(credentials)
|
| 25 |
+
sheet = client.open("Student Marks").sheet1
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ==================================
|
| 29 |
+
# π¨ PREMIUM UI CSS
|
| 30 |
+
# ==================================
|
| 31 |
+
st.markdown("""
|
| 32 |
+
<style>
|
| 33 |
+
.header {
|
| 34 |
+
display: flex;
|
| 35 |
+
align-items: center;
|
| 36 |
+
justify-content: center;
|
| 37 |
+
gap: 15px;
|
| 38 |
+
}
|
| 39 |
+
.header img {
|
| 40 |
+
width: 60px;
|
| 41 |
+
}
|
| 42 |
+
.header-text {
|
| 43 |
+
font-size: 30px;
|
| 44 |
+
font-weight: bold;
|
| 45 |
+
color: #2c3e50;
|
| 46 |
+
}
|
| 47 |
+
.sub-text {
|
| 48 |
+
text-align: center;
|
| 49 |
+
font-size: 16px;
|
| 50 |
+
color: gray;
|
| 51 |
+
}
|
| 52 |
+
.card {
|
| 53 |
+
padding: 20px;
|
| 54 |
+
border-radius: 12px;
|
| 55 |
+
background-color: #f8f9fa;
|
| 56 |
+
box-shadow: 2px 2px 10px rgba(0,0,0,0.1);
|
| 57 |
+
margin-bottom: 20px;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
""", unsafe_allow_html=True)
|
| 61 |
+
|
| 62 |
+
# ==================================
|
| 63 |
+
# π« HEADER
|
| 64 |
+
# ==================================
|
| 65 |
+
st.markdown("""
|
| 66 |
+
<div class="header">
|
| 67 |
+
<img src="https://cdn-icons-png.flaticon.com/512/3135/3135755.png">
|
| 68 |
+
<div class="header-text">Your College Name</div>
|
| 69 |
+
</div>
|
| 70 |
+
|
| 71 |
+
<div class="sub-text">
|
| 72 |
+
Department of Computer Engineering<br>
|
| 73 |
+
HTML Lab Digital Evaluation System
|
| 74 |
+
</div>
|
| 75 |
+
<hr>
|
| 76 |
+
""", unsafe_allow_html=True)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
# ==================================
|
| 80 |
+
# π§ HTML EVALUATION
|
| 81 |
+
# ==================================
|
| 82 |
+
def evaluate_html(content):
|
| 83 |
+
score = 0
|
| 84 |
+
feedback = []
|
| 85 |
+
|
| 86 |
+
soup = BeautifulSoup(content, 'html.parser')
|
| 87 |
+
|
| 88 |
+
if soup.html:
|
| 89 |
+
score += 1
|
| 90 |
+
else:
|
| 91 |
+
feedback.append("Missing <html> tag")
|
| 92 |
+
|
| 93 |
+
if soup.head and soup.title:
|
| 94 |
+
score += 1
|
| 95 |
+
else:
|
| 96 |
+
feedback.append("Missing <head> or <title>")
|
| 97 |
+
|
| 98 |
+
if soup.body:
|
| 99 |
+
score += 1
|
| 100 |
+
else:
|
| 101 |
+
feedback.append("Missing <body>")
|
| 102 |
+
|
| 103 |
+
tags = ['p', 'h1', 'img', 'a', 'table']
|
| 104 |
+
used = [tag for tag in tags if soup.find(tag)]
|
| 105 |
+
|
| 106 |
+
if len(used) >= 3:
|
| 107 |
+
score += 1
|
| 108 |
+
else:
|
| 109 |
+
feedback.append("Use at least 3 different HTML tags")
|
| 110 |
+
|
| 111 |
+
if len(soup.text.strip()) > 20:
|
| 112 |
+
score += 1
|
| 113 |
+
else:
|
| 114 |
+
feedback.append("Content too short")
|
| 115 |
+
|
| 116 |
+
return score, feedback
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
# ==================================
|
| 120 |
+
# π GOOGLE SHEET FUNCTIONS
|
| 121 |
+
# ==================================
|
| 122 |
+
def get_all_data():
|
| 123 |
+
return sheet.get_all_records()
|
| 124 |
+
|
| 125 |
+
def insert_data(data):
|
| 126 |
+
sheet.append_row(data)
|
| 127 |
|
|
|
|
| 128 |
|
| 129 |
# ==================================
|
| 130 |
+
# π ROLE SELECTION
|
| 131 |
# ==================================
|
| 132 |
+
st.markdown("### π Select Your Role")
|
| 133 |
+
role = st.radio("", ["π¨βπ Student", "π¨βπ« Teacher"], horizontal=True)
|
| 134 |
+
|
| 135 |
|
| 136 |
# ==================================
|
| 137 |
# π¨βπ STUDENT SECTION
|
| 138 |
# ==================================
|
| 139 |
+
if role == "π¨βπ Student":
|
| 140 |
|
| 141 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 142 |
|
| 143 |
+
st.subheader("π€ Student Submission")
|
|
|
|
|
|
|
| 144 |
|
| 145 |
+
col1, col2 = st.columns(2)
|
| 146 |
|
| 147 |
+
with col1:
|
| 148 |
+
name = st.text_input("Student Name")
|
| 149 |
+
roll = st.text_input("Roll Number")
|
| 150 |
+
|
| 151 |
+
with col2:
|
| 152 |
+
experiment = st.text_input("Experiment No")
|
| 153 |
+
uploaded_file = st.file_uploader("Upload HTML File", type=["html"])
|
| 154 |
+
|
| 155 |
+
if st.button("π Submit"):
|
| 156 |
|
| 157 |
if not (name and roll and experiment and uploaded_file):
|
| 158 |
st.error("Please fill all fields")
|
| 159 |
else:
|
| 160 |
content = uploaded_file.read().decode("utf-8")
|
| 161 |
|
| 162 |
+
performance, feedback = evaluate_html(content)
|
| 163 |
submission = 5
|
|
|
|
|
|
|
| 164 |
attendance = 0
|
| 165 |
oral = 0
|
|
|
|
| 166 |
total = submission + performance
|
| 167 |
|
| 168 |
records = get_all_data()
|
|
|
|
| 172 |
st.error("Already submitted!")
|
| 173 |
else:
|
| 174 |
data = [
|
| 175 |
+
name, roll, experiment,
|
| 176 |
+
attendance, oral,
|
| 177 |
+
submission, performance,
|
| 178 |
+
total, str(datetime.now())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
]
|
| 180 |
|
| 181 |
insert_data(data)
|
| 182 |
|
| 183 |
st.success("β
Submitted Successfully!")
|
| 184 |
+
|
| 185 |
+
if feedback:
|
| 186 |
+
st.warning("β Feedback:")
|
| 187 |
+
for f in feedback:
|
| 188 |
+
st.write(f"- {f}")
|
| 189 |
+
|
| 190 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 191 |
+
|
| 192 |
|
| 193 |
# ==================================
|
| 194 |
# π¨βπ« TEACHER SECTION
|
| 195 |
# ==================================
|
| 196 |
+
if role == "π¨βπ« Teacher":
|
| 197 |
+
|
| 198 |
+
pwd = st.text_input("π Enter Password", type="password")
|
| 199 |
if pwd != "admin123":
|
| 200 |
+
st.warning("Enter correct password")
|
| 201 |
st.stop()
|
|
|
|
| 202 |
|
| 203 |
+
st.markdown('<div class="card">', unsafe_allow_html=True)
|
| 204 |
+
|
| 205 |
+
st.subheader("π§βπ« Teacher Panel")
|
| 206 |
+
|
| 207 |
st.subheader("Update Attendance & Oral")
|
| 208 |
|
| 209 |
roll_input = st.text_input("Roll No")
|
|
|
|
| 214 |
|
| 215 |
if st.button("Update Marks"):
|
| 216 |
|
|
|
|
|
|
|
| 217 |
records = sheet.get_all_records()
|
|
|
|
| 218 |
found = False
|
| 219 |
|
| 220 |
for i, row in enumerate(records, start=2):
|
|
|
|
| 237 |
if not found:
|
| 238 |
st.error("Record not found!")
|
| 239 |
|
| 240 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 241 |
+
|
| 242 |
+
# ==================================
|
| 243 |
+
# π DASHBOARD
|
| 244 |
+
# ==================================
|
| 245 |
+
st.markdown("### π Performance Dashboard")
|
| 246 |
|
| 247 |
data = get_all_data()
|
| 248 |
df = pd.DataFrame(data)
|
|
|
|
| 252 |
col1, col2 = st.columns(2)
|
| 253 |
|
| 254 |
with col1:
|
| 255 |
+
st.info("π Average Marks per Experiment")
|
| 256 |
exp_avg = df.groupby("Experiment No")["Total"].mean()
|
| 257 |
st.bar_chart(exp_avg)
|
| 258 |
|
| 259 |
with col2:
|
| 260 |
+
st.info("π Top Students")
|
| 261 |
top_students = df.sort_values(by="Total", ascending=False).head(5)
|
| 262 |
st.dataframe(top_students)
|
| 263 |
|
| 264 |
+
st.subheader("π Marks Distribution")
|
| 265 |
fig, ax = plt.subplots()
|
| 266 |
ax.hist(df["Total"])
|
| 267 |
+
ax.set_title("Marks Distribution")
|
| 268 |
st.pyplot(fig)
|
| 269 |
|
| 270 |
+
st.subheader("π All Records")
|
| 271 |
st.dataframe(df)
|
| 272 |
|
| 273 |
else:
|
| 274 |
+
st.info("No data available")
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
# ==================================
|
| 278 |
+
# π§Ύ FOOTER
|
| 279 |
+
# ==================================
|
| 280 |
+
st.markdown("""
|
| 281 |
+
<hr>
|
| 282 |
+
<div style='text-align: center; color: gray;'>
|
| 283 |
+
Developed by Department of Computer Engineering <br>
|
| 284 |
+
Β© 2026 Your College Name | All Rights Reserved
|
| 285 |
+
</div>
|
| 286 |
+
""", unsafe_allow_html=True)
|