Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,18 @@ from google import genai
|
|
| 3 |
from docx import Document
|
| 4 |
from docx.shared import Pt, RGBColor, Inches
|
| 5 |
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
|
|
|
|
|
|
| 6 |
from datetime import datetime
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
-
# Initialize Gemini client
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Comprehensive data dictionaries
|
| 13 |
SUBJECTS_BY_GRADE = {
|
|
@@ -27,31 +34,133 @@ TEACHING_METHODS = [
|
|
| 27 |
"Lecture Method", "Discussion Method", "Demonstration Method",
|
| 28 |
"Activity-Based Learning", "Inquiry-Based Learning", "Group Work",
|
| 29 |
"Project-Based Learning", "Problem-Based Learning", "Hands-on Activities",
|
| 30 |
-
"Visual Learning", "Interactive Learning", "Storytelling"
|
|
|
|
| 31 |
]
|
| 32 |
|
| 33 |
ASSESSMENT_TYPES = [
|
| 34 |
"Formative Assessment", "Summative Assessment", "Oral Questions",
|
| 35 |
"Written Test", "Practical Work", "Class Participation",
|
| 36 |
-
"Quiz", "Worksheet", "Group Presentation", "Individual Assignment"
|
|
|
|
| 37 |
]
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
def update_subjects(grade_range):
|
| 40 |
"""Update subject dropdown based on grade selection"""
|
|
|
|
|
|
|
| 41 |
return gr.Dropdown(choices=SUBJECTS_BY_GRADE.get(grade_range, []), value=None)
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
def generate_lesson_plan(language, grade_range, grade_specific, subject, topic,
|
| 44 |
school_name, teacher_name, district, date_input,
|
| 45 |
students, duration, teaching_method, assessment_type,
|
| 46 |
include_resources, include_differentiation):
|
| 47 |
|
| 48 |
# Validate inputs
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Format date
|
| 53 |
if date_input:
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
else:
|
| 56 |
formatted_date = datetime.now().strftime("%Y-%m-%d")
|
| 57 |
|
|
@@ -61,6 +170,373 @@ def generate_lesson_plan(language, grade_range, grade_specific, subject, topic,
|
|
| 61 |
else:
|
| 62 |
full_grade = grade_range.split('-')[0] # Default to first grade in range
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
# Build enhanced prompt
|
| 65 |
prompt = f"""
|
| 66 |
You are an expert Pakistani educator and curriculum specialist with deep knowledge of the National Curriculum Framework and modern pedagogical approaches.
|
|
@@ -310,136 +786,254 @@ Generate a complete, ready-to-use lesson plan that meets professional teaching s
|
|
| 310 |
return None, f"❌ Error generating lesson plan: {str(e)}"
|
| 311 |
|
| 312 |
# Create Professional Gradio Interface
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
-
# Header
|
| 316 |
-
gr.
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
|
|
|
| 322 |
with gr.Row():
|
| 323 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
-
|
|
|
|
| 326 |
|
| 327 |
with gr.Row():
|
| 328 |
language = gr.Dropdown(
|
| 329 |
choices=["English", "Urdu"],
|
| 330 |
label="📝 Language",
|
| 331 |
value="English",
|
| 332 |
-
info="Select lesson plan language"
|
|
|
|
| 333 |
)
|
| 334 |
grade_range = gr.Dropdown(
|
| 335 |
choices=["Grade 1-5", "Grade 6-8", "Grade 9-10", "Grade 11-12"],
|
| 336 |
label="🎓 Grade Range",
|
| 337 |
-
info="Select grade level range"
|
|
|
|
| 338 |
)
|
| 339 |
grade_specific = gr.Dropdown(
|
| 340 |
choices=[f"Grade {i}" for i in range(1, 13)],
|
| 341 |
-
label="📊 Specific Grade",
|
| 342 |
-
info="
|
|
|
|
| 343 |
)
|
| 344 |
|
| 345 |
with gr.Row():
|
| 346 |
subject = gr.Dropdown(
|
| 347 |
choices=[],
|
| 348 |
label="📖 Subject",
|
| 349 |
-
info="
|
|
|
|
| 350 |
)
|
| 351 |
topic = gr.Textbox(
|
| 352 |
-
label="📌 Topic",
|
| 353 |
-
placeholder="e.g., Photosynthesis, Pythagorean Theorem,
|
| 354 |
-
info="Enter the
|
|
|
|
| 355 |
)
|
| 356 |
|
| 357 |
-
gr.
|
| 358 |
|
| 359 |
with gr.Row():
|
| 360 |
school_name = gr.Textbox(
|
| 361 |
label="🏫 School Name",
|
| 362 |
-
placeholder="e.g., Government High School",
|
| 363 |
-
info="Enter school name"
|
|
|
|
| 364 |
)
|
| 365 |
teacher_name = gr.Textbox(
|
| 366 |
label="👤 Teacher Name",
|
| 367 |
-
placeholder="e.g., Muhammad Ali",
|
| 368 |
-
info="Enter teacher's full name"
|
|
|
|
| 369 |
)
|
| 370 |
district = gr.Dropdown(
|
| 371 |
choices=DISTRICTS_GB,
|
| 372 |
label="📍 District",
|
| 373 |
value="Gilgit",
|
| 374 |
-
info="Select district in
|
|
|
|
| 375 |
)
|
| 376 |
|
| 377 |
-
gr.
|
| 378 |
|
| 379 |
with gr.Row():
|
| 380 |
date_input = gr.Textbox(
|
| 381 |
-
label="📅 Date",
|
| 382 |
value=datetime.now().strftime("%Y-%m-%d"),
|
| 383 |
placeholder="YYYY-MM-DD",
|
| 384 |
-
info="
|
| 385 |
)
|
| 386 |
students = gr.Number(
|
| 387 |
label="👥 Number of Students",
|
| 388 |
-
value=
|
| 389 |
minimum=1,
|
| 390 |
maximum=100,
|
| 391 |
-
|
|
|
|
| 392 |
)
|
| 393 |
duration = gr.Dropdown(
|
| 394 |
-
choices=[35, 40, 45, 50, 60, 70, 80],
|
| 395 |
label="⏱️ Duration (minutes)",
|
| 396 |
value=40,
|
| 397 |
-
info="
|
|
|
|
| 398 |
)
|
| 399 |
|
| 400 |
-
gr.
|
| 401 |
|
| 402 |
with gr.Row():
|
| 403 |
teaching_method = gr.Dropdown(
|
| 404 |
choices=TEACHING_METHODS,
|
| 405 |
label="🎓 Primary Teaching Method",
|
| 406 |
value="Lecture Method",
|
| 407 |
-
info="
|
|
|
|
| 408 |
)
|
| 409 |
assessment_type = gr.Dropdown(
|
| 410 |
choices=ASSESSMENT_TYPES,
|
| 411 |
-
label="📊 Assessment
|
| 412 |
value="Formative Assessment",
|
| 413 |
-
info="How will you
|
|
|
|
| 414 |
)
|
| 415 |
|
| 416 |
-
gr.
|
| 417 |
|
| 418 |
with gr.Row():
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
|
|
|
|
|
|
| 429 |
|
| 430 |
-
|
| 431 |
-
generate_btn = gr.Button("🚀 Generate Lesson Plan", variant="primary", size="lg")
|
| 432 |
|
| 433 |
-
#
|
| 434 |
-
gr.
|
| 435 |
-
|
| 436 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
|
| 438 |
# Event handlers
|
| 439 |
grade_range.change(
|
| 440 |
fn=update_subjects,
|
| 441 |
-
inputs=grade_range,
|
| 442 |
-
outputs=subject
|
| 443 |
)
|
| 444 |
|
| 445 |
generate_btn.click(
|
|
@@ -453,24 +1047,88 @@ with gr.Blocks(theme=gr.themes.Soft(), title="SMART Lesson Plan Generator") as d
|
|
| 453 |
outputs=[output_file, status_output]
|
| 454 |
)
|
| 455 |
|
| 456 |
-
# Footer
|
| 457 |
-
gr.Markdown(""
|
| 458 |
-
---
|
| 459 |
-
### 💡 Tips for Best Results:
|
| 460 |
-
- Fill in all required fields accurately
|
| 461 |
-
- Choose appropriate teaching methods for your topic
|
| 462 |
-
- Review and customize the generated plan as needed
|
| 463 |
-
- Save multiple versions for different classes
|
| 464 |
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
|
| 469 |
-
# Launch
|
| 470 |
if __name__ == "__main__":
|
| 471 |
demo.launch(
|
| 472 |
server_name="0.0.0.0",
|
| 473 |
server_port=7860,
|
| 474 |
share=False,
|
| 475 |
-
show_error=True
|
|
|
|
|
|
|
| 476 |
)
|
|
|
|
| 3 |
from docx import Document
|
| 4 |
from docx.shared import Pt, RGBColor, Inches
|
| 5 |
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
| 6 |
+
from docx.oxml.ns import qn
|
| 7 |
+
from docx.oxml import OxmlElement
|
| 8 |
from datetime import datetime
|
| 9 |
import os
|
| 10 |
+
import re
|
| 11 |
|
| 12 |
+
# Initialize Gemini client with error handling
|
| 13 |
+
try:
|
| 14 |
+
client = genai.Client()
|
| 15 |
+
except Exception as e:
|
| 16 |
+
print(f"Warning: Gemini client initialization failed: {e}")
|
| 17 |
+
client = None
|
| 18 |
|
| 19 |
# Comprehensive data dictionaries
|
| 20 |
SUBJECTS_BY_GRADE = {
|
|
|
|
| 34 |
"Lecture Method", "Discussion Method", "Demonstration Method",
|
| 35 |
"Activity-Based Learning", "Inquiry-Based Learning", "Group Work",
|
| 36 |
"Project-Based Learning", "Problem-Based Learning", "Hands-on Activities",
|
| 37 |
+
"Visual Learning", "Interactive Learning", "Storytelling",
|
| 38 |
+
"Cooperative Learning", "Flipped Classroom", "Think-Pair-Share"
|
| 39 |
]
|
| 40 |
|
| 41 |
ASSESSMENT_TYPES = [
|
| 42 |
"Formative Assessment", "Summative Assessment", "Oral Questions",
|
| 43 |
"Written Test", "Practical Work", "Class Participation",
|
| 44 |
+
"Quiz", "Worksheet", "Group Presentation", "Individual Assignment",
|
| 45 |
+
"Peer Assessment", "Self Assessment", "Portfolio Assessment"
|
| 46 |
]
|
| 47 |
|
| 48 |
+
BLOOM_LEVELS = {
|
| 49 |
+
"Knowledge": ["Remember", "Recall", "Define", "List", "Identify", "Label"],
|
| 50 |
+
"Understanding": ["Explain", "Describe", "Summarize", "Interpret", "Compare", "Classify"],
|
| 51 |
+
"Application": ["Apply", "Demonstrate", "Solve", "Calculate", "Use", "Implement"],
|
| 52 |
+
"Analysis": ["Analyze", "Differentiate", "Organize", "Examine", "Investigate"],
|
| 53 |
+
"Evaluation": ["Evaluate", "Assess", "Critique", "Justify", "Recommend"],
|
| 54 |
+
"Creation": ["Create", "Design", "Develop", "Compose", "Construct"]
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
# Urdu translations for key terms
|
| 58 |
+
URDU_TRANSLATIONS = {
|
| 59 |
+
"Grade": "درجہ",
|
| 60 |
+
"Subject": "مضمون",
|
| 61 |
+
"Topic": "موضوع",
|
| 62 |
+
"Teacher": "استاد",
|
| 63 |
+
"School": "اسکول",
|
| 64 |
+
"District": "ضلع",
|
| 65 |
+
"Date": "تاریخ",
|
| 66 |
+
"Students": "طلبہ کی تعداد",
|
| 67 |
+
"Duration": "دورانیہ",
|
| 68 |
+
"minutes": "منٹ",
|
| 69 |
+
"Teaching Method": "تدریسی طریقہ",
|
| 70 |
+
"Assessment": "تشخیص"
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
def update_subjects(grade_range):
|
| 74 |
"""Update subject dropdown based on grade selection"""
|
| 75 |
+
if not grade_range:
|
| 76 |
+
return gr.Dropdown(choices=[], value=None)
|
| 77 |
return gr.Dropdown(choices=SUBJECTS_BY_GRADE.get(grade_range, []), value=None)
|
| 78 |
|
| 79 |
+
def validate_inputs(language, grade_range, subject, topic, teacher_name, school_name):
|
| 80 |
+
"""Validate all required inputs"""
|
| 81 |
+
errors = []
|
| 82 |
+
|
| 83 |
+
if not language:
|
| 84 |
+
errors.append("Language is required")
|
| 85 |
+
if not grade_range:
|
| 86 |
+
errors.append("Grade range is required")
|
| 87 |
+
if not subject:
|
| 88 |
+
errors.append("Subject is required")
|
| 89 |
+
if not topic or len(topic.strip()) < 3:
|
| 90 |
+
errors.append("Topic must be at least 3 characters")
|
| 91 |
+
if not teacher_name or len(teacher_name.strip()) < 2:
|
| 92 |
+
errors.append("Teacher name is required")
|
| 93 |
+
if not school_name or len(school_name.strip()) < 3:
|
| 94 |
+
errors.append("School name is required")
|
| 95 |
+
|
| 96 |
+
return errors
|
| 97 |
+
|
| 98 |
+
def add_table_border(table):
|
| 99 |
+
"""Add borders to Word table"""
|
| 100 |
+
tbl = table._tbl
|
| 101 |
+
tblPr = tbl.tblPr
|
| 102 |
+
if tblPr is None:
|
| 103 |
+
tblPr = OxmlElement('w:tblPr')
|
| 104 |
+
tbl.insert(0, tblPr)
|
| 105 |
+
|
| 106 |
+
tblBorders = OxmlElement('w:tblBorders')
|
| 107 |
+
for border_name in ['top', 'left', 'bottom', 'right', 'insideH', 'insideV']:
|
| 108 |
+
border = OxmlElement(f'w:{border_name}')
|
| 109 |
+
border.set(qn('w:val'), 'single')
|
| 110 |
+
border.set(qn('w:sz'), '4')
|
| 111 |
+
border.set(qn('w:space'), '0')
|
| 112 |
+
border.set(qn('w:color'), '000000')
|
| 113 |
+
tblBorders.append(border)
|
| 114 |
+
tblPr.append(tblBorders)
|
| 115 |
+
|
| 116 |
+
def format_document_header(doc, language):
|
| 117 |
+
"""Create professional document header"""
|
| 118 |
+
# Main header
|
| 119 |
+
header = doc.add_paragraph()
|
| 120 |
+
run = header.add_run("Government of Gilgit-Baltistan\n")
|
| 121 |
+
run.bold = True
|
| 122 |
+
run.font.size = Pt(16)
|
| 123 |
+
run.font.color.rgb = RGBColor(0, 100, 0)
|
| 124 |
+
|
| 125 |
+
run2 = header.add_run("School Education Department")
|
| 126 |
+
run2.bold = True
|
| 127 |
+
run2.font.size = Pt(14)
|
| 128 |
+
run2.font.color.rgb = RGBColor(0, 100, 0)
|
| 129 |
+
header.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 130 |
+
|
| 131 |
+
# Subtitle
|
| 132 |
+
subheader = doc.add_paragraph()
|
| 133 |
+
run = subheader.add_run("SMART LESSON PLAN")
|
| 134 |
+
run.bold = True
|
| 135 |
+
run.font.size = Pt(13)
|
| 136 |
+
run.underline = True
|
| 137 |
+
subheader.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 138 |
+
subheader.space_after = Pt(16)
|
| 139 |
+
|
| 140 |
+
return doc
|
| 141 |
+
|
| 142 |
def generate_lesson_plan(language, grade_range, grade_specific, subject, topic,
|
| 143 |
school_name, teacher_name, district, date_input,
|
| 144 |
students, duration, teaching_method, assessment_type,
|
| 145 |
include_resources, include_differentiation):
|
| 146 |
|
| 147 |
# Validate inputs
|
| 148 |
+
validation_errors = validate_inputs(language, grade_range, subject, topic, teacher_name, school_name)
|
| 149 |
+
if validation_errors:
|
| 150 |
+
error_msg = "⚠️ Please fix the following errors:\n" + "\n".join(f"• {e}" for e in validation_errors)
|
| 151 |
+
return None, error_msg
|
| 152 |
+
|
| 153 |
+
# Check if client is initialized
|
| 154 |
+
if client is None:
|
| 155 |
+
return None, "❌ Error: Gemini API client not initialized. Please check your API key."
|
| 156 |
|
| 157 |
# Format date
|
| 158 |
if date_input:
|
| 159 |
+
try:
|
| 160 |
+
datetime.strptime(date_input, "%Y-%m-%d")
|
| 161 |
+
formatted_date = date_input
|
| 162 |
+
except ValueError:
|
| 163 |
+
formatted_date = datetime.now().strftime("%Y-%m-%d")
|
| 164 |
else:
|
| 165 |
formatted_date = datetime.now().strftime("%Y-%m-%d")
|
| 166 |
|
|
|
|
| 170 |
else:
|
| 171 |
full_grade = grade_range.split('-')[0] # Default to first grade in range
|
| 172 |
|
| 173 |
+
# Calculate time allocations
|
| 174 |
+
intro_time = int(duration * 0.15)
|
| 175 |
+
main_time = int(duration * 0.60)
|
| 176 |
+
conclusion_time = int(duration * 0.15)
|
| 177 |
+
assessment_time = duration - (intro_time + main_time + conclusion_time)
|
| 178 |
+
|
| 179 |
+
# Build enhanced prompt
|
| 180 |
+
prompt = f"""
|
| 181 |
+
You are an expert Pakistani educator and curriculum specialist with deep knowledge of the National Curriculum Framework, modern pedagogical approaches, and classroom management in Gilgit-Baltistan context.
|
| 182 |
+
|
| 183 |
+
Create a COMPREHENSIVE, PRACTICAL, and STUDENT-CENTERED SMART LESSON PLAN in {language} language.
|
| 184 |
+
|
| 185 |
+
**LESSON DETAILS:**
|
| 186 |
+
- Grade: {full_grade}
|
| 187 |
+
- Subject: {subject}
|
| 188 |
+
- Topic: {topic}
|
| 189 |
+
- School: {school_name}
|
| 190 |
+
- Teacher: {teacher_name}
|
| 191 |
+
- District: {district}, Gilgit-Baltistan
|
| 192 |
+
- Date: {formatted_date}
|
| 193 |
+
- Number of Students: {students}
|
| 194 |
+
- Duration: {duration} minutes
|
| 195 |
+
- Primary Teaching Method: {teaching_method}
|
| 196 |
+
- Assessment Type: {assessment_type}
|
| 197 |
+
|
| 198 |
+
**CRITICAL INSTRUCTIONS:**
|
| 199 |
+
|
| 200 |
+
1. **DO NOT repeat the information table in text format** - it will be added automatically.
|
| 201 |
+
|
| 202 |
+
2. **SMART STUDENT LEARNING OUTCOMES (SLOs):**
|
| 203 |
+
Write EXACTLY THREE SLOs following Bloom's Taxonomy. Each must be:
|
| 204 |
+
- **SLO 1 (Knowledge Level):** Start with verbs like: Define, List, Identify, Recall, State, Name
|
| 205 |
+
- **SLO 2 (Understanding Level):** Start with verbs like: Explain, Describe, Summarize, Interpret, Compare, Discuss
|
| 206 |
+
- **SLO 3 (Application Level):** Start with verbs like: Apply, Demonstrate, Solve, Calculate, Use, Illustrate
|
| 207 |
+
|
| 208 |
+
Format each SLO as: "By the end of this lesson, students will be able to [action verb] [specific content] [condition/criteria]."
|
| 209 |
+
|
| 210 |
+
Make SLOs:
|
| 211 |
+
- Specific and measurable
|
| 212 |
+
- Achievable within {duration} minutes
|
| 213 |
+
- Aligned with National Curriculum standards
|
| 214 |
+
- Observable and assessable
|
| 215 |
+
|
| 216 |
+
3. **CONTENT KNOWLEDGE:**
|
| 217 |
+
Provide comprehensive subject content organized under clear subheadings:
|
| 218 |
+
- **Key Concepts:** Main ideas students must understand
|
| 219 |
+
- **Definitions:** Important terms with simple explanations
|
| 220 |
+
- **Facts & Information:** Essential knowledge for this topic
|
| 221 |
+
- **Prior Knowledge Required:** What students should already know
|
| 222 |
+
- **Common Misconceptions:** Typical errors students make and how to address them
|
| 223 |
+
- **Real-World Connections:** How this topic relates to daily life in Gilgit-Baltistan
|
| 224 |
+
|
| 225 |
+
4. **DETAILED LESSON PROCEDURE:**
|
| 226 |
+
|
| 227 |
+
**A) INTRODUCTION/WARM-UP ({intro_time} minutes):**
|
| 228 |
+
- Engaging hook or attention-grabber relevant to local context
|
| 229 |
+
- Activity to activate prior knowledge
|
| 230 |
+
- Clear statement of learning objectives in student-friendly language
|
| 231 |
+
- Pre-assessment question to gauge understanding
|
| 232 |
+
|
| 233 |
+
**B) MAIN TEACHING & LEARNING ACTIVITIES ({main_time} minutes):**
|
| 234 |
+
|
| 235 |
+
*Teacher Activity:*
|
| 236 |
+
- Step-by-step explanation using {teaching_method}
|
| 237 |
+
- Clear examples with local/cultural relevance
|
| 238 |
+
- Visual aids and demonstrations to use
|
| 239 |
+
- Key questions to ask students
|
| 240 |
+
- Checking for understanding strategies
|
| 241 |
+
|
| 242 |
+
*Student Activity:*
|
| 243 |
+
- Guided practice tasks (teacher support)
|
| 244 |
+
- Independent practice activities
|
| 245 |
+
- Group work or pair activities (if applicable)
|
| 246 |
+
- Hands-on activities or experiments
|
| 247 |
+
- Problem-solving tasks
|
| 248 |
+
|
| 249 |
+
**C) ASSESSMENT & EVALUATION ({assessment_time} minutes):**
|
| 250 |
+
- {assessment_type} activity description
|
| 251 |
+
- Specific questions to assess each SLO
|
| 252 |
+
- Success criteria for student performance
|
| 253 |
+
- How to provide immediate feedback
|
| 254 |
+
|
| 255 |
+
**D) CONCLUSION/CLOSURE ({conclusion_time} minutes):**
|
| 256 |
+
- Summary of key learning points
|
| 257 |
+
- Student reflection questions
|
| 258 |
+
- Connection to next lesson
|
| 259 |
+
- Preview of home assignment
|
| 260 |
+
|
| 261 |
+
5. **TEACHING RESOURCES & MATERIALS:**
|
| 262 |
+
{"List all materials needed: textbooks, worksheets, charts, models, technology, stationery, etc. Be specific and practical for local school context." if include_resources else ""}
|
| 263 |
+
|
| 264 |
+
6. **DIFFERENTIATION STRATEGIES:**
|
| 265 |
+
{"Provide specific strategies for:\n - **Advanced Learners:** Extension activities and challenging tasks\n - **Struggling Students:** Scaffolding techniques and simplified tasks\n - **Visual Learners:** Charts, diagrams, videos\n - **Kinesthetic Learners:** Hands-on activities and movement\n - **English Language Learners:** Vocabulary support and bilingual strategies" if include_differentiation else ""}
|
| 266 |
+
|
| 267 |
+
7. **HOME ASSIGNMENT:**
|
| 268 |
+
Create a meaningful assignment that:
|
| 269 |
+
- Directly reinforces the three SLOs
|
| 270 |
+
- Is appropriate for {full_grade} level
|
| 271 |
+
- Can be completed independently in 20-30 minutes
|
| 272 |
+
- Has clear, step-by-step instructions
|
| 273 |
+
- Includes success criteria or rubric
|
| 274 |
+
- Encourages family involvement where appropriate
|
| 275 |
+
|
| 276 |
+
8. **TEACHER'S REFLECTION NOTES:**
|
| 277 |
+
Add blank section with prompts:
|
| 278 |
+
- What worked well in this lesson?
|
| 279 |
+
- What challenges did students face?
|
| 280 |
+
- Which students need additional support?
|
| 281 |
+
- What would I change next time?
|
| 282 |
+
- How well were SLOs achieved?
|
| 283 |
+
|
| 284 |
+
**FORMATTING & LANGUAGE GUIDELINES:**
|
| 285 |
+
|
| 286 |
+
{"For English version:" if language == "English" else "اردو کے لیے:"}
|
| 287 |
+
- Use clear, professional language appropriate for educational documentation
|
| 288 |
+
- Write in complete sentences and paragraphs
|
| 289 |
+
- Use bullet points ONLY for lists of items or steps
|
| 290 |
+
- Use proper headings hierarchy (Main headings bold and larger)
|
| 291 |
+
- Maintain logical flow between sections
|
| 292 |
+
- Be specific and practical, not vague or generic
|
| 293 |
+
- Include culturally relevant examples from Gilgit-Baltistan context
|
| 294 |
+
- {"Proper English grammar and spelling" if language == "English" else "صحیح اردو رسم الخط اور املا، دائیں سے بائیں سمت"}
|
| 295 |
+
|
| 296 |
+
**OUTPUT FORMAT:**
|
| 297 |
+
Generate ONLY the lesson plan content starting from "SMART STUDENT LEARNING OUTCOMES (SLOs)".
|
| 298 |
+
Do NOT include any table or repeat the lesson details (Grade, Subject, etc.) as that will be added automatically.
|
| 299 |
+
Do NOT add any developer credits, signatures, or metadata at the end.
|
| 300 |
+
|
| 301 |
+
Now generate the complete, ready-to-implement lesson plan:
|
| 302 |
+
"""
|
| 303 |
+
|
| 304 |
+
try:
|
| 305 |
+
# Generate content using Gemini
|
| 306 |
+
response = client.models.generate_content(
|
| 307 |
+
model="gemini-2.0-flash-exp",
|
| 308 |
+
contents=prompt
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
lesson_text = response.text.strip()
|
| 312 |
+
|
| 313 |
+
# Remove any accidental inclusion of lesson details from AI response
|
| 314 |
+
lesson_text = re.sub(r'^.*?(SMART|SLO)', r'\1', lesson_text, flags=re.DOTALL | re.IGNORECASE)
|
| 315 |
+
|
| 316 |
+
# Create Word document
|
| 317 |
+
doc = Document()
|
| 318 |
+
|
| 319 |
+
# Set margins
|
| 320 |
+
sections = doc.sections
|
| 321 |
+
for section in sections:
|
| 322 |
+
section.top_margin = Inches(0.75)
|
| 323 |
+
section.bottom_margin = Inches(0.75)
|
| 324 |
+
section.left_margin = Inches(0.75)
|
| 325 |
+
section.right_margin = Inches(0.75)
|
| 326 |
+
|
| 327 |
+
if language == "English":
|
| 328 |
+
# Professional header
|
| 329 |
+
doc = format_document_header(doc, language)
|
| 330 |
+
|
| 331 |
+
# Information table with enhanced styling
|
| 332 |
+
table = doc.add_table(rows=6, cols=4)
|
| 333 |
+
add_table_border(table)
|
| 334 |
+
|
| 335 |
+
# Header row styling
|
| 336 |
+
def style_cell(cell, text, bold=False, bg_color=None):
|
| 337 |
+
cell.text = text
|
| 338 |
+
if bold:
|
| 339 |
+
for paragraph in cell.paragraphs:
|
| 340 |
+
for run in paragraph.runs:
|
| 341 |
+
run.bold = True
|
| 342 |
+
run.font.size = Pt(10)
|
| 343 |
+
if bg_color:
|
| 344 |
+
shading_elm = OxmlElement('w:shd')
|
| 345 |
+
shading_elm.set(qn('w:fill'), bg_color)
|
| 346 |
+
cell._element.get_or_add_tcPr().append(shading_elm)
|
| 347 |
+
|
| 348 |
+
# Fill table with data
|
| 349 |
+
cells = table.rows[0].cells
|
| 350 |
+
style_cell(cells[0], "Grade", bold=True, bg_color="E7E6E6")
|
| 351 |
+
style_cell(cells[1], full_grade)
|
| 352 |
+
style_cell(cells[2], "Subject", bold=True, bg_color="E7E6E6")
|
| 353 |
+
style_cell(cells[3], subject)
|
| 354 |
+
|
| 355 |
+
cells = table.rows[1].cells
|
| 356 |
+
style_cell(cells[0], "Topic", bold=True, bg_color="E7E6E6")
|
| 357 |
+
style_cell(cells[1], topic)
|
| 358 |
+
style_cell(cells[2], "Duration", bold=True, bg_color="E7E6E6")
|
| 359 |
+
style_cell(cells[3], f"{duration} minutes")
|
| 360 |
+
|
| 361 |
+
cells = table.rows[2].cells
|
| 362 |
+
style_cell(cells[0], "Teacher", bold=True, bg_color="E7E6E6")
|
| 363 |
+
style_cell(cells[1], teacher_name)
|
| 364 |
+
style_cell(cells[2], "Date", bold=True, bg_color="E7E6E6")
|
| 365 |
+
style_cell(cells[3], formatted_date)
|
| 366 |
+
|
| 367 |
+
cells = table.rows[3].cells
|
| 368 |
+
style_cell(cells[0], "School", bold=True, bg_color="E7E6E6")
|
| 369 |
+
style_cell(cells[1], school_name)
|
| 370 |
+
style_cell(cells[2], "District", bold=True, bg_color="E7E6E6")
|
| 371 |
+
style_cell(cells[3], f"{district}, GB")
|
| 372 |
+
|
| 373 |
+
cells = table.rows[4].cells
|
| 374 |
+
style_cell(cells[0], "No. of Students", bold=True, bg_color="E7E6E6")
|
| 375 |
+
style_cell(cells[1], str(int(students)))
|
| 376 |
+
style_cell(cells[2], "Teaching Method", bold=True, bg_color="E7E6E6")
|
| 377 |
+
style_cell(cells[3], teaching_method)
|
| 378 |
+
|
| 379 |
+
cells = table.rows[5].cells
|
| 380 |
+
style_cell(cells[0], "Assessment Type", bold=True, bg_color="E7E6E6")
|
| 381 |
+
merged_cell = cells[1].merge(cells[3])
|
| 382 |
+
style_cell(merged_cell, assessment_type)
|
| 383 |
+
|
| 384 |
+
doc.add_paragraph() # Spacing
|
| 385 |
+
|
| 386 |
+
# Process lesson content with enhanced formatting
|
| 387 |
+
lines = lesson_text.split("\n")
|
| 388 |
+
current_section = ""
|
| 389 |
+
|
| 390 |
+
for line in lines:
|
| 391 |
+
line_stripped = line.strip()
|
| 392 |
+
if not line_stripped:
|
| 393 |
+
continue
|
| 394 |
+
|
| 395 |
+
# Detect main headings
|
| 396 |
+
is_main_heading = any(keyword in line_stripped.upper() for keyword in
|
| 397 |
+
["SMART STUDENT LEARNING OUTCOMES", "CONTENT KNOWLEDGE",
|
| 398 |
+
"LESSON PROCEDURE", "TEACHING RESOURCES",
|
| 399 |
+
"DIFFERENTIATION STRATEGIES", "HOME ASSIGNMENT",
|
| 400 |
+
"TEACHER'S REFLECTION", "REFLECTION NOTES"])
|
| 401 |
+
|
| 402 |
+
# Detect sub-headings
|
| 403 |
+
is_sub_heading = any(keyword in line_stripped.upper() for keyword in
|
| 404 |
+
["INTRODUCTION", "WARM-UP", "MAIN TEACHING",
|
| 405 |
+
"ASSESSMENT", "EVALUATION", "CONCLUSION", "CLOSURE",
|
| 406 |
+
"KEY CONCEPTS", "DEFINITIONS", "PRIOR KNOWLEDGE",
|
| 407 |
+
"TEACHER ACTIVITY", "STUDENT ACTIVITY"])
|
| 408 |
+
|
| 409 |
+
# Detect SLOs
|
| 410 |
+
is_slo = line_stripped.upper().startswith("SLO") or re.match(r'^(SLO\s*[1-3]|BY THE END)', line_stripped.upper())
|
| 411 |
+
|
| 412 |
+
para = doc.add_paragraph(line_stripped)
|
| 413 |
+
para.paragraph_format.space_after = Pt(6)
|
| 414 |
+
para.paragraph_format.line_spacing = 1.15
|
| 415 |
+
|
| 416 |
+
if is_main_heading:
|
| 417 |
+
para.runs[0].bold = True
|
| 418 |
+
para.runs[0].font.size = Pt(12)
|
| 419 |
+
para.runs[0].font.color.rgb = RGBColor(0, 70, 130)
|
| 420 |
+
para.paragraph_format.space_before = Pt(12)
|
| 421 |
+
para.paragraph_format.space_after = Pt(8)
|
| 422 |
+
elif is_sub_heading:
|
| 423 |
+
para.runs[0].bold = True
|
| 424 |
+
para.runs[0].font.size = Pt(11)
|
| 425 |
+
para.runs[0].font.color.rgb = RGBColor(0, 100, 180)
|
| 426 |
+
para.paragraph_format.space_before = Pt(8)
|
| 427 |
+
elif is_slo:
|
| 428 |
+
para.runs[0].bold = True
|
| 429 |
+
para.runs[0].font.color.rgb = RGBColor(139, 0, 0)
|
| 430 |
+
para.paragraph_format.left_indent = Inches(0.25)
|
| 431 |
+
|
| 432 |
+
# Professional footer
|
| 433 |
+
doc.add_paragraph()
|
| 434 |
+
separator = doc.add_paragraph("_" * 80)
|
| 435 |
+
separator.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 436 |
+
|
| 437 |
+
footer = doc.add_paragraph()
|
| 438 |
+
run = footer.add_run(f"Generated: {datetime.now().strftime('%d %B %Y at %H:%M')} | ")
|
| 439 |
+
run.font.size = Pt(8)
|
| 440 |
+
run.font.italic = True
|
| 441 |
+
run.font.color.rgb = RGBColor(100, 100, 100)
|
| 442 |
+
|
| 443 |
+
run2 = footer.add_run("SMART Lesson Plan Generator v2.0")
|
| 444 |
+
run2.font.size = Pt(8)
|
| 445 |
+
run2.font.italic = True
|
| 446 |
+
run2.font.color.rgb = RGBColor(100, 100, 100)
|
| 447 |
+
footer.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 448 |
+
|
| 449 |
+
# Save file with descriptive name
|
| 450 |
+
safe_topic = re.sub(r'[^\w\s-]', '', topic).strip()[:30]
|
| 451 |
+
file_path = f"/tmp/LP_{subject}_{safe_topic}_{full_grade}_{formatted_date}.docx"
|
| 452 |
+
doc.save(file_path)
|
| 453 |
+
|
| 454 |
+
status_msg = f"""✅ **Lesson Plan Generated Successfully!**
|
| 455 |
+
|
| 456 |
+
📄 **File Details:**
|
| 457 |
+
- Subject: {subject}
|
| 458 |
+
- Grade: {full_grade}
|
| 459 |
+
- Topic: {topic}
|
| 460 |
+
- Duration: {duration} minutes
|
| 461 |
+
- Date: {formatted_date}
|
| 462 |
+
|
| 463 |
+
💾 **File Name:** {os.path.basename(file_path)}
|
| 464 |
+
|
| 465 |
+
✨ **Next Steps:**
|
| 466 |
+
1. Download the file using the button below
|
| 467 |
+
2. Review and customize as needed
|
| 468 |
+
3. Print or share with colleagues
|
| 469 |
+
4. Use in your classroom!
|
| 470 |
+
|
| 471 |
+
🎯 **Quality Assurance:**
|
| 472 |
+
- ✓ SMART SLOs aligned with Bloom's Taxonomy
|
| 473 |
+
- ✓ Detailed lesson procedure with timings
|
| 474 |
+
- ✓ Assessment strategies included
|
| 475 |
+
- ✓ {('Teaching resources listed', 'Differentiation strategies added')[include_differentiation]}
|
| 476 |
+
- ✓ Home assignment provided"""
|
| 477 |
+
|
| 478 |
+
else: # Urdu version
|
| 479 |
+
# Create Urdu document
|
| 480 |
+
doc = Document()
|
| 481 |
+
|
| 482 |
+
# Urdu header
|
| 483 |
+
header = doc.add_paragraph()
|
| 484 |
+
run = header.add_run("حکومت گلگت بلتستان\nمحکمہ تعلیم")
|
| 485 |
+
run.bold = True
|
| 486 |
+
run.font.size = Pt(16)
|
| 487 |
+
run.font.color.rgb = RGBColor(0, 100, 0)
|
| 488 |
+
header.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 489 |
+
header.paragraph_format.right_to_left = True
|
| 490 |
+
|
| 491 |
+
subheader = doc.add_paragraph()
|
| 492 |
+
run = subheader.add_run("اسمارٹ سبق کا منصوبہ")
|
| 493 |
+
run.bold = True
|
| 494 |
+
run.font.size = Pt(14)
|
| 495 |
+
run.underline = True
|
| 496 |
+
subheader.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 497 |
+
subheader.paragraph_format.right_to_left = True
|
| 498 |
+
subheader.space_after = Pt(16)
|
| 499 |
+
|
| 500 |
+
# Add Urdu lesson content
|
| 501 |
+
for line in lesson_text.split("\n"):
|
| 502 |
+
if line.strip():
|
| 503 |
+
para = doc.add_paragraph(line.strip())
|
| 504 |
+
para.alignment = WD_ALIGN_PARAGRAPH.RIGHT
|
| 505 |
+
para.paragraph_format.right_to_left = True
|
| 506 |
+
para.paragraph_format.space_after = Pt(6)
|
| 507 |
+
para.paragraph_format.line_spacing = 1.5
|
| 508 |
+
|
| 509 |
+
safe_topic = re.sub(r'[^\w\s-]', '', topic).strip()[:30]
|
| 510 |
+
file_path = f"/tmp/LP_Urdu_{safe_topic}_{formatted_date}.docx"
|
| 511 |
+
doc.save(file_path)
|
| 512 |
+
|
| 513 |
+
status_msg = f"""✅ **سبق کا منصوبہ تیار ہو گیا!**
|
| 514 |
+
|
| 515 |
+
📄 **تفصیلات:**
|
| 516 |
+
- مضمون: {subject}
|
| 517 |
+
- درجہ: {full_grade}
|
| 518 |
+
- موضوع: {topic}
|
| 519 |
+
|
| 520 |
+
💾 فائل: {os.path.basename(file_path)}"""
|
| 521 |
+
|
| 522 |
+
return file_path, status_msg
|
| 523 |
+
|
| 524 |
+
except Exception as e:
|
| 525 |
+
error_details = f"""❌ **Error Generating Lesson Plan**
|
| 526 |
+
|
| 527 |
+
**Error Type:** {type(e).__name__}
|
| 528 |
+
**Details:** {str(e)}
|
| 529 |
+
|
| 530 |
+
**Troubleshooting Steps:**
|
| 531 |
+
1. Check your internet connection
|
| 532 |
+
2. Verify Gemini API key is configured
|
| 533 |
+
3. Ensure all required fields are filled
|
| 534 |
+
4. Try again with a simpler topic
|
| 535 |
+
|
| 536 |
+
**If problem persists:** Contact technical support"""
|
| 537 |
+
|
| 538 |
+
return None, error_details
|
| 539 |
+
|
| 540 |
# Build enhanced prompt
|
| 541 |
prompt = f"""
|
| 542 |
You are an expert Pakistani educator and curriculum specialist with deep knowledge of the National Curriculum Framework and modern pedagogical approaches.
|
|
|
|
| 786 |
return None, f"❌ Error generating lesson plan: {str(e)}"
|
| 787 |
|
| 788 |
# Create Professional Gradio Interface
|
| 789 |
+
custom_css = """
|
| 790 |
+
.gradio-container {
|
| 791 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
|
| 792 |
+
}
|
| 793 |
+
.main-header {
|
| 794 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 795 |
+
padding: 2rem;
|
| 796 |
+
border-radius: 10px;
|
| 797 |
+
color: white;
|
| 798 |
+
margin-bottom: 2rem;
|
| 799 |
+
}
|
| 800 |
+
.section-header {
|
| 801 |
+
background-color: #f8f9fa;
|
| 802 |
+
padding: 1rem;
|
| 803 |
+
border-left: 4px solid #667eea;
|
| 804 |
+
margin: 1.5rem 0 1rem 0;
|
| 805 |
+
border-radius: 5px;
|
| 806 |
+
}
|
| 807 |
+
.info-box {
|
| 808 |
+
background-color: #e3f2fd;
|
| 809 |
+
padding: 1rem;
|
| 810 |
+
border-radius: 5px;
|
| 811 |
+
border-left: 4px solid #2196f3;
|
| 812 |
+
margin: 1rem 0;
|
| 813 |
+
}
|
| 814 |
+
"""
|
| 815 |
+
|
| 816 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css, title="SMART Lesson Plan Generator - GB Education") as demo:
|
| 817 |
|
| 818 |
+
# Header with branding
|
| 819 |
+
with gr.Row():
|
| 820 |
+
gr.HTML("""
|
| 821 |
+
<div class="main-header">
|
| 822 |
+
<h1 style="margin:0; font-size: 2.5rem;">📚 SMART Lesson Plan Generator</h1>
|
| 823 |
+
<p style="margin: 0.5rem 0 0 0; font-size: 1.1rem; opacity: 0.9;">
|
| 824 |
+
Professional Lesson Planning Tool for Gilgit-Baltistan Schools
|
| 825 |
+
</p>
|
| 826 |
+
<p style="margin: 0.3rem 0 0 0; font-size: 0.9rem; opacity: 0.8;">
|
| 827 |
+
Powered by Google Gemini AI | Developed by Najaf Ali Sharqi
|
| 828 |
+
</p>
|
| 829 |
+
</div>
|
| 830 |
+
""")
|
| 831 |
|
| 832 |
+
# Information box
|
| 833 |
with gr.Row():
|
| 834 |
+
gr.Markdown("""
|
| 835 |
+
<div class="info-box">
|
| 836 |
+
<strong>🎯 About This Tool:</strong> Generate comprehensive, curriculum-aligned SMART lesson plans in English or Urdu.
|
| 837 |
+
All plans include SMART SLOs based on Bloom's Taxonomy, detailed procedures, assessments, and home assignments.
|
| 838 |
+
</div>
|
| 839 |
+
""")
|
| 840 |
|
| 841 |
+
# Main form sections
|
| 842 |
+
gr.HTML('<div class="section-header"><h3>📋 Basic Lesson Information</h3></div>')
|
| 843 |
|
| 844 |
with gr.Row():
|
| 845 |
language = gr.Dropdown(
|
| 846 |
choices=["English", "Urdu"],
|
| 847 |
label="📝 Language",
|
| 848 |
value="English",
|
| 849 |
+
info="Select lesson plan language",
|
| 850 |
+
interactive=True
|
| 851 |
)
|
| 852 |
grade_range = gr.Dropdown(
|
| 853 |
choices=["Grade 1-5", "Grade 6-8", "Grade 9-10", "Grade 11-12"],
|
| 854 |
label="🎓 Grade Range",
|
| 855 |
+
info="Select grade level range",
|
| 856 |
+
interactive=True
|
| 857 |
)
|
| 858 |
grade_specific = gr.Dropdown(
|
| 859 |
choices=[f"Grade {i}" for i in range(1, 13)],
|
| 860 |
+
label="📊 Specific Grade (Optional)",
|
| 861 |
+
info="Select exact grade level",
|
| 862 |
+
interactive=True
|
| 863 |
)
|
| 864 |
|
| 865 |
with gr.Row():
|
| 866 |
subject = gr.Dropdown(
|
| 867 |
choices=[],
|
| 868 |
label="📖 Subject",
|
| 869 |
+
info="Will update based on grade selection",
|
| 870 |
+
interactive=True
|
| 871 |
)
|
| 872 |
topic = gr.Textbox(
|
| 873 |
+
label="📌 Lesson Topic",
|
| 874 |
+
placeholder="e.g., Photosynthesis, Pythagorean Theorem, Parts of Speech...",
|
| 875 |
+
info="Enter the specific topic for this lesson",
|
| 876 |
+
lines=1
|
| 877 |
)
|
| 878 |
|
| 879 |
+
gr.HTML('<div class="section-header"><h3>👨🏫 School & Teacher Details</h3></div>')
|
| 880 |
|
| 881 |
with gr.Row():
|
| 882 |
school_name = gr.Textbox(
|
| 883 |
label="🏫 School Name",
|
| 884 |
+
placeholder="e.g., Government High School Gilgit",
|
| 885 |
+
info="Enter complete school name",
|
| 886 |
+
lines=1
|
| 887 |
)
|
| 888 |
teacher_name = gr.Textbox(
|
| 889 |
label="👤 Teacher Name",
|
| 890 |
+
placeholder="e.g., Muhammad Ali Khan",
|
| 891 |
+
info="Enter teacher's full name",
|
| 892 |
+
lines=1
|
| 893 |
)
|
| 894 |
district = gr.Dropdown(
|
| 895 |
choices=DISTRICTS_GB,
|
| 896 |
label="📍 District",
|
| 897 |
value="Gilgit",
|
| 898 |
+
info="Select district in Gilgit-Baltistan",
|
| 899 |
+
interactive=True
|
| 900 |
)
|
| 901 |
|
| 902 |
+
gr.HTML('<div class="section-header"><h3>⏰ Class Details & Timing</h3></div>')
|
| 903 |
|
| 904 |
with gr.Row():
|
| 905 |
date_input = gr.Textbox(
|
| 906 |
+
label="📅 Lesson Date",
|
| 907 |
value=datetime.now().strftime("%Y-%m-%d"),
|
| 908 |
placeholder="YYYY-MM-DD",
|
| 909 |
+
info="Enter date in YYYY-MM-DD format"
|
| 910 |
)
|
| 911 |
students = gr.Number(
|
| 912 |
label="👥 Number of Students",
|
| 913 |
+
value=35,
|
| 914 |
minimum=1,
|
| 915 |
maximum=100,
|
| 916 |
+
step=1,
|
| 917 |
+
info="Total students in the class"
|
| 918 |
)
|
| 919 |
duration = gr.Dropdown(
|
| 920 |
+
choices=[35, 40, 45, 50, 60, 70, 80, 90],
|
| 921 |
label="⏱️ Duration (minutes)",
|
| 922 |
value=40,
|
| 923 |
+
info="Total lesson duration",
|
| 924 |
+
interactive=True
|
| 925 |
)
|
| 926 |
|
| 927 |
+
gr.HTML('<div class="section-header"><h3>🎯 Teaching Methodology & Assessment</h3></div>')
|
| 928 |
|
| 929 |
with gr.Row():
|
| 930 |
teaching_method = gr.Dropdown(
|
| 931 |
choices=TEACHING_METHODS,
|
| 932 |
label="🎓 Primary Teaching Method",
|
| 933 |
value="Lecture Method",
|
| 934 |
+
info="Main instructional approach for this lesson",
|
| 935 |
+
interactive=True
|
| 936 |
)
|
| 937 |
assessment_type = gr.Dropdown(
|
| 938 |
choices=ASSESSMENT_TYPES,
|
| 939 |
+
label="📊 Assessment Method",
|
| 940 |
value="Formative Assessment",
|
| 941 |
+
info="How will you evaluate student learning?",
|
| 942 |
+
interactive=True
|
| 943 |
)
|
| 944 |
|
| 945 |
+
gr.HTML('<div class="section-header"><h3>⚙️ Additional Options</h3></div>')
|
| 946 |
|
| 947 |
with gr.Row():
|
| 948 |
+
with gr.Column(scale=1):
|
| 949 |
+
include_resources = gr.Checkbox(
|
| 950 |
+
label="📦 Include Teaching Resources List",
|
| 951 |
+
value=True,
|
| 952 |
+
info="Add detailed list of required materials and resources"
|
| 953 |
+
)
|
| 954 |
+
with gr.Column(scale=1):
|
| 955 |
+
include_differentiation = gr.Checkbox(
|
| 956 |
+
label="🎯 Include Differentiation Strategies",
|
| 957 |
+
value=True,
|
| 958 |
+
info="Add strategies for diverse learners (advanced, struggling, special needs)"
|
| 959 |
+
)
|
| 960 |
|
| 961 |
+
gr.Markdown("---")
|
|
|
|
| 962 |
|
| 963 |
+
# Generate button with styling
|
| 964 |
+
generate_btn = gr.Button(
|
| 965 |
+
"🚀 Generate SMART Lesson Plan",
|
| 966 |
+
variant="primary",
|
| 967 |
+
size="lg",
|
| 968 |
+
scale=2
|
| 969 |
+
)
|
| 970 |
+
|
| 971 |
+
# Instructions
|
| 972 |
+
with gr.Accordion("📖 Instructions & Tips", open=False):
|
| 973 |
+
gr.Markdown("""
|
| 974 |
+
### How to Use This Generator:
|
| 975 |
+
|
| 976 |
+
1. **Select Language**: Choose English or Urdu for your lesson plan
|
| 977 |
+
2. **Choose Grade**: Select grade range, then specific grade if needed
|
| 978 |
+
3. **Select Subject**: Will auto-populate based on grade level
|
| 979 |
+
4. **Enter Topic**: Be specific (e.g., "Photosynthesis in Plants" not just "Science")
|
| 980 |
+
5. **Fill School Info**: Enter your school name and your name
|
| 981 |
+
6. **Set Class Details**: Number of students, date, and duration
|
| 982 |
+
7. **Choose Methods**: Select teaching and assessment approaches
|
| 983 |
+
8. **Click Generate**: Wait 10-20 seconds for AI to create your plan
|
| 984 |
+
|
| 985 |
+
### 💡 Tips for Best Results:
|
| 986 |
+
|
| 987 |
+
- **Be Specific**: Instead of "Math", use "Linear Equations" or "Fractions"
|
| 988 |
+
- **Realistic Duration**: Match duration to your actual class period
|
| 989 |
+
- **Consider Context**: Choose methods suitable for your classroom resources
|
| 990 |
+
- **Review & Edit**: Always review and customize the generated plan
|
| 991 |
+
- **Save Multiple**: Generate variations to compare approaches
|
| 992 |
+
|
| 993 |
+
### ✨ What You'll Get:
|
| 994 |
+
|
| 995 |
+
- **3 SMART SLOs** aligned with Bloom's Taxonomy (Knowledge, Understanding, Application)
|
| 996 |
+
- **Comprehensive Content Knowledge** with key concepts and misconceptions
|
| 997 |
+
- **Detailed Lesson Procedure** with exact timings for each phase
|
| 998 |
+
- **Teaching Resources** list (if enabled)
|
| 999 |
+
- **Differentiation Strategies** for diverse learners (if enabled)
|
| 1000 |
+
- **SMART Home Assignment** aligned with SLOs
|
| 1001 |
+
- **Reflection Section** for post-lesson notes
|
| 1002 |
+
|
| 1003 |
+
### 🎓 About SMART SLOs:
|
| 1004 |
+
|
| 1005 |
+
SMART stands for:
|
| 1006 |
+
- **S**pecific: Clear and precise learning outcomes
|
| 1007 |
+
- **M**easurable: Can be assessed and observed
|
| 1008 |
+
- **A**chievable: Realistic within lesson time
|
| 1009 |
+
- **R**elevant: Aligned with curriculum standards
|
| 1010 |
+
- **T**ime-bound: Achievable in one lesson period
|
| 1011 |
+
""")
|
| 1012 |
+
|
| 1013 |
+
gr.Markdown("---")
|
| 1014 |
+
|
| 1015 |
+
# Output section with enhanced styling
|
| 1016 |
+
gr.HTML('<div class="section-header"><h3>📥 Your Generated Lesson Plan</h3></div>')
|
| 1017 |
+
|
| 1018 |
+
with gr.Row():
|
| 1019 |
+
with gr.Column(scale=2):
|
| 1020 |
+
status_output = gr.Textbox(
|
| 1021 |
+
label="📊 Generation Status",
|
| 1022 |
+
interactive=False,
|
| 1023 |
+
lines=10,
|
| 1024 |
+
placeholder="Status messages will appear here..."
|
| 1025 |
+
)
|
| 1026 |
+
with gr.Column(scale=1):
|
| 1027 |
+
output_file = gr.File(
|
| 1028 |
+
label="💾 Download File",
|
| 1029 |
+
file_count="single"
|
| 1030 |
+
)
|
| 1031 |
|
| 1032 |
# Event handlers
|
| 1033 |
grade_range.change(
|
| 1034 |
fn=update_subjects,
|
| 1035 |
+
inputs=[grade_range],
|
| 1036 |
+
outputs=[subject]
|
| 1037 |
)
|
| 1038 |
|
| 1039 |
generate_btn.click(
|
|
|
|
| 1047 |
outputs=[output_file, status_output]
|
| 1048 |
)
|
| 1049 |
|
| 1050 |
+
# Footer with additional information
|
| 1051 |
+
gr.Markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1052 |
|
| 1053 |
+
with gr.Accordion("ℹ️ About & Support", open=False):
|
| 1054 |
+
gr.Markdown("""
|
| 1055 |
+
### 📱 About This Application
|
| 1056 |
+
|
| 1057 |
+
**Version:** 2.0 (Production Release)
|
| 1058 |
+
**Developer:** Najaf Ali Sharqi
|
| 1059 |
+
**Organization:** School Education Department, Gilgit-Baltistan
|
| 1060 |
+
**AI Model:** Google Gemini 2.0 Flash
|
| 1061 |
+
|
| 1062 |
+
### 🎯 Features:
|
| 1063 |
+
|
| 1064 |
+
- ✅ SMART Learning Outcomes (Bloom's Taxonomy aligned)
|
| 1065 |
+
- ✅ Comprehensive lesson procedures with timings
|
| 1066 |
+
- ✅ National Curriculum Framework compliance
|
| 1067 |
+
- ✅ Bilingual support (English & Urdu)
|
| 1068 |
+
- ✅ Professional Word document formatting
|
| 1069 |
+
- ✅ Differentiation strategies
|
| 1070 |
+
- ✅ Assessment guidelines
|
| 1071 |
+
- ✅ Home assignments
|
| 1072 |
+
|
| 1073 |
+
### 📞 Support & Feedback:
|
| 1074 |
+
|
| 1075 |
+
For technical support, feature requests, or to report issues:
|
| 1076 |
+
- **Email:** Contact School Education Department
|
| 1077 |
+
- **Feedback:** Use the feedback option in your district office
|
| 1078 |
+
|
| 1079 |
+
### 🔒 Privacy & Data:
|
| 1080 |
+
|
| 1081 |
+
- All lesson plans are generated in real-time
|
| 1082 |
+
- No data is stored on external servers
|
| 1083 |
+
- Your lesson plans remain confidential
|
| 1084 |
+
- Files are temporarily created and deleted after download
|
| 1085 |
+
|
| 1086 |
+
### 📚 Resources:
|
| 1087 |
+
|
| 1088 |
+
- **National Curriculum:** [MoFEPT Website](http://www.mofept.gov.pk/)
|
| 1089 |
+
- **Bloom's Taxonomy Guide:** Refer to teacher training materials
|
| 1090 |
+
- **SMART Objectives:** Available in professional development resources
|
| 1091 |
+
|
| 1092 |
+
### 🙏 Acknowledgments:
|
| 1093 |
+
|
| 1094 |
+
This tool was developed to support teachers in Gilgit-Baltistan in creating high-quality,
|
| 1095 |
+
standards-aligned lesson plans efficiently. Special thanks to all educators who provided
|
| 1096 |
+
feedback during development.
|
| 1097 |
+
|
| 1098 |
+
---
|
| 1099 |
+
|
| 1100 |
+
**© 2024 School Education Department, Gilgit-Baltistan**
|
| 1101 |
+
*Empowering Teachers, Enriching Learning*
|
| 1102 |
+
""")
|
| 1103 |
+
|
| 1104 |
+
# Quick reference guide
|
| 1105 |
+
with gr.Accordion("📋 Quick Reference: Bloom's Taxonomy", open=False):
|
| 1106 |
+
gr.Markdown("""
|
| 1107 |
+
### Understanding Bloom's Taxonomy Levels
|
| 1108 |
+
|
| 1109 |
+
| Level | Action Verbs | Sample SLO |
|
| 1110 |
+
|-------|-------------|------------|
|
| 1111 |
+
| **Knowledge** (Remember) | Define, List, Identify, Recall, Name, State | "Students will be able to **identify** the main parts of a plant cell" |
|
| 1112 |
+
| **Understanding** (Comprehend) | Explain, Describe, Summarize, Interpret, Compare | "Students will be able to **explain** the process of photosynthesis" |
|
| 1113 |
+
| **Application** (Apply) | Apply, Demonstrate, Solve, Calculate, Use | "Students will be able to **apply** the Pythagorean theorem to solve problems" |
|
| 1114 |
+
| **Analysis** (Analyze) | Analyze, Differentiate, Examine, Compare | "Students will be able to **analyze** the causes of climate change" |
|
| 1115 |
+
| **Evaluation** (Evaluate) | Evaluate, Judge, Critique, Justify | "Students will be able to **evaluate** the effectiveness of different solutions" |
|
| 1116 |
+
| **Creation** (Create) | Create, Design, Develop, Compose | "Students will be able to **design** an experiment to test their hypothesis" |
|
| 1117 |
+
|
| 1118 |
+
### 💡 Tips:
|
| 1119 |
+
- Start with lower levels (Knowledge, Understanding) for new topics
|
| 1120 |
+
- Progress to higher levels (Application, Analysis) as students master basics
|
| 1121 |
+
- Each lesson should target 2-3 adjacent levels
|
| 1122 |
+
- Match the cognitive level to student readiness and topic complexity
|
| 1123 |
+
""")
|
| 1124 |
|
| 1125 |
+
# Launch configuration
|
| 1126 |
if __name__ == "__main__":
|
| 1127 |
demo.launch(
|
| 1128 |
server_name="0.0.0.0",
|
| 1129 |
server_port=7860,
|
| 1130 |
share=False,
|
| 1131 |
+
show_error=True,
|
| 1132 |
+
max_threads=10,
|
| 1133 |
+
inbrowser=True
|
| 1134 |
)
|