DS_webclass / app /main.py
raymondEDS's picture
Upload 13 files
d1da800 verified
raw
history blame
7.07 kB
import streamlit as st
import os
import glob
import sys
# 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
# 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
# Get class content
def get_class_content(week_number):
# Try different possible paths for class files
possible_paths = [
f"data_science_class_files/class_{week_number}", # Local development
f"app/data_science_class_files/class_{week_number}", # Alternative local path
f"class_{week_number}", # Streamlit Cloud deployment
]
for class_dir in possible_paths:
if os.path.exists(class_dir):
# Get all files in the class directory
files = glob.glob(f"{class_dir}/*")
return {
'directory': class_dir,
'files': [os.path.basename(f) for f in files]
}
return None
# 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}!")
# 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()
# 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
st.title("Data Science Research Paper Course")
# Welcome message for first-time visitors
if st.session_state.current_week == 1:
st.markdown("""
## Welcome to the Data Science Research Paper Course! πŸ“š
This 10-week course will guide you through the process of creating a machine learning research paper.
Each week, you'll learn new concepts and complete tasks that build upon each other.
### Getting Started
1. Use the sidebar to navigate between weeks
2. Complete the weekly tasks and assignments
3. Track your progress using the progress bar
4. Submit your work for feedback
### Course Overview
- Week 1: Research Topic Selection and Literature Review
- Week 2: Data Collection and Preprocessing
- Week 3: Exploratory Data Analysis
- Week 4: Feature Engineering
- Week 5: Model Selection and Baseline
- Week 6: Model Training and Optimization
- Week 7: Model Evaluation
- Week 8: Results Analysis
- Week 9: Paper Writing
- Week 10: Final Review and Submission
""")
# Display current week's content
st.markdown(f"## Week {st.session_state.current_week}")
# Get class content
class_content = get_class_content(st.session_state.current_week)
if class_content:
st.subheader("Class Materials")
# Display files in the class directory
for file in class_content['files']:
file_path = os.path.join(class_content['directory'], file)
# Handle different file types
if file.endswith('.py'):
try:
with open(file_path, 'r') as f:
st.code(f.read(), language='python')
except Exception as e:
st.error(f"Error reading file {file}: {str(e)}")
elif file.endswith('.md'):
try:
with open(file_path, 'r') as f:
st.markdown(f.read())
except Exception as e:
st.error(f"Error reading file {file}: {str(e)}")
elif file.endswith(('.pptx', '.pdf', '.doc', '.docx')):
try:
with open(file_path, 'rb') as f:
st.download_button(
label=f"Download {file}",
data=f.read(),
file_name=file,
mime='application/octet-stream'
)
except Exception as e:
st.error(f"Error reading file {file}: {str(e)}")
else:
st.write(f"- {file}")
else:
st.info("Content for this week is being prepared. Check back soon!")
if __name__ == "__main__":
load_css()
sidebar_navigation()
main()