Spaces:
Runtime error
Runtime error
Download src/streamlit_app.py from sujitv14/Automated_Web_Development_Lab_Evaluation: direct link, hf CLI and curl.
- Browser
- Download file 7.33 kB
-
https://huggingface.co/spaces/sujitv14/Automated_Web_Development_Lab_Evaluation/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/sujitv14/Automated_Web_Development_Lab_Evaluation/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/sujitv14/Automated_Web_Development_Lab_Evaluation/resolve/main/src/streamlit_app.py
7.33 kB
| 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) |