sujitv14 commited on
Commit
0c8268f
Β·
verified Β·
1 Parent(s): 12a2fe4

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +150 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,152 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
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()
54
+ df = pd.DataFrame(records)
55
+
56
+ if not df.empty and ((df["Roll No"] == roll) & (df["Experiment No"] == experiment)).any():
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")
90
+ exp_input = st.text_input("Experiment No")
91
+
92
+ attendance_input = st.slider("Attendance", 0, 5, 0)
93
+ oral_input = st.slider("Oral", 0, 5, 0)
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):
104
+
105
+ if str(row["Roll No"]) == roll_input and str(row["Experiment No"]) == exp_input:
106
+
107
+ performance = int(row["Performance"])
108
+ submission = int(row["Submission"])
109
+
110
+ total = attendance_input + oral_input + submission + performance
111
+
112
+ sheet.update_cell(i, 4, attendance_input)
113
+ sheet.update_cell(i, 5, oral_input)
114
+ sheet.update_cell(i, 8, total)
115
+
116
+ st.success("βœ… Marks Updated!")
117
+ found = True
118
+ break
119
+
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)
128
+
129
+ if not df.empty:
130
+
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")