| import os |
| import datetime |
| import gradio as gr |
| from docx import Document |
| from groq import Groq |
|
|
| |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") |
| client = Groq(api_key=GROQ_API_KEY) |
|
|
| |
| def generate_backward_plan(class_, subject, topic, students, duration, date, teacher): |
| |
| prompt_en = f""" |
| Generate a detailed lesson plan for Pakistani Curriculum using the BACKWARD DESIGN model. |
| Follow these three stages clearly: |
| |
| 1. Stage 1 – Identify Desired Results (Learning Outcomes aligned with Pakistan Curriculum) |
| 2. Stage 2 – Determine Acceptable Evidence (Assessment aligned with SLOs) |
| 3. Stage 3 – Plan Learning Experiences and Instruction (Activities, Methods, Resources) |
| |
| Lesson Information: |
| Class: {class_} |
| Subject: {subject} |
| Topic: {topic} |
| Number of Students: {students} |
| Duration: {duration} minutes |
| Date: {date} |
| Teacher: {teacher} |
| |
| Ensure relevance to Pakistani educational context. |
| """ |
|
|
| completion_en = client.chat.completions.create( |
| model="llama-3.1-8b-instant", |
| messages=[ |
| {"role": "system", "content": "You are an expert Pakistani curriculum lesson planner."}, |
| {"role": "user", "content": prompt_en}, |
| ], |
| ) |
|
|
| english_plan = completion_en.choices[0].message.content.strip() |
|
|
| |
| docx_file = f"Backward_Design_Lesson_{teacher}_EN.docx" |
| doc = Document() |
| doc.add_heading("Backward Design Lesson Plan (Pakistan Curriculum)", 0) |
| doc.add_paragraph(f"Class: {class_}") |
| doc.add_paragraph(f"Subject: {subject}") |
| doc.add_paragraph(f"Topic: {topic}") |
| doc.add_paragraph(f"Number of Students: {students}") |
| doc.add_paragraph(f"Duration: {duration} minutes") |
| doc.add_paragraph(f"Date: {date}") |
| doc.add_paragraph(f"Teacher: {teacher}") |
| doc.add_paragraph("\n" + english_plan) |
| doc.add_paragraph("\nDeveloped by Najaf Ali Sharqi") |
| doc.save(docx_file) |
|
|
| |
| prompt_ur = f""" |
| پاکستان کے نصاب (کریکولم) کے مطابق "بیکورڈ ڈیزائن" ماڈل پر مبنی تفصیلی سبق کا منصوبہ اردو میں تیار کریں۔ |
| تین مراحل کو واضح طور پر شامل کریں: |
| |
| 1. مرحلہ اوّل – مطلوبہ نتائج کی شناخت (مقاصدِ سبق / ایس ایل اوز) |
| 2. مرحلہ دوم – قابلِ قبول شواہد کا تعین (تشخیص) |
| 3. مرحلہ سوم – تدریسی تجربات اور سرگرمیوں کی منصوبہ بندی (طرزِ تدریس، وسائل، طلباء کی شرکت) |
| |
| معلومات: |
| کلاس: {class_} |
| مضمون: {subject} |
| موضوع: {topic} |
| طلباء کی تعداد: {students} |
| دورانیہ: {duration} منٹ |
| تاریخ: {date} |
| استاد: {teacher} |
| |
| سب کچھ خالص اردو میں لکھیں۔ انگریزی الفاظ اردو رسم الخط میں لکھے جائیں۔ |
| ناستعلیق انداز اپنائیں۔ |
| """ |
|
|
| completion_ur = client.chat.completions.create( |
| model="openai/gpt-oss-120b", |
| messages=[ |
| {"role": "system", "content": "آپ ایک ماہر پاکستانی نصاب کے استاد ہیں۔"}, |
| {"role": "user", "content": prompt_ur}, |
| ], |
| ) |
|
|
| urdu_plan = completion_ur.choices[0].message.content.strip() |
|
|
| |
| md_file = f"Backward_Design_Lesson_{teacher}_UR.md" |
| with open(md_file, "w", encoding="utf-8") as f: |
| f.write("# سبق کا منصوبہ (بیکورڈ ڈیزائن – پاکستانی نصاب)\n\n") |
| f.write(f"**کلاس:** {class_}\n\n") |
| f.write(f"**مضمون:** {subject}\n\n") |
| f.write(f"**موضوع:** {topic}\n\n") |
| f.write(f"**طلباء کی تعداد:** {students}\n\n") |
| f.write(f"**دورانیہ:** {duration} منٹ\n\n") |
| f.write(f"**تاریخ:** {date}\n\n") |
| f.write(f"**استاد:** {teacher}\n\n") |
| f.write("\n---\n\n") |
| f.write(urdu_plan) |
| f.write("\n\n---\n\n**تیار کنندہ:** نجف علی شرقی") |
|
|
| |
| return english_plan, urdu_plan, docx_file, md_file |
|
|
|
|
| |
| with gr.Blocks(title="Backward Design Lesson Plan Generator (Pakistan Curriculum)") as app: |
| gr.Markdown( |
| """ |
| # 📘 Backward Design Lesson Plan Generator |
| **Generate bilingual lesson plans aligned with Pakistan Curriculum (Grades 1–12)** |
| Developed by **Najaf Ali Sharqi** |
| """ |
| ) |
|
|
| with gr.Row(): |
| class_ = gr.Dropdown( |
| [f"Grade {i}" for i in range(1, 13)], |
| label="Class / جماعت" |
| ) |
| subject = gr.Dropdown( |
| [ |
| "Urdu", "English", "Arabic", "Science", "Mathematics", "Biology", |
| "Chemistry", "Physics", "Zoology", "Botany", "Civics", "Islamiat", |
| "Pakistan Studies", "Computer Science" |
| ], |
| label="Subject / مضمون", |
| ) |
|
|
| with gr.Row(): |
| topic = gr.Textbox(label="Topic / موضوع") |
| teacher = gr.Textbox(label="Teacher Name / استاد کا نام") |
|
|
| with gr.Row(): |
| date = gr.Textbox(label="Date (YYYY-MM-DD) / تاریخ") |
| students = gr.Slider(1, 200, step=1, label="Number of Students / طلباء کی تعداد") |
| duration = gr.Slider(30, 60, step=5, label="Time Duration (minutes) / دورانیہ") |
|
|
| generate_btn = gr.Button("✨ Generate Lesson Plans") |
| theme_toggle = gr.Radio(["Light 🌞", "Dark 🌙"], label="Theme") |
|
|
| english_output = gr.Textbox(label="English Lesson Plan", lines=15) |
| urdu_output = gr.Textbox(label="اردو سبق کا منصوبہ", lines=15, rtl=True) |
|
|
| english_file = gr.File(label="📘 Download English Plan (Word)") |
| urdu_file = gr.File(label="📗 اردو منصوبہ (Markdown)") |
|
|
| generate_btn.click( |
| generate_backward_plan, |
| inputs=[class_, subject, topic, students, duration, date, teacher], |
| outputs=[english_output, urdu_output, english_file, urdu_file], |
| ) |
|
|
| app.launch() |
|
|