Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from docx.enum.text import WD_ALIGN_PARAGRAPH
|
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
# ---------- Helper
|
| 9 |
def eng_to_urdu_script(text):
|
| 10 |
replacements = {
|
| 11 |
"Lesson": "لیسن",
|
|
@@ -14,12 +14,13 @@ def eng_to_urdu_script(text):
|
|
| 14 |
"Content": "کانٹنٹ",
|
| 15 |
"SLO": "ایس ایل او",
|
| 16 |
"Example": "ایگزامپل",
|
| 17 |
-
"Assessment": "اسیسمنٹ",
|
| 18 |
"Assignment": "اسائنمنٹ",
|
| 19 |
"Feedback": "فیڈبیک",
|
| 20 |
"Teacher": "ٹیچر",
|
| 21 |
"Student": "سٹوڈنٹ",
|
| 22 |
"School": "سکول",
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
for eng, urdu in replacements.items():
|
| 25 |
text = text.replace(eng, urdu)
|
|
@@ -28,117 +29,118 @@ def eng_to_urdu_script(text):
|
|
| 28 |
|
| 29 |
# ---------- Core Function ----------
|
| 30 |
def generate_lesson_plan(grade, subject, topic, language):
|
| 31 |
-
#
|
| 32 |
slos = [
|
| 33 |
"طلبہ موضوع کی بنیادی تعریفات بیان کر سکیں گے۔",
|
| 34 |
-
"طلبہ
|
| 35 |
-
"طلبہ
|
| 36 |
-
]
|
| 37 |
-
|
| 38 |
-
glossary = [
|
| 39 |
-
("موضوع", topic),
|
| 40 |
-
("درجہ", grade),
|
| 41 |
-
("مضمون", subject),
|
| 42 |
]
|
| 43 |
|
|
|
|
| 44 |
if language == "English":
|
| 45 |
-
# Generate Word Document
|
| 46 |
doc = Document()
|
|
|
|
| 47 |
heading = doc.add_heading("School Education Department, Gilgit-Baltistan", level=1)
|
| 48 |
heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 49 |
-
|
| 50 |
-
run.font.color.rgb = RGBColor(0, 128, 0)
|
| 51 |
|
| 52 |
-
doc.add_paragraph().add_run("
|
| 53 |
|
| 54 |
# Input Table
|
| 55 |
table = doc.add_table(rows=1, cols=3)
|
| 56 |
hdr_cells = table.rows[0].cells
|
| 57 |
-
hdr_cells[0].text, hdr_cells[1].text, hdr_cells[2].text = "
|
| 58 |
row_cells = table.add_row().cells
|
| 59 |
-
row_cells[0].text, row_cells[1].text, row_cells[2].text =
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
doc.add_paragraph(f"{i}. {slo}", style="List Number")
|
| 64 |
|
| 65 |
-
|
|
|
|
| 66 |
doc.add_paragraph(
|
| 67 |
-
f"This lesson
|
| 68 |
-
f"Teachers will explain
|
|
|
|
|
|
|
| 69 |
)
|
| 70 |
|
| 71 |
-
|
| 72 |
-
doc.add_paragraph("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".docx")
|
| 77 |
doc.save(tmp.name)
|
| 78 |
return tmp.name
|
| 79 |
|
|
|
|
| 80 |
else:
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
glossary_table = "| اصطلاح | تفصیل | |\n|----------|----------|----------|\n"
|
| 86 |
-
glossary_table += f"| {glossary[0][0]} | {glossary[0][1]} | |\n"
|
| 87 |
-
glossary_table += f"| {glossary[1][0]} | {glossary[1][1]} | |\n"
|
| 88 |
-
glossary_table += f"| {glossary[2][0]} | {glossary[2][1]} | |\n"
|
| 89 |
|
| 90 |
-
|
| 91 |
-
{
|
| 92 |
|
| 93 |
---
|
| 94 |
|
| 95 |
-
**س
|
| 96 |
-
**مضمون:** {subject}
|
| 97 |
-
**درجہ:** {grade}
|
| 98 |
|
| 99 |
---
|
| 100 |
|
| 101 |
-
{
|
| 102 |
|
| 103 |
---
|
| 104 |
|
| 105 |
-
**ایس ایل اوز:**
|
| 106 |
-
1. {slos[0]}
|
| 107 |
-
2. {slos[1]}
|
| 108 |
-
3. {slos[2]}
|
| 109 |
|
| 110 |
---
|
| 111 |
|
| 112 |
-
**
|
| 113 |
-
یہ سبق {eng_to_urdu_script(topic)}
|
| 114 |
-
اساتذہ ان تعریفات اور اصطلاحات کو
|
|
|
|
| 115 |
|
| 116 |
---
|
| 117 |
|
| 118 |
-
**گھر کا کام (اختیاری):**
|
| 119 |
-
طلبہ
|
| 120 |
-
ہر کلیدی اصطلاح کے معنی اور مثال لکھیں تاکہ سبق کی سمجھ بہتر ہو۔
|
| 121 |
|
| 122 |
---
|
| 123 |
|
| 124 |
-
**فیڈبیک برائے مینٹر/پرنسپل:**
|
| 125 |
|
| 126 |
---
|
| 127 |
"""
|
| 128 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
| 129 |
with open(tmp.name, "w", encoding="utf-8") as f:
|
| 130 |
-
f.write(
|
| 131 |
return tmp.name
|
| 132 |
|
| 133 |
|
| 134 |
-
# ---------- Gradio
|
| 135 |
def app_interface(grade, subject, topic, language):
|
| 136 |
file_path = generate_lesson_plan(grade, subject, topic, language)
|
| 137 |
return file_path
|
| 138 |
|
| 139 |
|
| 140 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 141 |
-
gr.Markdown("## 📘 Smart Lesson Plan Generator\
|
| 142 |
|
| 143 |
with gr.Row():
|
| 144 |
grade = gr.Textbox(label="Grade / درجہ")
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
# ---------- Helper for Urdu Transliteration ----------
|
| 9 |
def eng_to_urdu_script(text):
|
| 10 |
replacements = {
|
| 11 |
"Lesson": "لیسن",
|
|
|
|
| 14 |
"Content": "کانٹنٹ",
|
| 15 |
"SLO": "ایس ایل او",
|
| 16 |
"Example": "ایگزامپل",
|
|
|
|
| 17 |
"Assignment": "اسائنمنٹ",
|
| 18 |
"Feedback": "فیڈبیک",
|
| 19 |
"Teacher": "ٹیچر",
|
| 20 |
"Student": "سٹوڈنٹ",
|
| 21 |
"School": "سکول",
|
| 22 |
+
"Education": "ایجوکیشن",
|
| 23 |
+
"Department": "ڈیپارٹمنٹ",
|
| 24 |
}
|
| 25 |
for eng, urdu in replacements.items():
|
| 26 |
text = text.replace(eng, urdu)
|
|
|
|
| 29 |
|
| 30 |
# ---------- Core Function ----------
|
| 31 |
def generate_lesson_plan(grade, subject, topic, language):
|
| 32 |
+
# Sample SLOs
|
| 33 |
slos = [
|
| 34 |
"طلبہ موضوع کی بنیادی تعریفات بیان کر سکیں گے۔",
|
| 35 |
+
"طلبہ کلیدی اصطلاحات کی وضاحت کر سکیں گے۔",
|
| 36 |
+
"طلبہ مثالوں کے ذریعے تصور کو سمجھ سکیں گے۔"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
]
|
| 38 |
|
| 39 |
+
# --- ENGLISH VERSION ---
|
| 40 |
if language == "English":
|
|
|
|
| 41 |
doc = Document()
|
| 42 |
+
|
| 43 |
heading = doc.add_heading("School Education Department, Gilgit-Baltistan", level=1)
|
| 44 |
heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 45 |
+
heading.runs[0].font.color.rgb = RGBColor(0, 128, 0)
|
|
|
|
| 46 |
|
| 47 |
+
doc.add_paragraph().add_run("SMART LESSON PLAN").bold = True
|
| 48 |
|
| 49 |
# Input Table
|
| 50 |
table = doc.add_table(rows=1, cols=3)
|
| 51 |
hdr_cells = table.rows[0].cells
|
| 52 |
+
hdr_cells[0].text, hdr_cells[1].text, hdr_cells[2].text = "Grade", "Subject", "Topic"
|
| 53 |
row_cells = table.add_row().cells
|
| 54 |
+
row_cells[0].text, row_cells[1].text, row_cells[2].text = grade, subject, topic
|
| 55 |
+
|
| 56 |
+
# SLOs
|
| 57 |
+
doc.add_paragraph().add_run("SLOs (Student Learning Outcomes):").bold = True
|
| 58 |
+
for i, slo in enumerate([
|
| 59 |
+
"Define key concepts related to the topic.",
|
| 60 |
+
"Explain important terms and definitions.",
|
| 61 |
+
"Apply examples to understand the concept."
|
| 62 |
+
], 1):
|
| 63 |
doc.add_paragraph(f"{i}. {slo}", style="List Number")
|
| 64 |
|
| 65 |
+
# Lesson Notes (Content)
|
| 66 |
+
doc.add_paragraph().add_run("Lesson Notes (Content):").bold = True
|
| 67 |
doc.add_paragraph(
|
| 68 |
+
f"This lesson focuses on the topic '{topic}'. "
|
| 69 |
+
f"Teachers will briefly explain the definitions and key terms related to {topic}, "
|
| 70 |
+
f"providing examples that support student understanding. "
|
| 71 |
+
"These notes will guide the teacher before classroom delivery."
|
| 72 |
)
|
| 73 |
|
| 74 |
+
# Home Assignment
|
| 75 |
+
doc.add_paragraph().add_run("Home Assignment (Optional):").bold = True
|
| 76 |
+
doc.add_paragraph(
|
| 77 |
+
"Students will write short notes on the key terms discussed in the lesson "
|
| 78 |
+
"and provide one real-life example related to the topic."
|
| 79 |
+
)
|
| 80 |
|
| 81 |
+
# Feedback
|
| 82 |
+
doc.add_paragraph().add_run("Feedback by the Mentor/Principal:").bold = True
|
| 83 |
|
| 84 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".docx")
|
| 85 |
doc.save(tmp.name)
|
| 86 |
return tmp.name
|
| 87 |
|
| 88 |
+
# --- URDU VERSION ---
|
| 89 |
else:
|
| 90 |
+
urdu_text = """اسکول ایجوکیشن ڈیپارٹمنٹ، گلگت بلتستان
|
| 91 |
+
(سبز رنگ میں)"""
|
| 92 |
+
urdu_department = "اسکول ایجوکیشن ڈیپارٹمنٹ، گلگت بلتستان"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
content = f"""
|
| 95 |
+
**{urdu_department}**
|
| 96 |
|
| 97 |
---
|
| 98 |
|
| 99 |
+
**اسمارٹ لیسن پلان**
|
|
|
|
|
|
|
| 100 |
|
| 101 |
---
|
| 102 |
|
| 103 |
+
**درجہ:** {grade} **مضمون:** {subject} **موضوع:** {topic}
|
| 104 |
|
| 105 |
---
|
| 106 |
|
| 107 |
+
**ایس ایل اوز (طلبہ کے سیکھنے کے نتائج):**
|
| 108 |
+
1. {slos[0]}
|
| 109 |
+
2. {slos[1]}
|
| 110 |
+
3. {slos[2]}
|
| 111 |
|
| 112 |
---
|
| 113 |
|
| 114 |
+
**سبق کے نوٹس (مواد):**
|
| 115 |
+
یہ سبق **{eng_to_urdu_script(topic)}** سے متعلق اہم تعریفات اور کلیدی اصطلاحات پر مشتمل ہے۔
|
| 116 |
+
اساتذہ سبق سے پہلے ان تعریفات اور اصطلاحات کو سمجھیں تاکہ وہ کلاس روم میں وضاحت کے ساتھ سمجھا سکیں۔
|
| 117 |
+
مثالوں کے ذریعے طلبہ کو موضوع کی بہتر سمجھ فراہم کی جائے گی۔
|
| 118 |
|
| 119 |
---
|
| 120 |
|
| 121 |
+
**گھر کا کام (اختیاری):**
|
| 122 |
+
طلبہ سے کہا جائے کہ وہ سبق میں شامل کلیدی اصطلاحات کی مختصر تعریفات لکھیں اور ایک مثال فراہم کریں۔
|
|
|
|
| 123 |
|
| 124 |
---
|
| 125 |
|
| 126 |
+
**فیڈبیک برائے مینٹر / پرنسپل:**
|
| 127 |
|
| 128 |
---
|
| 129 |
"""
|
| 130 |
tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
|
| 131 |
with open(tmp.name, "w", encoding="utf-8") as f:
|
| 132 |
+
f.write(content)
|
| 133 |
return tmp.name
|
| 134 |
|
| 135 |
|
| 136 |
+
# ---------- Gradio Interface ----------
|
| 137 |
def app_interface(grade, subject, topic, language):
|
| 138 |
file_path = generate_lesson_plan(grade, subject, topic, language)
|
| 139 |
return file_path
|
| 140 |
|
| 141 |
|
| 142 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 143 |
+
gr.Markdown("## 📘 Smart Lesson Plan Generator\nDeveloped by **Najaf Ali Sharqi**")
|
| 144 |
|
| 145 |
with gr.Row():
|
| 146 |
grade = gr.Textbox(label="Grade / درجہ")
|