msc / app.py
sameernotes's picture
Create app.py
e807081 verified
import streamlit as st
import os
# Set the main directories
SYLLABUS_DIR = "syllabus"
SUBJECT_DIRS = {
"Maths": "paper-1-maths",
"Advanced Operating Systems": "paper-2-advanceOS",
"Data Structures": "paper-3-DS",
"C++ Programming": "paper-4-cplusplus",
"Computer Architecture": "paper-5-computer-architecture"
}
# Helper function to read markdown files
def read_markdown_file(filepath):
with open(filepath, "r") as file:
return file.read()
# Sidebar for navigation
st.sidebar.title("Notes Navigator")
st.sidebar.write("Select a subject and unit to view notes.")
# Syllabus Section
if st.sidebar.checkbox("Show Syllabus"):
st.header("Syllabus")
for subject_file in os.listdir(SYLLABUS_DIR):
file_path = os.path.join(SYLLABUS_DIR, subject_file)
if os.path.isfile(file_path) and subject_file.endswith(".md"):
subject_name = subject_file.replace(".md", "").replace("-", " ").title()
with st.expander(subject_name):
content = read_markdown_file(file_path)
st.markdown(content, unsafe_allow_html=True)
# Subject and Unit Selection
selected_subject = st.sidebar.selectbox("Select Subject", list(SUBJECT_DIRS.keys()))
subject_folder = SUBJECT_DIRS[selected_subject]
# Unit Selection
selected_unit = st.sidebar.selectbox("Select Unit", ["Unit 1", "Unit 2", "Unit 3", "Unit 4", "Unit 5"])
unit_file = f"{selected_unit.lower().replace(' ', '-')}.md"
unit_file_path = os.path.join(subject_folder, unit_file)
# Display selected notes
st.header(f"{selected_subject} - {selected_unit}")
if os.path.exists(unit_file_path):
unit_content = read_markdown_file(unit_file_path)
st.markdown(unit_content, unsafe_allow_html=True)
else:
st.error("The selected notes file does not exist.")