import streamlit as st import openai # Streamlit Session State if 'learning_objectives' not in st.session_state: st.session_state.learning_objectives = "" # Streamlit User Input Form st.title("Lesson Plan Generator") # API Key Input api_key = st.text_input("Enter your OpenAI API Key:", type="password") # Model Selection Dropdown model_choice = st.selectbox( "Select the model you want to use:", ["gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo", "gpt-4-0314", "gpt-4-0613", "gpt-4"] ) # Context, Subject, and Level context = "Your goal is to create an effective lesson plan." subject = st.text_input("Subject:", "Mathematics") level = st.text_input("Education Level:", "High School") # Initialize OpenAI API if api_key: openai.api_key = api_key # Learning Objectives st.write("### Learning Objectives:") # Initialize autogenerated objectives autogenerated_objectives = "" # Initialize status placeholder learning_status_placeholder = st.empty() disable_button_bool = False if subject and level and api_key and st.button("Generate Learning Objectives",key="generate_learning_objectives",disabled=disable_button_bool): # Display status message learning_status_placeholder.text("Generating learning objectives...") # API call to generate objectives learning_objectives_response = openai.ChatCompletion.create( model=model_choice, messages=[ {"role": "user", "content": f"Generate learning objectives for a {level} level {subject} lesson."} ] ) # Extract the generated objectives from the API response learning_objectives=learning_objectives_response['choices'][0]['message']['content'] # Save generated objectives to session state st.session_state.learning_objectives = learning_objectives.strip() # Display generated objectives learning_status_placeholder.text(f"Learning objectives generated!\n{learning_objectives.strip()}") # Generate Lesson Plan Button if st.button("Generate Lesson Plan") and api_key: # Construct the prompt as a dictionary prompt_dict = { "context": context, "subject": subject, "level": level, "learning_objectives": st.session_state.learning_objectives, "tasks": [ {"task": "Curate educational material", "objective": "To provide accurate and relevant information"}, {"task": "Evaluate the material", "objective": "To ensure alignment with educational standards"}, {"task": "Create assessment tools", "objective": "To measure student understanding and retention"}, {"task": "Design interactive activities", "objective": "To facilitate active learning and engagement"} ], "output_format": """Present the lesson plan in a structured format. \nTitle: \nGrade Level: RESTATED FROM ABOVE \nSubject: RESTATED FROM ABOVE \nObjectives: RESTATED FROM ABOVE \nActivities: \nAssessment: Application of knowledge and skills through a task \nProcedure: Formatted as a list of steps and substeps \nResources: \nNotes: """ } # Convert the dictionary to a string prompt_str = str(prompt_dict) # API call to generate the lesson plan lesson_plan_response = openai.ChatCompletion.create( model=model_choice, messages=[ {"role": "user", "content": f"Create a lesson plan based on the following parameters: {prompt_str}"} ] ) # Display status message lesson_plan=st.text("Generating lesson plan...") # Extract and display the lesson plan assistant_reply = lesson_plan_response['choices'][0]['message']['content'] lesson_plan=st.text(assistant_reply.strip())