Spaces:
Running
Running
import streamlit as st | |
import os | |
import glob | |
import sys | |
import numpy as np | |
import plotly.graph_objects as go | |
from sklearn.linear_model import LinearRegression | |
# Add the parent directory to the Python path | |
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
# Import the login component | |
from app.components.login import login | |
# Import week pages | |
from app.pages import week_1 | |
from app.pages import week_2 | |
from app.pages import week_3 | |
# Page configuration | |
st.set_page_config( | |
page_title="Data Science Course App", | |
page_icon="π", | |
layout="wide", | |
initial_sidebar_state="expanded" | |
) | |
# Custom CSS | |
def load_css(): | |
try: | |
with open('assets/style.css') as f: | |
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True) | |
except FileNotFoundError: | |
# Fallback for Streamlit Cloud deployment | |
st.markdown(""" | |
<style> | |
/* Main title styling */ | |
.main .block-container h1 { | |
color: #2c3e50; | |
font-size: 2.5rem; | |
margin-bottom: 1rem; | |
} | |
/* Subtitle styling */ | |
.main .block-container h2 { | |
color: #34495e; | |
font-size: 1.8rem; | |
margin-top: 2rem; | |
margin-bottom: 1rem; | |
} | |
/* Sidebar styling */ | |
.sidebar .sidebar-content { | |
background-color: #f8f9fa; | |
} | |
/* Button styling */ | |
.stButton>button { | |
width: 100%; | |
border-radius: 5px; | |
height: 3em; | |
margin: 0.5em 0; | |
background-color: #3498db; | |
color: white; | |
border: none; | |
} | |
.stButton>button:hover { | |
background-color: #2980b9; | |
} | |
/* Progress bar styling */ | |
.stProgress > div > div { | |
background-color: #2ecc71; | |
} | |
/* Info box styling */ | |
.stAlert { | |
border-radius: 5px; | |
padding: 1rem; | |
margin: 1rem 0; | |
} | |
/* Code block styling */ | |
.stCodeBlock { | |
background-color: #f8f9fa; | |
border-radius: 5px; | |
padding: 1rem; | |
margin: 1rem 0; | |
} | |
</style> | |
""", unsafe_allow_html=True) | |
# Initialize session state | |
if 'current_week' not in st.session_state: | |
st.session_state.current_week = 1 | |
if 'logged_in' not in st.session_state: | |
st.session_state.logged_in = False | |
# Sidebar navigation | |
def sidebar_navigation(): | |
with st.sidebar: | |
st.title("Course Navigation") | |
# Show username if logged in | |
if st.session_state.logged_in: | |
st.write(f"Welcome, {st.session_state.username}!") | |
# Debug button to show current week | |
if st.session_state.username == "admin": | |
if st.button("Debug: Show Current Week"): | |
st.write(f"Current week: {st.session_state.current_week}") | |
# Logout button | |
if st.button("Logout"): | |
st.session_state.logged_in = False | |
st.session_state.username = None | |
st.rerun() | |
st.markdown("---") | |
st.subheader("Course Progress") | |
progress = st.progress(st.session_state.current_week / 10) | |
st.write(f"Week {st.session_state.current_week} of 10") | |
st.markdown("---") | |
st.subheader("Quick Links") | |
for week in range(1, 11): | |
if st.button(f"Week {week}", key=f"week_{week}"): | |
st.session_state.current_week = week | |
st.rerun() | |
def show_week_content(): | |
# Debug print to show current week | |
st.write(f"Debug: Current week is {st.session_state.current_week}") | |
if st.session_state.current_week == 1: | |
week_1.show() | |
elif st.session_state.current_week == 2: | |
week_2.show() | |
elif st.session_state.current_week == 3: | |
week_3.show() | |
else: | |
st.warning("Content for this week is not yet available.") | |
# Main content | |
def main(): | |
# Check if user is logged in | |
if not st.session_state.logged_in: | |
# Show login page | |
login() | |
return | |
# User is logged in, show course content | |
if st.session_state.current_week in [1, 2, 3]: | |
show_week_content() | |
else: | |
st.title("Data Science Research Paper Course") | |
st.markdown(""" | |
## Welcome to the Data Science Research Paper Course! π | |
This section has not bee released yet. | |
""") | |
if __name__ == "__main__": | |
load_css() | |
sidebar_navigation() | |
main() |