Spaces:
Sleeping
Sleeping
File size: 3,789 Bytes
a4b11cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
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())
|