Spaces:
Sleeping
Sleeping
Update .gitattributes and .gitignore; modify README.md for formatting; enhance app_new.py with database connection and user authentication; update encrypted_grades.csv with new encrypted data.
Browse files- .gitattributes +35 -35
- .gitignore +1 -1
- README.md +14 -14
- app_new.py +248 -248
- encrypted_grades.csv +1 -1
.gitattributes
CHANGED
|
@@ -1,35 +1,35 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
.streamlit/secrets.toml
|
|
|
|
| 1 |
+
.streamlit/secrets.toml
|
README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: GRADEVIEW
|
| 3 |
-
emoji: ๐
|
| 4 |
-
colorFrom: pink
|
| 5 |
-
colorTo: red
|
| 6 |
-
sdk: streamlit
|
| 7 |
-
sdk_version: 1.39.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: apache-2.0
|
| 11 |
-
short_description: GRADEVIEWING
|
| 12 |
-
---
|
| 13 |
-
|
| 14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: GRADEVIEW
|
| 3 |
+
emoji: ๐
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
sdk_version: 1.39.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: GRADEVIEWING
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app_new.py
CHANGED
|
@@ -1,248 +1,248 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import numpy as np
|
| 4 |
-
from cryptography.fernet import Fernet
|
| 5 |
-
import os
|
| 6 |
-
import io
|
| 7 |
-
from dotenv import load_dotenv
|
| 8 |
-
from google.oauth2.credentials import Credentials
|
| 9 |
-
from google_auth_oauthlib.flow import Flow
|
| 10 |
-
from google.auth.transport.requests import Request
|
| 11 |
-
from googleapiclient.discovery import build
|
| 12 |
-
import json
|
| 13 |
-
import logging
|
| 14 |
-
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
|
| 15 |
-
import secrets
|
| 16 |
-
import time
|
| 17 |
-
import mysql.connector # Add new import
|
| 18 |
-
|
| 19 |
-
# Load environment variables from .env file
|
| 20 |
-
load_dotenv()
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# Set up logging
|
| 24 |
-
logging.basicConfig(level=logging.DEBUG)
|
| 25 |
-
|
| 26 |
-
# Set page configuration
|
| 27 |
-
st.set_page_config(page_title="Midterm Grade for 2nd Sem 2024-2025", page_icon="๐", layout="centered")
|
| 28 |
-
#ADDD
|
| 29 |
-
# Custom CSS to improve the app's appearance
|
| 30 |
-
st.markdown("""
|
| 31 |
-
<style>
|
| 32 |
-
.reportview-container {
|
| 33 |
-
background: #f0f2f6
|
| 34 |
-
}
|
| 35 |
-
.big-font {
|
| 36 |
-
font-size:20px !important;
|
| 37 |
-
font-weight: bold;
|
| 38 |
-
}
|
| 39 |
-
.welcome-message {
|
| 40 |
-
font-size:24px !important;
|
| 41 |
-
font-weight: bold;
|
| 42 |
-
margin-bottom: 20px;
|
| 43 |
-
}
|
| 44 |
-
.stAlert > div {
|
| 45 |
-
padding-top: 15px;
|
| 46 |
-
padding-bottom: 15px;
|
| 47 |
-
}
|
| 48 |
-
.message {
|
| 49 |
-
font-size: 18px;
|
| 50 |
-
font-style: italic;
|
| 51 |
-
margin-top: 20px;
|
| 52 |
-
}
|
| 53 |
-
.warning-message {
|
| 54 |
-
font-size: 18px;
|
| 55 |
-
font-weight: bold;
|
| 56 |
-
color: #ff9800;
|
| 57 |
-
margin-top: 20px;
|
| 58 |
-
}
|
| 59 |
-
</style>
|
| 60 |
-
""", unsafe_allow_html=True)
|
| 61 |
-
|
| 62 |
-
# Google OAuth configuration
|
| 63 |
-
CLIENT_CONFIG = {
|
| 64 |
-
"web": {
|
| 65 |
-
"client_id": os.getenv("GOOGLE_CLIENT_ID"),
|
| 66 |
-
"client_secret": os.getenv("GOOGLE_CLIENT_SECRET"),
|
| 67 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 68 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
| 69 |
-
}
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
SCOPES = ['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'openid']
|
| 73 |
-
|
| 74 |
-
# Function to create OAuth flow
|
| 75 |
-
def create_flow():
|
| 76 |
-
redirect_uri = "https://meng21-gradeview.hf.space/" # Update this with your Streamlit app's URL
|
| 77 |
-
# redirect_uri = "http://192.168.1.18:8501" # local dev
|
| 78 |
-
logging.debug(f"Creating flow with redirect URI: {redirect_uri}")
|
| 79 |
-
flow = Flow.from_client_config(
|
| 80 |
-
client_config=CLIENT_CONFIG,
|
| 81 |
-
scopes=SCOPES,
|
| 82 |
-
redirect_uri=redirect_uri
|
| 83 |
-
)
|
| 84 |
-
return flow
|
| 85 |
-
|
| 86 |
-
# Function to check if the user is logged in
|
| 87 |
-
def is_logged_in():
|
| 88 |
-
return 'credentials' in st.session_state
|
| 89 |
-
|
| 90 |
-
# Function to get user info
|
| 91 |
-
def get_user_info(credentials):
|
| 92 |
-
service = build('oauth2', 'v2', credentials=credentials)
|
| 93 |
-
user_info = service.userinfo().get().execute()
|
| 94 |
-
return user_info
|
| 95 |
-
|
| 96 |
-
# Remove the load_data function and replace with database connection
|
| 97 |
-
def get_db_connection():
|
| 98 |
-
return mysql.connector.connect(
|
| 99 |
-
host=st.secrets.host,
|
| 100 |
-
port=int(st.secrets.port),
|
| 101 |
-
user=st.secrets.user,
|
| 102 |
-
password=st.secrets.password,
|
| 103 |
-
database=st.secrets.database
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
-
# Main function to run the Streamlit app
|
| 107 |
-
def main():
|
| 108 |
-
st.title('๐ Midterm Grade for 2nd Sem 2024-2025')
|
| 109 |
-
st.markdown("---")
|
| 110 |
-
|
| 111 |
-
if not is_logged_in():
|
| 112 |
-
st.write("Please log in with your CSPC Google account to access your grade.")
|
| 113 |
-
|
| 114 |
-
if st.button("Login with Google"):
|
| 115 |
-
flow = create_flow()
|
| 116 |
-
authorization_url, _ = flow.authorization_url(prompt="consent")
|
| 117 |
-
st.markdown(f'<meta http-equiv="refresh" content="0;url={authorization_url}">', unsafe_allow_html=True)
|
| 118 |
-
else:
|
| 119 |
-
credentials = Credentials.from_authorized_user_info(json.loads(st.session_state['credentials']))
|
| 120 |
-
user_info = get_user_info(credentials)
|
| 121 |
-
st.markdown(f"<p class='welcome-message'>Welcome, {user_info['name']}!</p>", unsafe_allow_html=True)
|
| 122 |
-
|
| 123 |
-
try:
|
| 124 |
-
conn = get_db_connection()
|
| 125 |
-
cursor = conn.cursor(dictionary=True)
|
| 126 |
-
|
| 127 |
-
# Get student ID from email
|
| 128 |
-
cursor.execute("""
|
| 129 |
-
SELECT s.student_id, s.name
|
| 130 |
-
FROM students s
|
| 131 |
-
WHERE s.email = %s
|
| 132 |
-
""", (user_info['email'],))
|
| 133 |
-
|
| 134 |
-
student = cursor.fetchone()
|
| 135 |
-
|
| 136 |
-
if student:
|
| 137 |
-
# Get student's courses and grades
|
| 138 |
-
cursor.execute("""
|
| 139 |
-
SELECT c.course_name AS COURSE, e.grade AS GRADE, e.remarks AS REMARKS
|
| 140 |
-
FROM enrollments e
|
| 141 |
-
JOIN courses c ON e.course_code = c.course_code
|
| 142 |
-
WHERE e.student_id = %s
|
| 143 |
-
""", (student['student_id'],))
|
| 144 |
-
|
| 145 |
-
student_records = cursor.fetchall()
|
| 146 |
-
|
| 147 |
-
if not student_records:
|
| 148 |
-
st.error('Your email is not found in our records. Please contact the administrator.')
|
| 149 |
-
else:
|
| 150 |
-
st.markdown("---")
|
| 151 |
-
st.subheader('Your Grade Information:')
|
| 152 |
-
|
| 153 |
-
for record in student_records:
|
| 154 |
-
st.markdown(f"### Course: {record['COURSE']}")
|
| 155 |
-
|
| 156 |
-
col1, col2, col3 = st.columns(3)
|
| 157 |
-
|
| 158 |
-
with col1:
|
| 159 |
-
st.markdown("<p class='big-font'>ID</p>", unsafe_allow_html=True)
|
| 160 |
-
st.write(f"{student['student_id']}")
|
| 161 |
-
|
| 162 |
-
with col2:
|
| 163 |
-
st.markdown("<p class='big-font'>Grade</p>", unsafe_allow_html=True)
|
| 164 |
-
grade = record['GRADE']
|
| 165 |
-
if pd.isna(grade):
|
| 166 |
-
grade_display = "N/A"
|
| 167 |
-
else:
|
| 168 |
-
grade_display = f"{grade:.2f}"
|
| 169 |
-
st.write(grade_display)
|
| 170 |
-
|
| 171 |
-
with col3:
|
| 172 |
-
st.markdown("<p class='big-font'>Remarks</p>", unsafe_allow_html=True)
|
| 173 |
-
remarks = record['REMARKS']
|
| 174 |
-
if remarks == "Passed":
|
| 175 |
-
st.success(remarks)
|
| 176 |
-
elif remarks == "Conditional":
|
| 177 |
-
st.warning(remarks)
|
| 178 |
-
else:
|
| 179 |
-
st.write(remarks)
|
| 180 |
-
|
| 181 |
-
if not pd.isna(grade):
|
| 182 |
-
if grade >= 1.9 and grade <= 3.0:
|
| 183 |
-
message = f"Keep up the good work! Your grade of {grade:.2f} shows dedication. Consider seeking additional support to further improve your performance."
|
| 184 |
-
st.markdown(f"<p class='message'>{message}</p>", unsafe_allow_html=True)
|
| 185 |
-
|
| 186 |
-
elif grade > 3.00:
|
| 187 |
-
message = f"Your grade of {grade:.2f} indicates that you did not meet the passing requirements. Please consult with your instructor to discuss options for improvement and potential remediation."
|
| 188 |
-
st.markdown(f"<p class='message'>{message}</p>", unsafe_allow_html=True)
|
| 189 |
-
else:
|
| 190 |
-
message = f"Congratulations! Your outstanding grade of {grade:.2f} demonstrates exceptional performance. Keep up the excellent work!"
|
| 191 |
-
st.markdown(f"<p class='message'>{message}</p>", unsafe_allow_html=True)
|
| 192 |
-
|
| 193 |
-
if remarks == "Conditional":
|
| 194 |
-
warning_message = "Warning: Your current status is Conditional. You need to pass or achieve a higher grade in the final term to improve your standing."
|
| 195 |
-
st.markdown(f"<p class='warning-message'>{warning_message}</p>", unsafe_allow_html=True)
|
| 196 |
-
|
| 197 |
-
st.markdown("---")
|
| 198 |
-
else:
|
| 199 |
-
st.error('Your email is not found in our records. Please contact the administrator.')
|
| 200 |
-
|
| 201 |
-
conn.close()
|
| 202 |
-
except mysql.connector.Error as err:
|
| 203 |
-
st.error(f"Database error: {err}")
|
| 204 |
-
|
| 205 |
-
# Add refresh button above logout
|
| 206 |
-
col1, col2 = st.columns(2)
|
| 207 |
-
with col1:
|
| 208 |
-
if st.button("๐ Refresh Grades"):
|
| 209 |
-
st.success("Grades refreshed!")
|
| 210 |
-
time.sleep(0.5)
|
| 211 |
-
st.rerun()
|
| 212 |
-
with col2:
|
| 213 |
-
if st.button("๐ช Logout"):
|
| 214 |
-
for key in list(st.session_state.keys()):
|
| 215 |
-
del st.session_state[key]
|
| 216 |
-
st.rerun()
|
| 217 |
-
|
| 218 |
-
# Function to handle OAuth callback
|
| 219 |
-
def handle_callback():
|
| 220 |
-
flow = create_flow()
|
| 221 |
-
try:
|
| 222 |
-
flow.fetch_token(code=st.query_params["code"])
|
| 223 |
-
credentials = flow.credentials
|
| 224 |
-
st.session_state['credentials'] = credentials.to_json()
|
| 225 |
-
logging.debug("Token fetch successful")
|
| 226 |
-
st.success("Authentication successful!")
|
| 227 |
-
time.sleep(2) # Give user time to see the success message
|
| 228 |
-
st.rerun() # Rerun the app to clear the URL parameters
|
| 229 |
-
except Exception as e:
|
| 230 |
-
pass
|
| 231 |
-
# logging.error(f"Error during authentication: {str(e)}")
|
| 232 |
-
# st.error(f"Authentication failed: {str(e)}")
|
| 233 |
-
|
| 234 |
-
# Database configuration
|
| 235 |
-
DB_CONFIG = {
|
| 236 |
-
'host': st.secrets.host,
|
| 237 |
-
'port': int(st.secrets.port),
|
| 238 |
-
'user': st.secrets.user,
|
| 239 |
-
'password': st.secrets.password,
|
| 240 |
-
'database': st.secrets.database
|
| 241 |
-
}
|
| 242 |
-
|
| 243 |
-
if __name__ == '__main__':
|
| 244 |
-
logging.debug("Starting the application")
|
| 245 |
-
if 'code' in st.query_params:
|
| 246 |
-
logging.debug("Authorization code found in query parameters")
|
| 247 |
-
handle_callback()
|
| 248 |
-
main()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from cryptography.fernet import Fernet
|
| 5 |
+
import os
|
| 6 |
+
import io
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
from google.oauth2.credentials import Credentials
|
| 9 |
+
from google_auth_oauthlib.flow import Flow
|
| 10 |
+
from google.auth.transport.requests import Request
|
| 11 |
+
from googleapiclient.discovery import build
|
| 12 |
+
import json
|
| 13 |
+
import logging
|
| 14 |
+
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
|
| 15 |
+
import secrets
|
| 16 |
+
import time
|
| 17 |
+
import mysql.connector # Add new import
|
| 18 |
+
|
| 19 |
+
# Load environment variables from .env file
|
| 20 |
+
load_dotenv()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Set up logging
|
| 24 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 25 |
+
|
| 26 |
+
# Set page configuration
|
| 27 |
+
st.set_page_config(page_title="Midterm Grade for 2nd Sem 2024-2025", page_icon="๐", layout="centered")
|
| 28 |
+
#ADDD
|
| 29 |
+
# Custom CSS to improve the app's appearance
|
| 30 |
+
st.markdown("""
|
| 31 |
+
<style>
|
| 32 |
+
.reportview-container {
|
| 33 |
+
background: #f0f2f6
|
| 34 |
+
}
|
| 35 |
+
.big-font {
|
| 36 |
+
font-size:20px !important;
|
| 37 |
+
font-weight: bold;
|
| 38 |
+
}
|
| 39 |
+
.welcome-message {
|
| 40 |
+
font-size:24px !important;
|
| 41 |
+
font-weight: bold;
|
| 42 |
+
margin-bottom: 20px;
|
| 43 |
+
}
|
| 44 |
+
.stAlert > div {
|
| 45 |
+
padding-top: 15px;
|
| 46 |
+
padding-bottom: 15px;
|
| 47 |
+
}
|
| 48 |
+
.message {
|
| 49 |
+
font-size: 18px;
|
| 50 |
+
font-style: italic;
|
| 51 |
+
margin-top: 20px;
|
| 52 |
+
}
|
| 53 |
+
.warning-message {
|
| 54 |
+
font-size: 18px;
|
| 55 |
+
font-weight: bold;
|
| 56 |
+
color: #ff9800;
|
| 57 |
+
margin-top: 20px;
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
""", unsafe_allow_html=True)
|
| 61 |
+
|
| 62 |
+
# Google OAuth configuration
|
| 63 |
+
CLIENT_CONFIG = {
|
| 64 |
+
"web": {
|
| 65 |
+
"client_id": os.getenv("GOOGLE_CLIENT_ID"),
|
| 66 |
+
"client_secret": os.getenv("GOOGLE_CLIENT_SECRET"),
|
| 67 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
| 68 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
SCOPES = ['https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'openid']
|
| 73 |
+
|
| 74 |
+
# Function to create OAuth flow
|
| 75 |
+
def create_flow():
|
| 76 |
+
redirect_uri = "https://meng21-gradeview.hf.space/" # Update this with your Streamlit app's URL
|
| 77 |
+
# redirect_uri = "http://192.168.1.18:8501" # local dev
|
| 78 |
+
logging.debug(f"Creating flow with redirect URI: {redirect_uri}")
|
| 79 |
+
flow = Flow.from_client_config(
|
| 80 |
+
client_config=CLIENT_CONFIG,
|
| 81 |
+
scopes=SCOPES,
|
| 82 |
+
redirect_uri=redirect_uri
|
| 83 |
+
)
|
| 84 |
+
return flow
|
| 85 |
+
|
| 86 |
+
# Function to check if the user is logged in
|
| 87 |
+
def is_logged_in():
|
| 88 |
+
return 'credentials' in st.session_state
|
| 89 |
+
|
| 90 |
+
# Function to get user info
|
| 91 |
+
def get_user_info(credentials):
|
| 92 |
+
service = build('oauth2', 'v2', credentials=credentials)
|
| 93 |
+
user_info = service.userinfo().get().execute()
|
| 94 |
+
return user_info
|
| 95 |
+
|
| 96 |
+
# Remove the load_data function and replace with database connection
|
| 97 |
+
def get_db_connection():
|
| 98 |
+
return mysql.connector.connect(
|
| 99 |
+
host=st.secrets.host,
|
| 100 |
+
port=int(st.secrets.port),
|
| 101 |
+
user=st.secrets.user,
|
| 102 |
+
password=st.secrets.password,
|
| 103 |
+
database=st.secrets.database
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# Main function to run the Streamlit app
|
| 107 |
+
def main():
|
| 108 |
+
st.title('๐ Midterm Grade for 2nd Sem 2024-2025')
|
| 109 |
+
st.markdown("---")
|
| 110 |
+
|
| 111 |
+
if not is_logged_in():
|
| 112 |
+
st.write("Please log in with your CSPC Google account to access your grade.")
|
| 113 |
+
|
| 114 |
+
if st.button("Login with Google"):
|
| 115 |
+
flow = create_flow()
|
| 116 |
+
authorization_url, _ = flow.authorization_url(prompt="consent")
|
| 117 |
+
st.markdown(f'<meta http-equiv="refresh" content="0;url={authorization_url}">', unsafe_allow_html=True)
|
| 118 |
+
else:
|
| 119 |
+
credentials = Credentials.from_authorized_user_info(json.loads(st.session_state['credentials']))
|
| 120 |
+
user_info = get_user_info(credentials)
|
| 121 |
+
st.markdown(f"<p class='welcome-message'>Welcome, {user_info['name']}!</p>", unsafe_allow_html=True)
|
| 122 |
+
|
| 123 |
+
try:
|
| 124 |
+
conn = get_db_connection()
|
| 125 |
+
cursor = conn.cursor(dictionary=True)
|
| 126 |
+
|
| 127 |
+
# Get student ID from email
|
| 128 |
+
cursor.execute("""
|
| 129 |
+
SELECT s.student_id, s.name
|
| 130 |
+
FROM students s
|
| 131 |
+
WHERE s.email = %s
|
| 132 |
+
""", (user_info['email'],))
|
| 133 |
+
|
| 134 |
+
student = cursor.fetchone()
|
| 135 |
+
|
| 136 |
+
if student:
|
| 137 |
+
# Get student's courses and grades
|
| 138 |
+
cursor.execute("""
|
| 139 |
+
SELECT c.course_name AS COURSE, e.grade AS GRADE, e.remarks AS REMARKS
|
| 140 |
+
FROM enrollments e
|
| 141 |
+
JOIN courses c ON e.course_code = c.course_code
|
| 142 |
+
WHERE e.student_id = %s
|
| 143 |
+
""", (student['student_id'],))
|
| 144 |
+
|
| 145 |
+
student_records = cursor.fetchall()
|
| 146 |
+
|
| 147 |
+
if not student_records:
|
| 148 |
+
st.error('Your email is not found in our records. Please contact the administrator.')
|
| 149 |
+
else:
|
| 150 |
+
st.markdown("---")
|
| 151 |
+
st.subheader('Your Grade Information:')
|
| 152 |
+
|
| 153 |
+
for record in student_records:
|
| 154 |
+
st.markdown(f"### Course: {record['COURSE']}")
|
| 155 |
+
|
| 156 |
+
col1, col2, col3 = st.columns(3)
|
| 157 |
+
|
| 158 |
+
with col1:
|
| 159 |
+
st.markdown("<p class='big-font'>ID</p>", unsafe_allow_html=True)
|
| 160 |
+
st.write(f"{student['student_id']}")
|
| 161 |
+
|
| 162 |
+
with col2:
|
| 163 |
+
st.markdown("<p class='big-font'>Grade</p>", unsafe_allow_html=True)
|
| 164 |
+
grade = record['GRADE']
|
| 165 |
+
if pd.isna(grade):
|
| 166 |
+
grade_display = "N/A"
|
| 167 |
+
else:
|
| 168 |
+
grade_display = f"{grade:.2f}"
|
| 169 |
+
st.write(grade_display)
|
| 170 |
+
|
| 171 |
+
with col3:
|
| 172 |
+
st.markdown("<p class='big-font'>Remarks</p>", unsafe_allow_html=True)
|
| 173 |
+
remarks = record['REMARKS']
|
| 174 |
+
if remarks == "Passed":
|
| 175 |
+
st.success(remarks)
|
| 176 |
+
elif remarks == "Conditional":
|
| 177 |
+
st.warning(remarks)
|
| 178 |
+
else:
|
| 179 |
+
st.write(remarks)
|
| 180 |
+
|
| 181 |
+
if not pd.isna(grade):
|
| 182 |
+
if grade >= 1.9 and grade <= 3.0:
|
| 183 |
+
message = f"Keep up the good work! Your grade of {grade:.2f} shows dedication. Consider seeking additional support to further improve your performance."
|
| 184 |
+
st.markdown(f"<p class='message'>{message}</p>", unsafe_allow_html=True)
|
| 185 |
+
|
| 186 |
+
elif grade > 3.00:
|
| 187 |
+
message = f"Your grade of {grade:.2f} indicates that you did not meet the passing requirements. Please consult with your instructor to discuss options for improvement and potential remediation."
|
| 188 |
+
st.markdown(f"<p class='message'>{message}</p>", unsafe_allow_html=True)
|
| 189 |
+
else:
|
| 190 |
+
message = f"Congratulations! Your outstanding grade of {grade:.2f} demonstrates exceptional performance. Keep up the excellent work!"
|
| 191 |
+
st.markdown(f"<p class='message'>{message}</p>", unsafe_allow_html=True)
|
| 192 |
+
|
| 193 |
+
if remarks == "Conditional":
|
| 194 |
+
warning_message = "Warning: Your current status is Conditional. You need to pass or achieve a higher grade in the final term to improve your standing."
|
| 195 |
+
st.markdown(f"<p class='warning-message'>{warning_message}</p>", unsafe_allow_html=True)
|
| 196 |
+
|
| 197 |
+
st.markdown("---")
|
| 198 |
+
else:
|
| 199 |
+
st.error('Your email is not found in our records. Please contact the administrator.')
|
| 200 |
+
|
| 201 |
+
conn.close()
|
| 202 |
+
except mysql.connector.Error as err:
|
| 203 |
+
st.error(f"Database error: {err}")
|
| 204 |
+
|
| 205 |
+
# Add refresh button above logout
|
| 206 |
+
col1, col2 = st.columns(2)
|
| 207 |
+
with col1:
|
| 208 |
+
if st.button("๐ Refresh Grades"):
|
| 209 |
+
st.success("Grades refreshed!")
|
| 210 |
+
time.sleep(0.5)
|
| 211 |
+
st.rerun()
|
| 212 |
+
with col2:
|
| 213 |
+
if st.button("๐ช Logout"):
|
| 214 |
+
for key in list(st.session_state.keys()):
|
| 215 |
+
del st.session_state[key]
|
| 216 |
+
st.rerun()
|
| 217 |
+
|
| 218 |
+
# Function to handle OAuth callback
|
| 219 |
+
def handle_callback():
|
| 220 |
+
flow = create_flow()
|
| 221 |
+
try:
|
| 222 |
+
flow.fetch_token(code=st.query_params["code"])
|
| 223 |
+
credentials = flow.credentials
|
| 224 |
+
st.session_state['credentials'] = credentials.to_json()
|
| 225 |
+
logging.debug("Token fetch successful")
|
| 226 |
+
st.success("Authentication successful!")
|
| 227 |
+
time.sleep(2) # Give user time to see the success message
|
| 228 |
+
st.rerun() # Rerun the app to clear the URL parameters
|
| 229 |
+
except Exception as e:
|
| 230 |
+
pass
|
| 231 |
+
# logging.error(f"Error during authentication: {str(e)}")
|
| 232 |
+
# st.error(f"Authentication failed: {str(e)}")
|
| 233 |
+
|
| 234 |
+
# Database configuration
|
| 235 |
+
DB_CONFIG = {
|
| 236 |
+
'host': st.secrets.host,
|
| 237 |
+
'port': int(st.secrets.port),
|
| 238 |
+
'user': st.secrets.user,
|
| 239 |
+
'password': st.secrets.password,
|
| 240 |
+
'database': st.secrets.database
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
if __name__ == '__main__':
|
| 244 |
+
logging.debug("Starting the application")
|
| 245 |
+
if 'code' in st.query_params:
|
| 246 |
+
logging.debug("Authorization code found in query parameters")
|
| 247 |
+
handle_callback()
|
| 248 |
+
main()
|
encrypted_grades.csv
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
gAAAAABo5y_BCTV_fnnDYy2MnSK3bLP-WoT4M8B4qbjiolP1ZLVw-rtyOlwnKWzHfxB1T0vzoq84sU0McZt8YdC5qvjOaeBydzY5mEgAbpw0zyqDUKg-kF9y1K9lQnK-K4st7d_5S4q-AGdJi4N4V3uXRReFmtxGle-YJ2gfiUtleUJ_uO19ZhJYPYopnoU6XR3HU4_PlABWZPzxpiUjzL203G3Pp2mqYjpvbI5oU4Qh3qd94gTa_O03vihHywtbiB6EwKjMkFL-xJzPFi76SEoLNIsxQHHr8-HeW4KqM4cRPjucO-NrkmF6wcDN5SUpCJH-BL1GnkT7gZqy_YQ-Btzwupt5TSvYuvVM4cYkiiQGXmydmyyIudRvdnUoqDmUNj9B9ew5Peu1phJKdJrWu0lIo8a5FC5YVa4Ks0vyhl7RH_027ccIA-rTmwegxQMpSNO8YQy5zVuu6zUiz7giv76RRI_gh1bwcJW6KwoLvTuPXjzPU7fFdX52--d-Xy37Gdizoe1fJlPMh4xlXnwrPLOOtZfNAX5zqNedqilOf_Bchub-9ULMnWT6mRMHjiGtf3RAyDzUFWunmGg5I8L1Sy2qAD2iKNqQjHLEI_XFQiUv_bLnMJaxpyyM4P_fcRs58KRTn9DleWWHqj6Ze6zqe0-87IPVHxuxOV2mETu6gQNwL-pzixUwrega57xcKV_Uz_H1Gnyx5GeiGw0Ov5Cp11pqcGrd47aElctZwzP6SSSp9zcD2pmjQMmUp71M_ZxcRioC82Qnqu7G3YiA8PV36iOoZOcETb7W31pSmlr2vTqHFlOZmkVHdCLHbdFqrKTVYTnYvT9fbRpKJt4yMCVml8ohUXV-S-6c_SbgpMv7LdUDvKHe7Tz1h0Aq9fk9W4er-z_x7PVjfGFk3EVGuYlZHh8YwclQkihmMvADcJe4EvLImm6wiF2pzz2NqMdgQjRCvU8l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