sujitv14 commited on
Commit
e4f707b
Β·
verified Β·
1 Parent(s): e8d17f3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +180 -46
src/streamlit_app.py CHANGED
@@ -1,53 +1,168 @@
1
  import streamlit as st
2
- from evaluator import evaluate_html
3
- from gsheet import insert_data, get_all_data
4
  import pandas as pd
5
  from datetime import datetime
6
  import matplotlib.pyplot as plt
7
- import os
8
- import json
9
  from google.oauth2.service_account import Credentials
10
 
11
- # Load credentials from Hugging Face secret
 
 
12
  creds_dict = json.loads(os.environ["GOOGLE_CREDENTIALS"])
13
 
14
- credentials = Credentials.from_service_account_info(creds_dict)
15
- st.set_page_config(page_title="HTML Lab Evaluator", layout="wide")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- st.title("🌐 HTML Lab Digital Evaluation System")
18
 
19
  # ==================================
20
- # ROLE SELECTION
21
  # ==================================
22
- role = st.selectbox("Select Role", ["Student", "Teacher"])
 
 
23
 
24
  # ==================================
25
  # πŸ‘¨β€πŸŽ“ STUDENT SECTION
26
  # ==================================
27
- if role == "Student":
28
 
29
- st.header("πŸ“€ Student Submission")
30
 
31
- name = st.text_input("Student Name")
32
- roll = st.text_input("Roll Number")
33
- experiment = st.text_input("Experiment No")
34
 
35
- uploaded_file = st.file_uploader("Upload HTML File", type=["html"])
36
 
37
- if st.button("Submit"):
 
 
 
 
 
 
 
 
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, _ = evaluate_html(content)
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
- roll,
62
- experiment,
63
- attendance,
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
- st.info("Marks will be updated by teacher")
 
 
 
 
 
 
 
75
 
76
  # ==================================
77
  # πŸ‘¨β€πŸ« TEACHER SECTION
78
  # ==================================
79
- if role == "Teacher":
80
- if role == "Teacher":
81
- pwd = st.text_input("Enter Password", type="password")
82
  if pwd != "admin123":
 
83
  st.stop()
84
- st.header("πŸ§‘β€πŸ« Teacher Panel")
85
 
86
- # ---- Update Marks ----
 
 
 
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
- # ---- Dashboard ----
124
- st.subheader("πŸ“Š Dashboard")
 
 
 
 
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.subheader("Average per Experiment")
135
  exp_avg = df.groupby("Experiment No")["Total"].mean()
136
  st.bar_chart(exp_avg)
137
 
138
  with col2:
139
- st.subheader("Top Students")
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)