Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,64 +7,51 @@ from datetime import date
|
|
| 7 |
client = genai.Client()
|
| 8 |
|
| 9 |
def generate_lesson_plan(language, grade, subject, topic, students, duration, teacher_name):
|
| 10 |
-
#
|
| 11 |
prompt = f"""
|
| 12 |
You are a qualified and experienced school teacher in Pakistan, well-versed in the National Curriculum of Pakistan.
|
| 13 |
-
Your task is to create a complete and structured "SMART LESSON PLAN" in the language requested by the user (either Urdu or English).
|
| 14 |
|
| 15 |
-
Follow the exact format and structure below without
|
| 16 |
-
Use clear, teacher-friendly, classroom-appropriate language.
|
| 17 |
-
If the selected language is Urdu, write in right-to-left direction using Jameel Noori Nastaleeq font style and write English terms in Urdu script (for example, "Science" as "سائنس", "Homework" as "ہوم ورک").
|
| 18 |
-
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
-------------------------
|
| 21 |
SMART LESSON PLAN
|
| 22 |
|
| 23 |
-
|
| 24 |
-
| Field | Details |
|
| 25 |
-
|--------|----------|
|
| 26 |
-
| Language | {language} |
|
| 27 |
-
| Grade Level | {grade} |
|
| 28 |
-
| Subject | {subject} |
|
| 29 |
-
| Topic | {topic} |
|
| 30 |
-
| Number of Students | {students} |
|
| 31 |
-
| Duration | {duration} minutes |
|
| 32 |
-
| Teacher Name | {teacher_name} |
|
| 33 |
-
| Date | {date.today()} |
|
| 34 |
-
|
| 35 |
-
-------------------------
|
| 36 |
-
|
| 37 |
-
A) **Students Learning Outcomes:**
|
| 38 |
By the end of this lesson, students will be able to:
|
| 39 |
-
1.
|
| 40 |
-
2.
|
| 41 |
-
3.
|
| 42 |
|
| 43 |
-
B)
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
-
C)
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
D)
|
| 50 |
-
(Leave four
|
| 51 |
-
.........................................................................................................................
|
| 52 |
"""
|
| 53 |
|
| 54 |
-
#
|
| 55 |
response = client.models.generate_content(
|
| 56 |
model="gemini-2.5-flash",
|
| 57 |
contents=prompt,
|
| 58 |
)
|
| 59 |
-
|
| 60 |
lesson_text = response.text
|
| 61 |
|
| 62 |
-
#
|
| 63 |
doc = Document()
|
| 64 |
doc.add_heading("SMART LESSON PLAN", level=1)
|
| 65 |
|
| 66 |
# Input Table
|
| 67 |
-
doc.add_paragraph()
|
| 68 |
table = doc.add_table(rows=8, cols=2)
|
| 69 |
table.style = 'Table Grid'
|
| 70 |
fields = [
|
|
@@ -81,18 +68,38 @@ D) **Feedback by the Mentor/ Principal:**
|
|
| 81 |
table.cell(i, 0).text = label
|
| 82 |
table.cell(i, 1).text = value
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
doc.add_paragraph()
|
| 85 |
-
doc.add_paragraph(
|
|
|
|
|
|
|
| 86 |
|
| 87 |
-
#
|
| 88 |
file_name = f"SMART_Lesson_Plan_{topic.replace(' ', '_')}.docx"
|
| 89 |
doc.save(file_name)
|
| 90 |
|
| 91 |
return lesson_text, file_name
|
| 92 |
|
| 93 |
-
|
|
|
|
| 94 |
with gr.Blocks(title="SMART Lesson Plan Generator") as demo:
|
| 95 |
-
gr.Markdown("
|
|
|
|
| 96 |
|
| 97 |
with gr.Row():
|
| 98 |
language = gr.Dropdown(["English", "Urdu"], label="Select Language")
|
|
@@ -100,16 +107,16 @@ with gr.Blocks(title="SMART Lesson Plan Generator") as demo:
|
|
| 100 |
subject = gr.Textbox(label="Subject (e.g., Science)")
|
| 101 |
|
| 102 |
with gr.Row():
|
| 103 |
-
topic = gr.Textbox(label="Topic (e.g., Chemical
|
| 104 |
students = gr.Textbox(label="Number of Students")
|
| 105 |
duration = gr.Textbox(label="Duration (in minutes)")
|
| 106 |
|
| 107 |
with gr.Row():
|
| 108 |
teacher_name = gr.Textbox(label="Teacher Name")
|
| 109 |
|
| 110 |
-
generate_btn = gr.Button("
|
| 111 |
-
output_text = gr.Textbox(label="Generated Lesson Plan", lines=
|
| 112 |
-
download_file = gr.File(label="Download Word File")
|
| 113 |
|
| 114 |
generate_btn.click(
|
| 115 |
generate_lesson_plan,
|
|
@@ -117,5 +124,7 @@ with gr.Blocks(title="SMART Lesson Plan Generator") as demo:
|
|
| 117 |
outputs=[output_text, download_file],
|
| 118 |
)
|
| 119 |
|
| 120 |
-
|
|
|
|
| 121 |
demo.launch()
|
|
|
|
|
|
| 7 |
client = genai.Client()
|
| 8 |
|
| 9 |
def generate_lesson_plan(language, grade, subject, topic, students, duration, teacher_name):
|
| 10 |
+
# Build the structured prompt
|
| 11 |
prompt = f"""
|
| 12 |
You are a qualified and experienced school teacher in Pakistan, well-versed in the National Curriculum of Pakistan.
|
| 13 |
+
Your task is to create a complete and structured "SMART LESSON PLAN" in the language requested by the user (either Urdu or English).
|
| 14 |
|
| 15 |
+
Follow the exact format and structure below without using any symbols or special characters.
|
| 16 |
+
Use clear, teacher-friendly, classroom-appropriate language.
|
| 17 |
+
If the selected language is Urdu, write in right-to-left direction using Jameel Noori Nastaleeq font style and write English terms in Urdu script (for example, "Science" as "سائنس", "Homework" as "ہوم ورک").
|
| 18 |
+
Ensure the lesson content aligns with the given topic and is relevant to Pakistani classrooms.
|
| 19 |
+
|
| 20 |
+
Generate the lesson plan as follows:
|
| 21 |
|
|
|
|
| 22 |
SMART LESSON PLAN
|
| 23 |
|
| 24 |
+
A) Students Learning Outcomes:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
By the end of this lesson, students will be able to:
|
| 26 |
+
1. Write the first clear and measurable SLO aligned with the topic "{topic}".
|
| 27 |
+
2. Write the second clear and measurable SLO aligned with the topic "{topic}".
|
| 28 |
+
3. Write the third clear and measurable SLO aligned with the topic "{topic}".
|
| 29 |
|
| 30 |
+
B) Content to be delivered:
|
| 31 |
+
Write detailed and meaningful content based on "{topic}" and the SLOs, including clear definitions, short explanations, and at least one example that can be taught in the classroom.
|
| 32 |
+
Ensure the content is conceptually sound and suitable for grade {grade} students.
|
| 33 |
|
| 34 |
+
C) Home Assignment:
|
| 35 |
+
Create a simple, practical, and creative home assignment aligned with the above SLOs.
|
| 36 |
+
The assignment should be doable within 24 hours and promote understanding and application of the topic.
|
| 37 |
+
Write actual directions that a teacher would give to students.
|
| 38 |
|
| 39 |
+
D) Feedback by the Mentor/ Principal:
|
| 40 |
+
(Leave four continuous blank lines for handwritten feedback with approximately 2.5 line spacing.)
|
|
|
|
| 41 |
"""
|
| 42 |
|
| 43 |
+
# Generate lesson content using Gemini
|
| 44 |
response = client.models.generate_content(
|
| 45 |
model="gemini-2.5-flash",
|
| 46 |
contents=prompt,
|
| 47 |
)
|
|
|
|
| 48 |
lesson_text = response.text
|
| 49 |
|
| 50 |
+
# Create Word Document
|
| 51 |
doc = Document()
|
| 52 |
doc.add_heading("SMART LESSON PLAN", level=1)
|
| 53 |
|
| 54 |
# Input Table
|
|
|
|
| 55 |
table = doc.add_table(rows=8, cols=2)
|
| 56 |
table.style = 'Table Grid'
|
| 57 |
fields = [
|
|
|
|
| 68 |
table.cell(i, 0).text = label
|
| 69 |
table.cell(i, 1).text = value
|
| 70 |
|
| 71 |
+
# Add lesson sections
|
| 72 |
+
doc.add_paragraph()
|
| 73 |
+
doc.add_paragraph("A) Students Learning Outcomes:", style='Heading2')
|
| 74 |
+
doc.add_paragraph("By the end of this lesson, students will be able to:")
|
| 75 |
+
doc.add_paragraph(lesson_text.split("B)")[0].strip())
|
| 76 |
+
|
| 77 |
+
doc.add_paragraph()
|
| 78 |
+
doc.add_paragraph("B) Content to be delivered:", style='Heading2')
|
| 79 |
+
content_section = lesson_text.split("B)")[1].split("C)")[0].strip()
|
| 80 |
+
doc.add_paragraph(content_section)
|
| 81 |
+
|
| 82 |
+
doc.add_paragraph()
|
| 83 |
+
doc.add_paragraph("C) Home Assignment:", style='Heading2')
|
| 84 |
+
assignment_section = lesson_text.split("C)")[1].split("D)")[0].strip()
|
| 85 |
+
doc.add_paragraph(assignment_section)
|
| 86 |
+
|
| 87 |
doc.add_paragraph()
|
| 88 |
+
doc.add_paragraph("D) Feedback by the Mentor/ Principal:", style='Heading2')
|
| 89 |
+
for _ in range(4):
|
| 90 |
+
doc.add_paragraph(" ")
|
| 91 |
|
| 92 |
+
# Save document
|
| 93 |
file_name = f"SMART_Lesson_Plan_{topic.replace(' ', '_')}.docx"
|
| 94 |
doc.save(file_name)
|
| 95 |
|
| 96 |
return lesson_text, file_name
|
| 97 |
|
| 98 |
+
|
| 99 |
+
# Gradio UI
|
| 100 |
with gr.Blocks(title="SMART Lesson Plan Generator") as demo:
|
| 101 |
+
gr.Markdown("<h2 style='text-align:center;'>SMART Lesson Plan Generator</h2>")
|
| 102 |
+
gr.Markdown("<p style='text-align:center;'>Generate complete, structured lesson plans in Urdu or English for Pakistani classrooms.</p>")
|
| 103 |
|
| 104 |
with gr.Row():
|
| 105 |
language = gr.Dropdown(["English", "Urdu"], label="Select Language")
|
|
|
|
| 107 |
subject = gr.Textbox(label="Subject (e.g., Science)")
|
| 108 |
|
| 109 |
with gr.Row():
|
| 110 |
+
topic = gr.Textbox(label="Topic (e.g., Chemical Bonding)")
|
| 111 |
students = gr.Textbox(label="Number of Students")
|
| 112 |
duration = gr.Textbox(label="Duration (in minutes)")
|
| 113 |
|
| 114 |
with gr.Row():
|
| 115 |
teacher_name = gr.Textbox(label="Teacher Name")
|
| 116 |
|
| 117 |
+
generate_btn = gr.Button("Generate Lesson Plan")
|
| 118 |
+
output_text = gr.Textbox(label="Generated Lesson Plan", lines=25)
|
| 119 |
+
download_file = gr.File(label="Download MS Word File")
|
| 120 |
|
| 121 |
generate_btn.click(
|
| 122 |
generate_lesson_plan,
|
|
|
|
| 124 |
outputs=[output_text, download_file],
|
| 125 |
)
|
| 126 |
|
| 127 |
+
gr.Markdown("<hr><p style='text-align:center;'>Developed by <b>Najaf Ali Sharqi</b></p>")
|
| 128 |
+
|
| 129 |
demo.launch()
|
| 130 |
+
|