Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,173 +1,128 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from google import genai
|
| 3 |
from docx import Document
|
| 4 |
-
from docx.
|
| 5 |
-
from
|
| 6 |
-
|
| 7 |
-
from datetime import date
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def generate_lesson_plan(language, grade, subject, topic, students, duration, teacher_name):
|
| 13 |
-
# ===== Prompt =====
|
| 14 |
-
prompt = f"""
|
| 15 |
-
You are a qualified and experienced school teacher in Pakistan, well-versed in the National Curriculum of Pakistan.
|
| 16 |
-
Your task is to create a complete and structured "SMART LESSON PLAN" in the language requested by the user (either Urdu or English).
|
| 17 |
-
|
| 18 |
-
If Urdu is selected, write right-to-left in Jameel Noori Nastaleeq style, with English words in Urdu script (for example, "Science" as "سائنس").
|
| 19 |
-
Avoid all symbols, bullets, or special characters.
|
| 20 |
-
Generate only the following sections once, clearly separated and formatted:
|
| 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 SLO related to "{topic}".
|
| 27 |
-
2. Write the second SLO related to "{topic}".
|
| 28 |
-
3. Write the third SLO related to "{topic}".
|
| 29 |
-
|
| 30 |
-
B) Content to be delivered:
|
| 31 |
-
Write detailed and clear content (definitions, explanations, and one example) about "{topic}" aligned with the SLOs.
|
| 32 |
-
Ensure it fits Grade {grade} Pakistani context.
|
| 33 |
-
|
| 34 |
-
C) Home Assignment:
|
| 35 |
-
Create a simple and creative home assignment aligned with SLOs that can be completed within 24 hours.
|
| 36 |
-
|
| 37 |
-
D) Feedback by the Mentor/ Principal:
|
| 38 |
-
(Leave four continuous blank lines.)
|
| 39 |
-
"""
|
| 40 |
-
|
| 41 |
-
# ===== Generate Response =====
|
| 42 |
-
response = client.models.generate_content(
|
| 43 |
-
model="gemini-2.5-flash",
|
| 44 |
-
contents=prompt,
|
| 45 |
-
)
|
| 46 |
-
lesson_text = response.text.strip()
|
| 47 |
-
|
| 48 |
-
# ===== File Generation Based on Language =====
|
| 49 |
if language == "English":
|
| 50 |
-
# Create Word Document
|
| 51 |
doc = Document()
|
| 52 |
-
|
| 53 |
# Header
|
| 54 |
section = doc.sections[0]
|
| 55 |
-
header = section.header
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
# Footer with page numbers
|
| 61 |
-
footer = section.footer
|
| 62 |
-
footer_para = footer.paragraphs[0]
|
| 63 |
-
footer_para.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 64 |
-
footer_para.add_run("Page ").add_field('PAGE')
|
| 65 |
-
footer_para.add_run(" of ").add_field('NUMPAGES')
|
| 66 |
-
|
| 67 |
# Title
|
| 68 |
-
doc.add_heading("SMART LESSON PLAN", level=1)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
table.cell(i, 1).text = value
|
| 86 |
-
|
| 87 |
-
# Add Lesson Content
|
| 88 |
-
doc.add_paragraph()
|
| 89 |
-
for line in lesson_text.splitlines():
|
| 90 |
-
doc.add_paragraph(line)
|
| 91 |
-
|
| 92 |
-
# Save DOCX
|
| 93 |
-
file_name = f"SMART_Lesson_Plan_{topic.replace(' ', '_')}.docx"
|
| 94 |
-
doc.save(file_name)
|
| 95 |
-
return lesson_text, file_name
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
موضوع: {topic}
|
| 106 |
-
طلباء کی تعداد: {students}
|
| 107 |
-
دورانیہ: {duration} منٹ
|
| 108 |
-
استاد کا نام: {teacher_name}
|
| 109 |
-
تاریخ: {date.today()}
|
| 110 |
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
|
| 115 |
-
---
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
|
|
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
-
#
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
grade = gr.Dropdown(
|
| 136 |
-
["Grade 1", "Grade 2", "Grade 3", "Grade 4", "Grade 5", "Grade 6", "Grade 7", "Grade 8", "Grade 9", "Grade 10", "Grade 11", "Grade 12"],
|
| 137 |
-
label="Select Grade Level"
|
| 138 |
-
)
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
topic = gr.Textbox(label="Enter Topic (e.g., Chemical Bonding)")
|
| 146 |
|
| 147 |
-
with gr.Row():
|
| 148 |
-
students = gr.Dropdown(
|
| 149 |
-
["20", "25", "30", "35", "40", "45", "50+"],
|
| 150 |
-
label="Number of Students"
|
| 151 |
-
)
|
| 152 |
-
duration = gr.Dropdown(
|
| 153 |
-
["30", "35", "40", "45", "50", "60"],
|
| 154 |
-
label="Duration (in minutes)"
|
| 155 |
-
)
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
with gr.Row():
|
| 158 |
-
|
| 159 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
generate_btn = gr.Button("Generate Lesson Plan")
|
| 161 |
-
|
| 162 |
-
download_file = gr.File(label="Download File")
|
| 163 |
-
|
| 164 |
generate_btn.click(
|
| 165 |
generate_lesson_plan,
|
| 166 |
-
inputs=[language, grade, subject, topic, students, duration, teacher_name],
|
| 167 |
-
outputs=
|
| 168 |
)
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
demo.launch()
|
| 173 |
-
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from docx import Document
|
| 3 |
+
from docx.shared import Pt
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
import markdown
|
|
|
|
| 6 |
|
| 7 |
+
def generate_lesson_plan(language, grade, subject, topic, students, duration, teacher_name, date):
|
| 8 |
+
# --------------------- ENGLISH VERSION ---------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
if language == "English":
|
|
|
|
| 10 |
doc = Document()
|
| 11 |
+
|
| 12 |
# Header
|
| 13 |
section = doc.sections[0]
|
| 14 |
+
header = section.header.paragraphs[0]
|
| 15 |
+
header.text = "School Education Department, Gilgit-Baltistan"
|
| 16 |
+
header.alignment = 1 # center
|
| 17 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Title
|
| 19 |
+
doc.add_heading("SMART LESSON PLAN", level=1)
|
| 20 |
+
doc.add_paragraph(f"Grade Level: {grade}")
|
| 21 |
+
doc.add_paragraph(f"Subject: {subject}")
|
| 22 |
+
doc.add_paragraph(f"Topic: {topic}")
|
| 23 |
+
doc.add_paragraph(f"Number of Students: {students}")
|
| 24 |
+
doc.add_paragraph(f"Duration: {duration}")
|
| 25 |
+
doc.add_paragraph(f"Teacher Name: {teacher_name}")
|
| 26 |
+
doc.add_paragraph(f"Date: {date}")
|
| 27 |
+
|
| 28 |
+
# Content to be Delivered
|
| 29 |
+
doc.add_heading("Content to be Delivered", level=2)
|
| 30 |
+
doc.add_paragraph(
|
| 31 |
+
"Explain the concept of Chemical Bonding by introducing ionic and covalent bonds. "
|
| 32 |
+
"Use real-life examples like the bonding in NaCl and water molecules. "
|
| 33 |
+
"Demonstrate through molecular models and guide students to identify the type of bonding in given compounds. "
|
| 34 |
+
"Conclude with a class discussion to reinforce understanding."
|
| 35 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# SLOs
|
| 38 |
+
doc.add_heading("SLOs (Student Learning Outcomes)", level=2)
|
| 39 |
+
doc.add_paragraph(
|
| 40 |
+
"By the end of the lesson, students will be able to:\n"
|
| 41 |
+
"1. Define and differentiate between ionic and covalent bonds.\n"
|
| 42 |
+
"2. Describe examples of both bond types.\n"
|
| 43 |
+
"3. Predict the type of bond formed between given elements."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Home Assignment
|
| 47 |
+
doc.add_heading("Home Assignment", level=2)
|
| 48 |
+
doc.add_paragraph(
|
| 49 |
+
"1. Write short notes on types of chemical bonds.\n"
|
| 50 |
+
"2. Draw Lewis structures for the following compounds: H₂O, CO₂, NaCl.\n"
|
| 51 |
+
"3. Explain how ionic and covalent bonds contribute to compound stability.\n"
|
| 52 |
+
"4. Align responses with today’s lesson SLOs."
|
| 53 |
+
)
|
| 54 |
|
| 55 |
+
# Feedback Section
|
| 56 |
+
doc.add_heading("Feedback by the Mentor / Principal", level=2)
|
| 57 |
+
doc.add_paragraph("\n" * 4) # Four blank lines for manual feedback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
# Footer (Page number text manually)
|
| 60 |
+
footer = section.footer.paragraphs[0]
|
| 61 |
+
footer.text = "Page 1 of 3"
|
| 62 |
+
footer.alignment = 1 # center
|
| 63 |
|
| 64 |
+
filename = "Lesson_Plan_English.docx"
|
| 65 |
+
doc.save(filename)
|
| 66 |
+
return filename
|
| 67 |
|
| 68 |
+
# --------------------- URDU VERSION ---------------------
|
| 69 |
+
else:
|
| 70 |
+
content = f"""
|
| 71 |
+
# سمارٹ سبق منصوبہ
|
| 72 |
|
| 73 |
+
**کلاس:** {grade}
|
| 74 |
+
**مضمون:** {subject}
|
| 75 |
+
**موضوع:** {topic}
|
| 76 |
+
**طلبہ کی تعداد:** {students}
|
| 77 |
+
**دورانیہ:** {duration}
|
| 78 |
+
**استاد کا نام:** {teacher_name}
|
| 79 |
+
**تاریخ:** {date}
|
| 80 |
|
| 81 |
+
## مواد جو پڑھایا جائے گا
|
| 82 |
+
کیمیائی بندش کے تصور کو مثالوں کے ذریعے واضح کریں، مثلاً سوڈیم کلورائیڈ اور پانی کے سالمے۔ طلبہ کو مختلف مرکبات میں بندش کی نوعیت پہچاننے کے لیے رہنمائی فراہم کریں۔ سبق کے آخر میں بحث کے ذریعے سمجھ کو مضبوط بنائیں۔
|
| 83 |
|
| 84 |
+
## مقاصدِ سبق (SLOs)
|
| 85 |
+
1. طلبہ آئنک اور کوویلنٹ بندش میں فرق بیان کریں۔
|
| 86 |
+
2. دونوں اقسام کی مثالیں وضاحت سے پیش کریں۔
|
| 87 |
+
3. مختلف عناصر کے ملاپ سے بندش کی نوعیت بتائیں۔
|
| 88 |
|
| 89 |
+
## گھریلو کام
|
| 90 |
+
1. بندش کی اقسام پر مختصر نوٹ لکھیں۔
|
| 91 |
+
2. درج ذیل مرکبات کے لیوس اسٹرکچر بنائیں: H₂O، CO₂، NaCl۔
|
| 92 |
+
3. وضاحت کریں کہ آئنک اور کوویلنٹ بندش کس طرح مرکب کے استحکام میں مددگار ہیں۔
|
| 93 |
|
| 94 |
+
## رائے برائے رہنمائی / پرنسپل کی طرف سے
|
| 95 |
+
(چار سطور خالی جگہ برائے رائے)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
"""
|
| 98 |
+
filename = "Lesson_Plan_Urdu.md"
|
| 99 |
+
with open(filename, "w", encoding="utf-8") as f:
|
| 100 |
+
f.write(content)
|
| 101 |
+
return filename
|
|
|
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
# --------- Gradio UI ------------
|
| 105 |
+
with gr.Blocks(theme="soft") as app:
|
| 106 |
+
gr.Markdown("## SMART Lesson Plan Generator\nDeveloped by **Najaf Ali Sharqi**")
|
| 107 |
+
|
| 108 |
with gr.Row():
|
| 109 |
+
language = gr.Dropdown(["English", "Urdu"], label="Select Language")
|
| 110 |
+
grade = gr.Dropdown([str(i) for i in range(1, 13)], label="Grade Level")
|
| 111 |
+
subject = gr.Dropdown(["Chemistry", "Physics", "Biology", "Mathematics", "Urdu", "English"], label="Subject")
|
| 112 |
+
|
| 113 |
+
topic = gr.Textbox(label="Topic")
|
| 114 |
+
students = gr.Number(label="Number of Students", value=30)
|
| 115 |
+
duration = gr.Dropdown(["30 minutes", "40 minutes", "45 minutes", "60 minutes"], label="Duration")
|
| 116 |
+
teacher_name = gr.Textbox(label="Teacher Name")
|
| 117 |
+
date = gr.Textbox(label="Date (YYYY-MM-DD)", value=str(datetime.now().date()))
|
| 118 |
+
|
| 119 |
+
output = gr.File(label="Download Lesson Plan")
|
| 120 |
generate_btn = gr.Button("Generate Lesson Plan")
|
| 121 |
+
|
|
|
|
|
|
|
| 122 |
generate_btn.click(
|
| 123 |
generate_lesson_plan,
|
| 124 |
+
inputs=[language, grade, subject, topic, students, duration, teacher_name, date],
|
| 125 |
+
outputs=output
|
| 126 |
)
|
| 127 |
|
| 128 |
+
app.launch()
|
|
|
|
|
|
|
|
|