Turbiling commited on
Commit
b1d497e
·
verified ·
1 Parent(s): 9d03731

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -31
app.py CHANGED
@@ -3,7 +3,6 @@ from docx import Document
3
  from docx.shared import RGBColor
4
  from docx.enum.text import WD_ALIGN_PARAGRAPH
5
  import tempfile
6
- import os
7
 
8
  # ---------- Helper: English → Urdu word replacements ----------
9
  def eng_to_urdu_script(text):
@@ -25,23 +24,51 @@ def eng_to_urdu_script(text):
25
  text = text.replace(eng, urdu)
26
  return text
27
 
 
28
  # ---------- Core Function ----------
29
  def generate_lesson_plan(grade, subject, topic, teacher, date, language):
30
- # Simulated SLOs
31
  slos = [
32
- "Define key concepts and terms related to the topic.",
33
- "Explain with examples how the concept applies in real life.",
34
- "Differentiate the topic from similar concepts.",
35
  ]
36
 
37
- # Convert SLOs to Lesson Notes (brief answers to WH questions)
38
- lesson_notes = [
39
- f"This section explains the meaning of '{topic}' with definitions and key terms. For example, [insert key term example].",
40
- f"Here we explore practical applications of '{topic}' in real-life situations. For instance, [insert real-life example].",
41
- f"We compare '{topic}' with related concepts and highlight differences to strengthen understanding.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ]
43
 
44
  if language == "English":
 
45
  doc = Document()
46
  heading = doc.add_heading("School Education Department, Gilgit-Baltistan", level=1)
47
  heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
@@ -61,18 +88,19 @@ def generate_lesson_plan(grade, subject, topic, teacher, date, language):
61
 
62
  doc.add_paragraph().add_run("SLOs (Student Learning Outcomes)").bold = True
63
  doc.add_paragraph("At the end of this lesson, students will be able to:")
64
-
65
  for i, slo in enumerate(slos, 1):
66
  doc.add_paragraph(f"{i}. {slo}", style="List Number")
67
 
68
  doc.add_paragraph().add_run("Lesson Notes (Content)").bold = True
69
- for note in lesson_notes:
70
- doc.add_paragraph(note)
 
 
 
71
 
72
  doc.add_paragraph().add_run("Home Assignment (Optional)").bold = True
73
  doc.add_paragraph(
74
- "Students will write short notes defining the key terms, "
75
- "give one real-life example, and submit it in their notebooks."
76
  )
77
 
78
  doc.add_paragraph().add_run("Feedback by the Mentor/Principal").bold = True
@@ -82,18 +110,13 @@ def generate_lesson_plan(grade, subject, topic, teacher, date, language):
82
  return tmp.name
83
 
84
  else:
 
85
  urdu_heading = "اسکول ایجوکیشن ڈیپارٹمنٹ، گلگت بلتستان"
86
  glossary_table = "| درجہ | مضمون | موضوع |\n|-------|--------|--------|\n"
87
  glossary_table += f"| {grade} | {subject} | {topic} |\n"
88
 
89
- urdu_notes = [
90
- f"{eng_to_urdu_script('Define')} '{topic}' کے بنیادی تصورات اور اصطلاحات کی وضاحت کرتے ہیں۔ مثال کے طور پر، [کلیدی اصطلاح کی مثال]۔",
91
- f"'{topic}' کے حقیقی زندگی میں اطلاق کی مثالیں بیان کی جاتی ہیں۔ مثال کے طور پر، [حقیقی زندگی کی مثال]۔",
92
- f"'{topic}' کو مشابہ تصورا�� سے موازنہ کیا جاتا ہے تاکہ طلبہ کی سمجھ مضبوط ہو۔",
93
- ]
94
-
95
  urdu_text = f"""
96
- **<span style='color:green'>{urdu_heading}</span>**
97
 
98
  ---
99
 
@@ -108,27 +131,34 @@ def generate_lesson_plan(grade, subject, topic, teacher, date, language):
108
 
109
  **ایس ایل اوز (طلبا کے سیکھنے کے نتائج):**
110
  سبق کے اختتام پر طلبہ یہ کرنے کے قابل ہوں گے:
111
- 1. {slos[0]}
112
- 2. {slos[1]}
113
- 3. {slos[2]}
114
 
115
  ---
116
 
117
  **سبق کے نوٹس (مواد):**
118
- {urdu_notes[0]}
119
- {urdu_notes[1]}
120
- {urdu_notes[2]}
 
 
 
 
 
 
121
 
122
  ---
123
 
124
  **گھر کا کام (اختیاری):**
125
- طلبہ ہر کلیدی اصطلاح کی تعریف لکھیں، ایک مثال دیں اور اپنی کاپی میں جمع کریں۔
126
 
127
  ---
128
 
129
  **فیڈبیک برائے مینٹر/پرنسپل:**
130
- """
131
 
 
 
132
  tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
133
  with open(tmp.name, "w", encoding="utf-8") as f:
134
  f.write(urdu_text)
@@ -142,7 +172,7 @@ def app_interface(grade, subject, topic, teacher, date, language):
142
 
143
 
144
  with gr.Blocks(theme=gr.themes.Soft()) as app:
145
- gr.Markdown("## SMART LESSON PLAN GENERATOR\nDeveloped by **Najaf Ali Sharqi**")
146
 
147
  with gr.Row():
148
  grade = gr.Textbox(label="Grade / درجہ")
 
3
  from docx.shared import RGBColor
4
  from docx.enum.text import WD_ALIGN_PARAGRAPH
5
  import tempfile
 
6
 
7
  # ---------- Helper: English → Urdu word replacements ----------
8
  def eng_to_urdu_script(text):
 
24
  text = text.replace(eng, urdu)
25
  return text
26
 
27
+
28
  # ---------- Core Function ----------
29
  def generate_lesson_plan(grade, subject, topic, teacher, date, language):
30
+ # ---------- Exactly 3 SMART SLOs ----------
31
  slos = [
32
+ f"Understand the key concept of {topic}.",
33
+ f"Identify examples and practical applications of {topic}.",
34
+ f"Explain the significance and differentiate {topic} from related concepts."
35
  ]
36
 
37
+ # ---------- Generate Lesson Notes based on SLOs ----------
38
+ lesson_notes = ""
39
+ wh_questions = [
40
+ [
41
+ f"What is {topic}?",
42
+ f"Why is {topic} important? Give an example."
43
+ ],
44
+ [
45
+ f"Give one real-life example of {topic}.",
46
+ f"How is {topic} applied in daily life? Explain briefly."
47
+ ],
48
+ [
49
+ f"How does {topic} differ from similar concepts?",
50
+ f"What are the key points to remember about {topic}?"
51
+ ]
52
+ ]
53
+
54
+ # Brief answers
55
+ answers = [
56
+ [
57
+ f"{topic} is the process/concept that explains its fundamental definition and principles.",
58
+ f"{topic} is important because it helps understand related phenomena. For example, [provide simple example]."
59
+ ],
60
+ [
61
+ f"An example of {topic} is [insert practical classroom example].",
62
+ f"In daily life, {topic} is applied in situations like [give example]."
63
+ ],
64
+ [
65
+ f"{topic} differs from similar concepts because of [key distinguishing feature].",
66
+ f"Key points to remember include [point 1, point 2, point 3]."
67
+ ]
68
  ]
69
 
70
  if language == "English":
71
+ # ---------- Generate Word Document ----------
72
  doc = Document()
73
  heading = doc.add_heading("School Education Department, Gilgit-Baltistan", level=1)
74
  heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
 
88
 
89
  doc.add_paragraph().add_run("SLOs (Student Learning Outcomes)").bold = True
90
  doc.add_paragraph("At the end of this lesson, students will be able to:")
 
91
  for i, slo in enumerate(slos, 1):
92
  doc.add_paragraph(f"{i}. {slo}", style="List Number")
93
 
94
  doc.add_paragraph().add_run("Lesson Notes (Content)").bold = True
95
+ for i, (qs, ans) in enumerate(zip(wh_questions, answers), 1):
96
+ doc.add_paragraph(f"SLO {i}: {slos[i-1]}", bold=True)
97
+ for q, a in zip(qs, ans):
98
+ doc.add_paragraph(f"Q: {q}")
99
+ doc.add_paragraph(f"A: {a}")
100
 
101
  doc.add_paragraph().add_run("Home Assignment (Optional)").bold = True
102
  doc.add_paragraph(
103
+ "Students will answer the above questions in brief and provide one additional example of their own."
 
104
  )
105
 
106
  doc.add_paragraph().add_run("Feedback by the Mentor/Principal").bold = True
 
110
  return tmp.name
111
 
112
  else:
113
+ # ---------- Urdu Markdown Version ----------
114
  urdu_heading = "اسکول ایجوکیشن ڈیپارٹمنٹ، گلگت بلتستان"
115
  glossary_table = "| درجہ | مضمون | موضوع |\n|-------|--------|--------|\n"
116
  glossary_table += f"| {grade} | {subject} | {topic} |\n"
117
 
 
 
 
 
 
 
118
  urdu_text = f"""
119
+ **{urdu_heading}**
120
 
121
  ---
122
 
 
131
 
132
  **ایس ایل اوز (طلبا کے سیکھنے کے نتائج):**
133
  سبق کے اختتام پر طلبہ یہ کرنے کے قابل ہوں گے:
134
+ 1. {eng_to_urdu_script(slos[0])}
135
+ 2. {eng_to_urdu_script(slos[1])}
136
+ 3. {eng_to_urdu_script(slos[2])}
137
 
138
  ---
139
 
140
  **سبق کے نوٹس (مواد):**
141
+ """
142
+
143
+ for i, (qs, ans) in enumerate(zip(wh_questions, answers), 1):
144
+ urdu_text += f"**ایس ایل او {i}: {eng_to_urdu_script(slos[i-1])}**\n"
145
+ for q, a in zip(qs, ans):
146
+ urdu_text += f"سوال: {eng_to_urdu_script(q)}\n"
147
+ urdu_text += f"جواب: {eng_to_urdu_script(a)}\n"
148
+
149
+ urdu_text += """
150
 
151
  ---
152
 
153
  **گھر کا کام (اختیاری):**
154
+ طلبہ اوپر دیے گئے سوالات کے جوابات لکھیں اور اپنا ایک اضافی مثال دیں۔
155
 
156
  ---
157
 
158
  **فیڈبیک برائے مینٹر/پرنسپل:**
 
159
 
160
+ ---
161
+ """
162
  tmp = tempfile.NamedTemporaryFile(delete=False, suffix=".md")
163
  with open(tmp.name, "w", encoding="utf-8") as f:
164
  f.write(urdu_text)
 
172
 
173
 
174
  with gr.Blocks(theme=gr.themes.Soft()) as app:
175
+ gr.Markdown("## 📘 SMART LESSON PLAN GENERATOR\nDeveloped by **Najaf Ali Sharqi**")
176
 
177
  with gr.Row():
178
  grade = gr.Textbox(label="Grade / درجہ")