noname122e1e commited on
Commit
f6aed3a
1 Parent(s): 23162eb

Upload final.py

Browse files
Files changed (1) hide show
  1. final.py +145 -0
final.py ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ from reportlab.lib.pagesizes import letter
4
+ from reportlab.platypus import SimpleDocTemplate, Paragraph
5
+ from reportlab.lib.styles import getSampleStyleSheet
6
+ from reportlab.pdfgen import canvas
7
+ from reportlab.lib.pagesizes import A4
8
+ import docx
9
+ from docx.shared import Inches
10
+ from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
11
+
12
+ # Set OpenAI API credentials
13
+ openai.api_key = "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"
14
+ st.markdown("Unleashing Boundless :red[Creativity], Welcome to Lesson Plan generator, created by **:blue[Daniyal]**")
15
+
16
+
17
+ # Apply custom CSS classes to style the app
18
+
19
+
20
+ # Set page title
21
+ st.title("A.I Lesson Plan for Teachers")
22
+
23
+ # Ask for age
24
+ age = st.number_input("Enter learner's age", min_value=0, max_value=100, step=1)
25
+
26
+ # Ask for subject and provide a text area
27
+ subject = st.text_area("Enter the subject")
28
+ topic= st.text_area("Enter the topic")
29
+ board = st.text_area("Enter the board ex: edexcel, aqa, IB or CBSE")
30
+ teacher=st.text_area("Enter the Educator's name")
31
+
32
+
33
+ # Complexity levels
34
+ complexity_levels = ["Beginner", "Intermediate", "Advanced", "Expert", "Master"]
35
+ complexity = st.selectbox("Select the complexity level", complexity_levels)
36
+
37
+ # Number of days
38
+ plan_duration = st.selectbox("Select the duration of the plan", ["1 hour", "1 week", "1 month", "3 months","6 months"])
39
+
40
+ # Generate lesson plan
41
+ if st.button("Generate Lesson Plan"):
42
+ 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."
43
+ # Define the prompt for ChatGPT
44
+ # Define the maximum number of tokens for each API call
45
+ response = openai.Completion.create(
46
+ engine="text-davinci-003",
47
+ prompt=prompt,
48
+ max_tokens=3600,
49
+ temperature=0.7,
50
+ n=1,
51
+ stop=None,
52
+ )
53
+
54
+ lesson_plan = response.choices[0].text.strip()
55
+ st.subheader("Generated Lesson Plan")
56
+ st.write(lesson_plan)
57
+
58
+
59
+ def create_word_document(lesson_plan):
60
+ doc = docx.Document()
61
+
62
+ # Add a section to the document
63
+ section = doc.sections[0]
64
+
65
+ # Set the header
66
+ header = section.header
67
+ paragraph = header.paragraphs[0]
68
+
69
+ # Add the logo to the header
70
+ run = paragraph.add_run()
71
+ logo_path = "digitalschool.png"
72
+ run.add_picture(logo_path, width=Inches(1.0), height=Inches(1.0))
73
+
74
+ # Set the footer
75
+ footer = section.footer
76
+ footer_text = "AI generated lesson plan - By Daniyal"
77
+ footer_paragraph = footer.paragraphs[0]
78
+ footer_paragraph.text = footer_text
79
+
80
+ # Define the custom subheading style
81
+ doc.styles.add_style("Subheading", docx.enum.style.WD_STYLE_TYPE.PARAGRAPH)
82
+ subheading_style = doc.styles["Subheading"]
83
+ subheading_style.font.bold = True
84
+ subheading_style.font.underline = True
85
+ subheading_style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.LEFT
86
+
87
+ # Split the lesson plan into lines
88
+ lines = lesson_plan.split("\n")
89
+
90
+ # Iterate over the lines and format the subheadings
91
+ for line in lines:
92
+ 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:"):
93
+ doc.add_paragraph(line, style="Subheading")
94
+ else:
95
+ doc.add_paragraph(line)
96
+
97
+ doc_file = "lesson_plan.docx"
98
+ doc.save(doc_file)
99
+ return doc_file
100
+
101
+
102
+ def create_pdf(lesson_plan):
103
+ pdf_file = "lesson_plan.pdf"
104
+ doc = SimpleDocTemplate(pdf_file, pagesize=letter)
105
+ styles = getSampleStyleSheet()
106
+
107
+ story = []
108
+ lesson_plan = lesson_plan.replace("\n\n", "<br/><br/>")
109
+
110
+ # Adjust font size and leading for the lesson plan text
111
+ lesson_plan_style = styles["BodyText"]
112
+ lesson_plan_style.fontSize = 12
113
+ lesson_plan_style.leading = 14
114
+
115
+ p = Paragraph(lesson_plan, style=lesson_plan_style)
116
+ story.append(p)
117
+
118
+ doc.build(story)
119
+ return pdf_file
120
+
121
+
122
+ doc_file = create_word_document(lesson_plan)
123
+ with open(doc_file, "rb") as f:
124
+ doc_data = f.read()
125
+
126
+ # Download button for the lesson plan in Word format
127
+ st.download_button(
128
+ label="Download Lesson Plan (Word)",
129
+ data=doc_data,
130
+ file_name="lesson_plan.docx",
131
+ mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
132
+ )
133
+
134
+
135
+ pdf_file = create_pdf(lesson_plan)
136
+ with open(pdf_file, "rb") as f:
137
+ pdf_data = f.read()
138
+
139
+ # Download button for the lesson plan in PDF format
140
+ st.download_button(
141
+ label="Download Lesson Plan (PDF)",
142
+ data=pdf_data,
143
+ file_name="lesson_plan.pdf",
144
+ mime="application/pdf"
145
+ )