File size: 6,909 Bytes
f6aed3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import streamlit as st
import openai
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Paragraph
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
import docx
from docx.shared import Inches
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT

# Set OpenAI API credentials
openai.api_key = "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"
st.markdown("Unleashing Boundless :red[Creativity], Welcome to Lesson Plan generator, created by **:blue[Daniyal]**")


# Apply custom CSS classes to style the app


# Set page title
st.title("A.I Lesson Plan for Teachers")

# Ask for age
age = st.number_input("Enter learner's age", min_value=0, max_value=100, step=1)

# Ask for subject and provide a text area
subject = st.text_area("Enter the subject")
topic= st.text_area("Enter the topic")
board = st.text_area("Enter the board ex: edexcel, aqa, IB or CBSE")
teacher=st.text_area("Enter the Educator's name")


# Complexity levels
complexity_levels = ["Beginner", "Intermediate", "Advanced", "Expert", "Master"]
complexity = st.selectbox("Select the complexity level", complexity_levels)

# Number of days
plan_duration = st.selectbox("Select the duration of the plan", ["1 hour", "1 week", "1 month", "3 months","6 months"])

# Generate lesson plan
if st.button("Generate Lesson Plan"):
    prompt = f"You are tasked to produce a detailed lesson plan for teaching {subject} to {age}-year-old students. The lesson plan should be designed for a duration of {plan_duration}. The lesson should describe the following components:\n\nLesson Title: {topic}\nTeacher Name: {teacher}\n\n Duration: {plan_duration}\n\nKey Vocabulary: \n\nSupporting Material:\n\n. \n\nLearning Outcome:\n\n. \n\nKnowledge:\n\ninclude things students should know about {topic} in brief\n\nSkills:\n\nbecome proficient in {topic} include few example\n\nUnderstanding:\n\nunderstand the concepts of {topic} with an example. Differentiation:\n\ninclude tasks for students needing extra efforts and additional challenge\n\nLearning Experiences:\n\n.\n\nPrepare:\n\nMake a personal connect with the student including an ice breaker to develop interest in the {topic}\n\nPlan:\n\nplan out few activities to better understand the {topic} provide few example activities\n\nInvestigate:\n\nexplore in a structured way to collect and record information\n\nApply:\n\nStudents organize the information practice skills deepen understanding include few questions for student groups\n\nConnect:\n\nconnect and share learning with others.\n\nEvaluate and Reflect:\n\nStudent Assessment:\n\n sample QUESTIONS on {topic}. \n\nEducator Reflection:\n\nEnsure that the lesson plan is aligned with the requirements of the {board} exam board and promotes active learning and engagement. Incorporate appropriate supporting materials and consider the needs of diverse learners. Aim to achieve SMART objectives and create a stimulating learning environment. Once the lesson plan is developed, please provide a detailed description of each component as specified above."
    # Define the prompt for ChatGPT
    # Define the maximum number of tokens for each API call
    response = openai.Completion.create(
        engine="text-davinci-003",
        prompt=prompt,
        max_tokens=3600,
        temperature=0.7,
        n=1,
        stop=None,
    )

    lesson_plan = response.choices[0].text.strip()
    st.subheader("Generated Lesson Plan")
    st.write(lesson_plan)


    def create_word_document(lesson_plan):
        doc = docx.Document()
        
        # Add a section to the document
        section = doc.sections[0]
        
        # Set the header
        header = section.header
        paragraph = header.paragraphs[0]
        
        # Add the logo to the header
        run = paragraph.add_run()
        logo_path = "digitalschool.png"
        run.add_picture(logo_path, width=Inches(1.0), height=Inches(1.0))
        
        # Set the footer
        footer = section.footer
        footer_text = "AI generated lesson plan - By Daniyal"
        footer_paragraph = footer.paragraphs[0]
        footer_paragraph.text = footer_text
        
        # Define the custom subheading style
        doc.styles.add_style("Subheading", docx.enum.style.WD_STYLE_TYPE.PARAGRAPH)
        subheading_style = doc.styles["Subheading"]
        subheading_style.font.bold = True
        subheading_style.font.underline = True
        subheading_style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
        
        # Split the lesson plan into lines
        lines = lesson_plan.split("\n")
        
        # Iterate over the lines and format the subheadings
        for line in lines:
            if line.startswith("Key Vocabulary:") or line.startswith("Supporting Material:") or line.startswith("Learning Outcome:") or line.startswith("Knowledge:") or line.startswith("Skills:") or line.startswith("Understanding:") or line.startswith("Differentiation:") or line.startswith("Learning Experiences:") or line.startswith("Prepare:") or line.startswith("Plan:") or line.startswith("Investigate:") or line.startswith("Apply:") or line.startswith("Connect:") or line.startswith("Evaluate and Reflect:") or line.startswith("Student Assessment:") or line.startswith("Educator Reflection:"):
                doc.add_paragraph(line, style="Subheading")
            else:
                doc.add_paragraph(line)
        
        doc_file = "lesson_plan.docx"
        doc.save(doc_file)
        return doc_file

        
    def create_pdf(lesson_plan):
        pdf_file = "lesson_plan.pdf"
        doc = SimpleDocTemplate(pdf_file, pagesize=letter)
        styles = getSampleStyleSheet()
    
        story = []
        lesson_plan = lesson_plan.replace("\n\n", "<br/><br/>")
    
        # Adjust font size and leading for the lesson plan text
        lesson_plan_style = styles["BodyText"]
        lesson_plan_style.fontSize = 12
        lesson_plan_style.leading = 14
    
        p = Paragraph(lesson_plan, style=lesson_plan_style)
        story.append(p)
    
        doc.build(story)
        return pdf_file


    doc_file = create_word_document(lesson_plan)
    with open(doc_file, "rb") as f:
        doc_data = f.read()

    # Download button for the lesson plan in Word format
    st.download_button(
        label="Download Lesson Plan (Word)",
        data=doc_data,
        file_name="lesson_plan.docx",
        mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    )


    pdf_file = create_pdf(lesson_plan)
    with open(pdf_file, "rb") as f:
        pdf_data = f.read() 

    # Download button for the lesson plan in PDF format
    st.download_button(
        label="Download Lesson Plan (PDF)",
        data=pdf_data,
        file_name="lesson_plan.pdf",
        mime="application/pdf"
    )