import streamlit as st import pandas as pd import numpy as np import os import time from dotenv import load_dotenv from gpt_method import ( generate_lesson_plan, generate_objectives, generate_materials, generate_steps, generate_assessment ) from lesson_editor import edit_lesson_plan # Load environment variables load_dotenv() # Set page config st.set_page_config( page_title="Lesson Plan Generator", page_icon="📚", layout="wide" ) # Add custom CSS st.markdown(""" """, unsafe_allow_html=True) # Initialize session state for lesson plan if 'lesson_plan' not in st.session_state: st.session_state.lesson_plan = {} # Title and description st.title("📚 Lesson Plan Generator") st.markdown(""" Welcome to the Lesson Plan Generator! This tool helps educators create comprehensive lesson plans. Fill out the form below to generate your lesson plan. """) # Create tabs for Create and Edit tab1, tab2 = st.tabs(["Create New", "Edit Existing"]) with tab1: # Create a form for lesson plan details with st.form("lesson_plan_form"): # Basic Information st.subheader("Basic Information") lesson_name = st.text_input("Course Name (Required)", placeholder="e.g., Data Structures and Algorithms") lesson_theme = st.text_input("Course Theme (Required)", placeholder="e.g., Quick Sort") grade_level = st.selectbox("Student Level (Required)", ["Elementary School", "Middle School", "High School", "College", "Graduate"]) # Learning Objectives st.subheader("Learning Objectives") st.markdown(""" Please enter your course objectives (Optional). If left empty, we will generate them based on Bloom's Taxonomy. Each objective should be on a new line. """) objectives = st.text_area("Course Objectives", height=200) # Materials st.subheader("Materials") materials = st.text_area("List the materials needed for this lesson (One per line)") # Lesson Duration st.subheader("Lesson Duration") duration = st.number_input("Duration (in minutes)", min_value=15, step=15) # Lesson Steps st.subheader("Lesson Steps") steps = st.text_area("Describe the lesson steps (One per line)") # Assessment st.subheader("Assessment") assessment = st.text_area("How will you assess student learning?") # Submit button submitted = st.form_submit_button("Generate Lesson Plan") if submitted: # Show a spinner while generating the lesson plan with st.spinner("Generating your lesson plan..."): try: # Generate missing components if needed if not objectives.strip(): objectives = generate_objectives( lesson_theme, lesson_name=lesson_name, lesson_type=grade_level ) if not materials.strip(): materials = generate_materials(lesson_theme, grade_level) if not steps.strip(): steps = generate_steps(lesson_theme, grade_level, duration) if not assessment.strip(): assessment = generate_assessment(lesson_theme, grade_level) # Generate the complete lesson plan lesson_plan = generate_lesson_plan( lesson_name, lesson_theme, grade_level, objectives, materials, duration, steps, assessment ) # Save to session state st.session_state.lesson_plan = { 'lesson_name': lesson_name, 'lesson_theme': lesson_theme, 'grade_level': grade_level, 'duration': duration, 'objectives': objectives, 'materials': materials, 'steps': steps, 'assessment': assessment, 'full_plan': lesson_plan } # Create a container for the generated lesson plan with st.container(): st.markdown("## Generated Lesson Plan") st.markdown(lesson_plan) # Add a download button for the lesson plan st.download_button( label="Download Lesson Plan", data=lesson_plan, file_name=f"lesson_plan_{lesson_name.lower().replace(' ', '_')}.txt", mime="text/plain" ) except Exception as e: st.error(f"An error occurred while generating the lesson plan: {str(e)}") st.info("Please try again or contact support if the issue persists.") with tab2: edit_lesson_plan()