File size: 5,976 Bytes
b384740
ff1591a
1f9daab
317ecc2
ff1591a
 
31b89f7
ff1591a
219fbe3
31b89f7
219fbe3
2533efc
317ecc2
b3e725a
ff1591a
7326e44
ff1591a
 
562622a
 
 
 
 
 
 
 
 
 
b3e725a
 
b1d497e
 
317ecc2
 
ff1591a
317ecc2
31b89f7
ff1591a
31b89f7
317ecc2
ff1591a
317ecc2
b3e725a
 
2dd8510
562622a
2dd8510
b3e725a
2dd8510
 
b3e725a
46bbcfc
2dd8510
 
562622a
46bbcfc
562622a
46bbcfc
2dd8510
562622a
46bbcfc
562622a
46bbcfc
562622a
 
46bbcfc
562622a
46bbcfc
562622a
2dd8510
562622a
cfcf065
562622a
 
46bbcfc
562622a
ea7b61a
ff1591a
ea7b61a
 
 
 
 
 
 
 
 
 
 
 
 
2dd8510
b3e725a
562622a
317ecc2
b3e725a
ff1591a
 
 
317ecc2
562622a
b3e725a
2dd8510
 
 
 
562622a
b3e725a
 
 
31b89f7
 
 
b3e725a
317ecc2
562622a
 
d98b657
ff1591a
8fdfb66
 
 
ff1591a
 
8fdfb66
 
 
ff1591a
31b89f7
ff1591a
5a4d69c
a5305ea
fa04077
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
import gradio as gr
from google import genai
from docx import Document
from docx.shared import Pt, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH
import os

# Initialize Gemini client
from google import genai

client = genai.Client(api_key="AIzaSyBNy1L8y-hA8ZV8sgL4Cknw0wStV8koHgg")
def generate_lesson_plan(language, grade, subject, section, topic, teacher, date, students, slo):
    prompt = f"""
You are a qualified and experienced school teacher in Pakistan, fully familiar with the National Curriculum and classroom context.
Create a SMART LESSON PLAN in {language} for the topic "{topic}" with the following details:
Class: {grade},Section: {section} Subject: {subject}, Teacher: {teacher}, Date: {date}, Students: {students}, SLO: {slo}

Rules:
1. Use the logo in center before header in center from the link "https://banner2.cleanpng.com/lnd/20250115/kl/b8b7a261362e1cc2ad46527307e685.webp"
2. Write the header as: "School Education Department Gilgit-Baltistan" ,font syle bold and size 18.
3. Write Second heading and underline "School Education Department Gilgit-Baltistan", font size 24.
4. Include an input table at the top with: Class, Section, Subject, Date, Teacher, Number of Students, Topic.
5. Do NOT repeat this input data after the table.
6. Write the given SLO only with SLO heading
7. After writing SLOs, add a new heading **Content Knowledge** and and use definition and describe key concepts need for each SLO.
8. After content, add an optional **Home Assignment** section that is SMART and aligned with the SLOs.
9. Avoid any extra lines or repetition. Write all text clearly and professionally.
10. English version: All text in English with bold headings. Urdu version: All text in Urdu with English terms in Urdu script, right aligned, and no special characters.

Return full formatted lesson plan text only (no developer credit inside the content).
"""

    response = client.models.generate_content(
        model="gemini-2.5-flash",
        contents=prompt
    )

    lesson_text = response.text.strip()

    if language.lower() == "english":
        # Create Word document for English version
        doc = Document()

        # Header
        header = doc.add_paragraph()
        run = header.add_run("School Education Department Gilgit-Baltistan")
        run.bold = True
        run.font.color.rgb = RGBColor(0, 128, 0)
        header.alignment = WD_ALIGN_PARAGRAPH.CENTER

        # Input table
        table = doc.add_table(rows=4, cols=4)
        table.style = 'Table Grid'
        cells = table.rows[0].cells
        cells[0].text = "Class"
        cells[1].text = str(grade)
        cells[2].text = "Section"
        cells[3].text = str(section)
        cells = table.rows[1].cells
        cells[0].text = "Subject"
        cells[1].text = str(subject)
        cells[2].text = "Date"
        cells[3].text = str(date)
        cells = table.rows[2].cells
        cells[0].text = "Teacher Name"
        cells[1].text = str(teacher)
        cells[2].text = "Number of Students"
        cells[3].text = str(students)
        cells = table.rows[3].cells
        cells[0].text = "Topic"
        # Merge columns 1, 2, 3 into a single cell
        merged_cell = cells[1].merge(cells[2])
        merged_cell = merged_cell.merge(cells[3])
        # Write the topic in merged cell
        merged_cell.text = str(topic)
        
# Add lesson content
        for line in lesson_text.split("\n"):
            if line.strip():
        
                # Write SLO once before each lesson point
                slo_para = doc.add_paragraph(f"SLO: {slo}")
                slo_para.space_after = Pt(12)
        
                # Write the lesson line
                para = doc.add_paragraph(line.strip())
                para.paragraph_format.space_after = Pt(6)
        
                # Bold headings if needed
                if any(line.strip().startswith(h) for h in ["Content Knowledge", "Home Assignment"]):
                    para.runs[0].bold = True

        # Save English file
        file_path = "/tmp/SMART_Lesson_Plan_SED.docx"
        doc.save(file_path)

    else:
        # Urdu version in Markdown
        file_path = "/tmp/SMART_Lesson_Plan_Urdu.md"
        with open(file_path, "w", encoding="utf-8") as f:
            f.write("School Education Department Gilgit-Baltistan\n\n")
            f.write("| درجہ | مضمون | موضوع | استاد |\n")
            f.write(f"| {grade} | {subject} | {topic} | {teacher} |\n\n")
            f.write(f"**تاریخ:** {date}    **طلبہ کی تعداد:** {students}    **دورانیہ:** {duration} منٹ\n\n")
            for line in lesson_text.split("\n"):
                if line.strip():
                    if any(h in line for h in ["SLOs", "Content Knowledge", "Home Assignment"]):
                        f.write(f"**{line.strip()}**\n\n")
                    else:
                        f.write(f"{line.strip()}\n\n")

    return file_path

# Create Gradio UI
with gr.Blocks() as demo:
    gr.Markdown("SMART Lesson Plan (SED)")
    gr.Markdown("Developed by Ashuftah Shigri")
    with gr.Row():
        language = gr.Dropdown(["English", "Urdu"], label="Language")
        grade = gr.Dropdown([f"Class {i}" for i in range(1, 13)], label="Class")
        subject = gr.Dropdown(["English","Urdu", "Islamiyat", "Mathematics", "Science", "Computer", "Chemistry", "Physics", "Biology", "Pakistan Studies"], label="Subject")
        section = gr.Textbox(label="Section")
    topic = gr.Textbox(label="Topic")
    teacher = gr.Textbox(label="Teacher Name")
    date = gr.Textbox(label="Date (DD-MM-YYYY)")
    students = gr.Number(label="Number of Students", value=50)
    slo = gr.Textbox(label="Write SLO")
    btn = gr.Button("Generate Lesson Plan")
    output_file = gr.File(label="Download Lesson Plan")

    btn.click(generate_lesson_plan, inputs=[language, grade, subject, section, topic, teacher, date, students, slo], outputs=output_file)

demo.launch()