Spaces:
Sleeping
Sleeping
app.py
CHANGED
|
@@ -79,6 +79,12 @@ def create_flow():
|
|
| 79 |
def is_logged_in():
|
| 80 |
return 'credentials' in st.session_state
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
# Load and decrypt the CSV file
|
| 83 |
@st.cache_data
|
| 84 |
def load_data():
|
|
@@ -97,16 +103,6 @@ def load_data():
|
|
| 97 |
st.error(f"Error decrypting file: {str(e)}")
|
| 98 |
return pd.DataFrame()
|
| 99 |
|
| 100 |
-
# Function to get user info
|
| 101 |
-
def get_user_info(credentials):
|
| 102 |
-
try:
|
| 103 |
-
service = build('oauth2', 'v2', credentials=credentials)
|
| 104 |
-
user_info = service.userinfo().get().execute()
|
| 105 |
-
return user_info
|
| 106 |
-
except Exception as e:
|
| 107 |
-
logging.error(f"Error getting user info: {str(e)}")
|
| 108 |
-
return None
|
| 109 |
-
|
| 110 |
# Main function to run the Streamlit app
|
| 111 |
def main():
|
| 112 |
st.title('📚 Student Grade Lookup')
|
|
@@ -122,65 +118,58 @@ def main():
|
|
| 122 |
else:
|
| 123 |
credentials = Credentials.from_authorized_user_info(json.loads(st.session_state['credentials']))
|
| 124 |
user_info = get_user_info(credentials)
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
-
|
| 131 |
-
df = load_data()
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
if not student.empty:
|
| 137 |
-
st.markdown("---")
|
| 138 |
-
st.subheader('Your Grade Information:')
|
| 139 |
-
|
| 140 |
-
# Display student information in a more structured way
|
| 141 |
-
col1, col2 = st.columns(2)
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
if pd.isna(grade):
|
| 155 |
-
grade_display = "N/A"
|
| 156 |
-
else:
|
| 157 |
-
grade_display = f"{grade:.2f}"
|
| 158 |
-
st.write(grade_display)
|
| 159 |
-
|
| 160 |
-
st.markdown("<p class='big-font'>Remarks</p>", unsafe_allow_html=True)
|
| 161 |
-
remarks = student['REMARKS'].values[0]
|
| 162 |
-
if remarks == "Passed":
|
| 163 |
-
st.success(remarks)
|
| 164 |
-
elif remarks == "Conditional":
|
| 165 |
-
st.warning(remarks)
|
| 166 |
-
else:
|
| 167 |
-
st.write(remarks)
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
if
|
| 180 |
-
|
| 181 |
-
st.markdown(f"<p class='
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
if st.button("Logout"):
|
| 186 |
for key in list(st.session_state.keys()):
|
|
@@ -194,7 +183,6 @@ def handle_callback():
|
|
| 194 |
flow.fetch_token(code=st.query_params["code"])
|
| 195 |
credentials = flow.credentials
|
| 196 |
st.session_state['credentials'] = credentials.to_json()
|
| 197 |
-
st.session_state['authenticated'] = True
|
| 198 |
logging.debug("Token fetch successful")
|
| 199 |
st.success("Authentication successful!")
|
| 200 |
time.sleep(2) # Give user time to see the success message
|
|
@@ -202,15 +190,10 @@ def handle_callback():
|
|
| 202 |
except Exception as e:
|
| 203 |
logging.error(f"Error during authentication: {str(e)}")
|
| 204 |
st.error(f"Authentication failed: {str(e)}")
|
| 205 |
-
st.session_state['authenticated'] = False
|
| 206 |
-
if 'credentials' in st.session_state:
|
| 207 |
-
del st.session_state['credentials']
|
| 208 |
|
| 209 |
if __name__ == '__main__':
|
| 210 |
logging.debug("Starting the application")
|
| 211 |
if 'code' in st.query_params:
|
| 212 |
logging.debug("Authorization code found in query parameters")
|
| 213 |
handle_callback()
|
| 214 |
-
elif st.session_state.get('authenticated', False):
|
| 215 |
-
st.success("You are already authenticated.")
|
| 216 |
main()
|
|
|
|
| 79 |
def is_logged_in():
|
| 80 |
return 'credentials' in st.session_state
|
| 81 |
|
| 82 |
+
# Function to get user info
|
| 83 |
+
def get_user_info(credentials):
|
| 84 |
+
service = build('oauth2', 'v2', credentials=credentials)
|
| 85 |
+
user_info = service.userinfo().get().execute()
|
| 86 |
+
return user_info
|
| 87 |
+
|
| 88 |
# Load and decrypt the CSV file
|
| 89 |
@st.cache_data
|
| 90 |
def load_data():
|
|
|
|
| 103 |
st.error(f"Error decrypting file: {str(e)}")
|
| 104 |
return pd.DataFrame()
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
# Main function to run the Streamlit app
|
| 107 |
def main():
|
| 108 |
st.title('📚 Student Grade Lookup')
|
|
|
|
| 118 |
else:
|
| 119 |
credentials = Credentials.from_authorized_user_info(json.loads(st.session_state['credentials']))
|
| 120 |
user_info = get_user_info(credentials)
|
| 121 |
+
st.write(f"Welcome, {user_info['name']}!")
|
| 122 |
|
| 123 |
+
# Load the data
|
| 124 |
+
df = load_data()
|
| 125 |
+
|
| 126 |
+
# Look up the student's information using their email
|
| 127 |
+
student = df[df['EMAIL'].str.lower() == user_info['email'].lower()]
|
| 128 |
+
|
| 129 |
+
if not student.empty:
|
| 130 |
+
st.markdown("---")
|
| 131 |
+
st.subheader('Your Grade Information:')
|
| 132 |
|
| 133 |
+
col1, col2 = st.columns(2)
|
|
|
|
| 134 |
|
| 135 |
+
with col1:
|
| 136 |
+
st.markdown("<p class='big-font'>Name</p>", unsafe_allow_html=True)
|
| 137 |
+
st.write(f"{student['NAME'].values[0]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
st.markdown("<p class='big-font'>ID</p>", unsafe_allow_html=True)
|
| 140 |
+
st.write(f"{student['ID'].values[0]}")
|
| 141 |
+
|
| 142 |
+
with col2:
|
| 143 |
+
st.markdown("<p class='big-font'>Grade</p>", unsafe_allow_html=True)
|
| 144 |
+
grade = student['GRADE'].values[0]
|
| 145 |
+
if pd.isna(grade):
|
| 146 |
+
grade_display = "N/A"
|
| 147 |
+
else:
|
| 148 |
+
grade_display = f"{grade:.2f}"
|
| 149 |
+
st.write(grade_display)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
st.markdown("<p class='big-font'>Remarks</p>", unsafe_allow_html=True)
|
| 152 |
+
remarks = student['REMARKS'].values[0]
|
| 153 |
+
if remarks == "Passed":
|
| 154 |
+
st.success(remarks)
|
| 155 |
+
elif remarks == "Conditional":
|
| 156 |
+
st.warning(remarks)
|
| 157 |
+
else:
|
| 158 |
+
st.write(remarks)
|
| 159 |
+
|
| 160 |
+
if not pd.isna(grade):
|
| 161 |
+
if grade > 1.9:
|
| 162 |
+
message = f"Keep up the good work! Your grade of {grade:.2f} shows dedication. Consider seeking additional support to further improve your performance."
|
| 163 |
+
st.markdown(f"<p class='message'>{message}</p>", unsafe_allow_html=True)
|
| 164 |
+
else:
|
| 165 |
+
message = f"Congratulations! Your outstanding grade of {grade:.2f} demonstrates exceptional performance. Keep up the excellent work!"
|
| 166 |
+
st.markdown(f"<p class='message'>{message}</p>", unsafe_allow_html=True)
|
| 167 |
+
|
| 168 |
+
if remarks == "Conditional":
|
| 169 |
+
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."
|
| 170 |
+
st.markdown(f"<p class='warning-message'>{warning_message}</p>", unsafe_allow_html=True)
|
| 171 |
+
else:
|
| 172 |
+
st.error('Your email is not found in our records. Please contact the administrator.')
|
| 173 |
|
| 174 |
if st.button("Logout"):
|
| 175 |
for key in list(st.session_state.keys()):
|
|
|
|
| 183 |
flow.fetch_token(code=st.query_params["code"])
|
| 184 |
credentials = flow.credentials
|
| 185 |
st.session_state['credentials'] = credentials.to_json()
|
|
|
|
| 186 |
logging.debug("Token fetch successful")
|
| 187 |
st.success("Authentication successful!")
|
| 188 |
time.sleep(2) # Give user time to see the success message
|
|
|
|
| 190 |
except Exception as e:
|
| 191 |
logging.error(f"Error during authentication: {str(e)}")
|
| 192 |
st.error(f"Authentication failed: {str(e)}")
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
if __name__ == '__main__':
|
| 195 |
logging.debug("Starting the application")
|
| 196 |
if 'code' in st.query_params:
|
| 197 |
logging.debug("Authorization code found in query parameters")
|
| 198 |
handle_callback()
|
|
|
|
|
|
|
| 199 |
main()
|