Cloudfaith commited on
Commit
a4b11cf
1 Parent(s): d885d70

Copy lesson_plan_streamlit_prototype.py from Github

Browse files
Files changed (1) hide show
  1. lesson_plan_streamlit_prototype.py +101 -0
lesson_plan_streamlit_prototype.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+
4
+ # Streamlit Session State
5
+ if 'learning_objectives' not in st.session_state:
6
+ st.session_state.learning_objectives = ""
7
+
8
+ # Streamlit User Input Form
9
+ st.title("Lesson Plan Generator")
10
+
11
+ # API Key Input
12
+ api_key = st.text_input("Enter your OpenAI API Key:", type="password")
13
+
14
+ # Model Selection Dropdown
15
+ model_choice = st.selectbox(
16
+ "Select the model you want to use:",
17
+ ["gpt-3.5-turbo-0301", "gpt-3.5-turbo-0613", "gpt-3.5-turbo", "gpt-4-0314", "gpt-4-0613", "gpt-4"]
18
+ )
19
+
20
+ # Context, Subject, and Level
21
+ context = "Your goal is to create an effective lesson plan."
22
+ subject = st.text_input("Subject:", "Mathematics")
23
+ level = st.text_input("Education Level:", "High School")
24
+
25
+ # Initialize OpenAI API
26
+ if api_key:
27
+ openai.api_key = api_key
28
+
29
+ # Learning Objectives
30
+ st.write("### Learning Objectives:")
31
+ # Initialize autogenerated objectives
32
+ autogenerated_objectives = ""
33
+ # Initialize status placeholder
34
+ learning_status_placeholder = st.empty()
35
+ disable_button_bool = False
36
+ if subject and level and api_key and st.button("Generate Learning Objectives",key="generate_learning_objectives",disabled=disable_button_bool):
37
+
38
+ # Display status message
39
+ learning_status_placeholder.text("Generating learning objectives...")
40
+ # API call to generate objectives
41
+ learning_objectives_response = openai.ChatCompletion.create(
42
+ model=model_choice,
43
+ messages=[
44
+ {"role": "user", "content": f"Generate learning objectives for a {level} level {subject} lesson."}
45
+ ]
46
+ )
47
+ # Extract the generated objectives from the API response
48
+ learning_objectives=learning_objectives_response['choices'][0]['message']['content']
49
+
50
+ # Save generated objectives to session state
51
+ st.session_state.learning_objectives = learning_objectives.strip()
52
+
53
+ # Display generated objectives
54
+ learning_status_placeholder.text(f"Learning objectives generated!\n{learning_objectives.strip()}")
55
+
56
+ # Generate Lesson Plan Button
57
+ if st.button("Generate Lesson Plan") and api_key:
58
+
59
+ # Construct the prompt as a dictionary
60
+ prompt_dict = {
61
+ "context": context,
62
+ "subject": subject,
63
+ "level": level,
64
+ "learning_objectives": st.session_state.learning_objectives,
65
+ "tasks": [
66
+ {"task": "Curate educational material", "objective": "To provide accurate and relevant information"},
67
+ {"task": "Evaluate the material", "objective": "To ensure alignment with educational standards"},
68
+ {"task": "Create assessment tools", "objective": "To measure student understanding and retention"},
69
+ {"task": "Design interactive activities", "objective": "To facilitate active learning and engagement"}
70
+ ],
71
+ "output_format": """Present the lesson plan in a structured format.
72
+ \nTitle:
73
+ \nGrade Level: RESTATED FROM ABOVE
74
+ \nSubject: RESTATED FROM ABOVE
75
+ \nObjectives: RESTATED FROM ABOVE
76
+ \nActivities:
77
+ \nAssessment: Application of knowledge and skills through a task
78
+ \nProcedure: Formatted as a list of steps and substeps
79
+ \nResources:
80
+ \nNotes:
81
+
82
+ """
83
+ }
84
+
85
+ # Convert the dictionary to a string
86
+ prompt_str = str(prompt_dict)
87
+
88
+ # API call to generate the lesson plan
89
+ lesson_plan_response = openai.ChatCompletion.create(
90
+ model=model_choice,
91
+ messages=[
92
+ {"role": "user", "content": f"Create a lesson plan based on the following parameters: {prompt_str}"}
93
+ ]
94
+ )
95
+
96
+ # Display status message
97
+ lesson_plan=st.text("Generating lesson plan...")
98
+
99
+ # Extract and display the lesson plan
100
+ assistant_reply = lesson_plan_response['choices'][0]['message']['content']
101
+ lesson_plan=st.text(assistant_reply.strip())