Turbiling commited on
Commit
cb5a0c7
·
verified ·
1 Parent(s): 9adf13c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -78
app.py CHANGED
@@ -1,69 +1,73 @@
1
  import gradio as gr
2
  from docx import Document
3
- from docx.shared import Pt, RGBColor
4
  from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
5
- import os
6
  from datetime import datetime
7
- import random
8
 
9
- # ✅ Function to generate SLOs, content, and home assignment dynamically
10
  def auto_generate_sections(topic, subject, language):
11
- # English version
12
  if language == "English":
13
  slos = [
14
- f"Define key concepts related to {topic}.",
15
- f"Explain how {topic} applies in real-world examples.",
16
- f"Analyze problems or examples involving {topic}.",
17
  ]
 
18
  content = (
19
- f"The teacher will introduce the concept of {topic} through real-life examples and diagrams. "
20
- f"Students will discuss how {topic} is applied in everyday life and perform a short activity to reinforce the concept."
 
 
 
21
  )
 
22
  assignment = (
23
- f"Students will write short notes on {topic} and give two examples from their daily life. "
24
- f"They will also solve one worksheet related to the topic."
25
  )
26
 
27
- # Urdu version
28
  else:
29
  slos = [
30
- f"{topic} کے بنیادی تصورات کی وضاحت کریں۔",
31
- f"وضاحت کریں کہ {topic} حقیقی زندگی میں کیسے لاگو ہوتا ہے۔",
32
- f"{topic} سے متعلق مسائل یا مثالوں کا تجزیہ کریں۔",
33
  ]
 
34
  content = (
35
- f"استاد {topic} کے تصور کو حقیقی زندگی کی مثالوں اور تصویری خاکوں کے ذریعے متعارف کرائے گا۔ "
36
- f"طلباء گفتگو کریں گے کہ {topic} روزمرہ زندگی میں کیسے لاگو ہوتا ہے اور ایک مختصر سرگرمی انجام دیں گے۔"
 
 
 
37
  )
 
38
  assignment = (
39
- f"طلباء {topic} پر مختصر نوٹس لکھیں گے اور روزمرہ زندگی سے دو مثالیں دیں گے۔ "
40
- f"وہ اس موضوع سے متعلق ایک ورک شیٹ بھی مکمل کریں گے۔"
41
  )
42
 
43
  return slos, content, assignment
44
 
45
 
46
- # ✅ Generate Lesson Plan
47
  def generate_lesson_plan(grade, subject, topic, num_students, duration, teacher_name, date, language):
48
 
49
- # Ensure valid output path
50
- output_dir = "/tmp"
51
- os.makedirs(output_dir, exist_ok=True)
52
 
53
- # Generate dynamic content
54
  slos, content, assignment = auto_generate_sections(topic, subject, language)
55
 
56
  if language == "English":
57
- file_path = os.path.join(output_dir, "SMART_Lesson_Plan_English.docx")
58
  doc = Document()
59
 
60
  # Header
61
  header = doc.add_paragraph("School Education Department, Gilgit-Baltistan")
62
  header.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
63
  run = header.runs[0]
64
- run.font.color.rgb = RGBColor(0, 128, 0)
65
- run.bold = True
66
  run.font.size = Pt(14)
 
 
67
 
68
  # Title
69
  title = doc.add_paragraph("SMART LESSON PLAN")
@@ -71,44 +75,43 @@ def generate_lesson_plan(grade, subject, topic, num_students, duration, teacher_
71
  title.runs[0].bold = True
72
  title.runs[0].font.size = Pt(16)
73
 
74
- # Table for details
 
75
  table = doc.add_table(rows=6, cols=2)
76
- details = [
77
- ("Grade Level:", grade),
78
- ("Subject:", subject),
79
- ("Topic:", topic),
80
- ("Number of Students:", str(num_students)),
81
- ("Duration:", duration),
82
- ("Teacher Name:", teacher_name or ""),
83
  ]
84
- for i, (key, value) in enumerate(details):
85
- row = table.rows[i]
86
- row.cells[0].text = key
87
- row.cells[1].text = value
88
  doc.add_paragraph(f"Date: {date}")
89
 
90
  # SLOs
91
  p = doc.add_paragraph("\nSLOs (Student Learning Outcomes)")
92
  p.runs[0].bold = True
93
- for s in slos:
94
- doc.add_paragraph(f"- {s}")
95
 
96
  # Content
97
  p = doc.add_paragraph("\nContent to be Delivered")
98
  p.runs[0].bold = True
99
  doc.add_paragraph(content)
100
 
101
- # Home Assignment
102
- p = doc.add_paragraph("\nHome Assignment")
103
  p.runs[0].bold = True
104
  doc.add_paragraph(assignment)
105
 
106
- # Feedback
107
  p = doc.add_paragraph("\nFeedback by the Mentor/Principal")
108
  p.runs[0].bold = True
109
- doc.add_paragraph("_________________________________________________________")
110
- doc.add_paragraph("_________________________________________________________")
111
- doc.add_paragraph("_________________________________________________________")
112
 
113
  # Footer
114
  section = doc.sections[0]
@@ -120,16 +123,16 @@ def generate_lesson_plan(grade, subject, topic, num_students, duration, teacher_
120
  return file_path
121
 
122
  else:
123
- file_path = os.path.join(output_dir, "SMART_Lesson_Plan_Urdu.docx")
124
  doc = Document()
125
 
126
  # Header
127
  header = doc.add_paragraph("School Education Department, Gilgit-Baltistan")
128
  header.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
129
  run = header.runs[0]
130
- run.font.color.rgb = RGBColor(0, 128, 0)
131
- run.bold = True
132
  run.font.size = Pt(14)
 
 
133
 
134
  # Title
135
  title = doc.add_paragraph("اسمارٹ لیسن پلان")
@@ -137,47 +140,48 @@ def generate_lesson_plan(grade, subject, topic, num_students, duration, teacher_
137
  title.runs[0].bold = True
138
  title.runs[0].font.size = Pt(16)
139
 
140
- # Table for details
141
  table = doc.add_table(rows=6, cols=2)
142
- details = [
143
- ("درجہ:", grade),
144
- ("مضمون:", subject),
145
- ("موضوع:", topic),
146
- ("طلباء کی تعداد:", str(num_students)),
147
- ("دورانیہ:", duration),
148
- ("استاد کا نام:", teacher_name or ""),
149
  ]
150
- for i, (key, value) in enumerate(details):
151
- row = table.rows[i]
152
- row.cells[0].text = key
153
- row.cells[1].text = value
154
- doc.add_paragraph(f"تاریخ: {date}")
155
 
156
  # SLOs
157
  p = doc.add_paragraph("\nتعلیمی مقاصد (SLOs)")
158
- p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
159
  p.runs[0].bold = True
 
160
  for s in slos:
161
  doc.add_paragraph(s).alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
162
 
163
  # Content
164
  p = doc.add_paragraph("\nپڑھائے جانے والا مواد")
165
- p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
166
  p.runs[0].bold = True
 
167
  doc.add_paragraph(content).alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
168
 
169
  # Assignment
170
- p = doc.add_paragraph("\nگھریلو مشق")
171
- p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
172
  p.runs[0].bold = True
 
173
  doc.add_paragraph(assignment).alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
174
 
175
- # Feedback
176
  p = doc.add_paragraph("\nمینٹر / پرنسپل کی رائے")
177
- p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
178
  p.runs[0].bold = True
 
179
  for _ in range(3):
180
- doc.add_paragraph("___________________________________________").alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
 
 
181
 
182
  # Footer
183
  section = doc.sections[0]
@@ -189,16 +193,13 @@ def generate_lesson_plan(grade, subject, topic, num_students, duration, teacher_
189
  return file_path
190
 
191
 
192
- # ✅ Gradio UI
193
  def build_ui():
194
  with gr.Blocks(title="SMART Lesson Plan Generator") as demo:
195
  gr.Markdown("### 🧠 **SMART Lesson Plan Generator** \nDeveloped by **Najaf Ali Sharqi**")
196
 
197
  with gr.Row():
198
- grade = gr.Dropdown(
199
- [f"Grade {i}" for i in range(1, 13)],
200
- label="Select Grade"
201
- )
202
  subject = gr.Dropdown(
203
  [
204
  "Urdu", "English", "Mathematics", "Science", "Physics", "Chemistry",
@@ -208,7 +209,7 @@ def build_ui():
208
  label="Select Subject"
209
  )
210
 
211
- topic = gr.Textbox(label="Enter Topic", placeholder="e.g., Photosynthesis, Ionic Bond, or Fractions")
212
  num_students = gr.Number(label="Number of Students", value=30)
213
  duration = gr.Textbox(label="Duration", placeholder="e.g., 40 minutes")
214
  teacher_name = gr.Textbox(label="Teacher Name", placeholder="Enter your name")
@@ -216,7 +217,7 @@ def build_ui():
216
  language = gr.Dropdown(["English", "Urdu"], label="Select Language Version")
217
 
218
  generate_btn = gr.Button("Generate Lesson Plan")
219
- output_file = gr.File(label="Download Your Lesson Plan")
220
 
221
  generate_btn.click(
222
  generate_lesson_plan,
 
1
  import gradio as gr
2
  from docx import Document
3
+ from docx.shared import Pt, RGBColor, Inches
4
  from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
 
5
  from datetime import datetime
6
+ import os
7
 
8
+ # ✅ Auto-generate SLOs, content, and assignment
9
  def auto_generate_sections(topic, subject, language):
 
10
  if language == "English":
11
  slos = [
12
+ f"Define the main concept of {topic}.",
13
+ f"Explain how {topic} occurs or functions in daily life.",
14
+ f"Apply the concept of {topic} to solve given examples or exercises."
15
  ]
16
+
17
  content = (
18
+ f"1. Begin the lesson by introducing the term '{topic}' with simple examples from everyday life.\n"
19
+ f"2. Ask students to recall where they have observed {topic} in their surroundings.\n"
20
+ f"3. Use diagrams, models, or demonstrations to explain the process of {topic}.\n"
21
+ f"4. Discuss each SLO step-by-step, ensuring conceptual clarity.\n"
22
+ f"5. Engage students through questioning and short activities to check understanding."
23
  )
24
+
25
  assignment = (
26
+ f"Students will write short notes on {topic} in their notebooks and give two real-life examples. "
27
+ f"They will also prepare a short oral explanation of {topic} for the next class."
28
  )
29
 
 
30
  else:
31
  slos = [
32
+ f"١۔ {topic} کے بنیادی تصور کی وضاحت کریں۔",
33
+ f"٢۔ وضاحت کریں کہ {topic} روزمرہ زندگی میں کیسے واقع ہوتا ہے۔",
34
+ f"٣۔ {topic} کے تصور کو مثالوں کے ذریعے لاگو کریں۔"
35
  ]
36
+
37
  content = (
38
+ f"١۔ سبق کا آغاز {topic} کے تعارف سے کریں اور روزمرہ زندگی کی آسان مثالیں دیں۔\n"
39
+ f"٢۔ طلباء سے دریافت کریں کہ انہوں نے {topic} کو اپنی زندگی میں کہاں دیکھا یا سنا ہے۔\n"
40
+ f"٣۔ چارٹ، ماڈل یا تصویروں کے ذریعے {topic} کا عمل سمجھائیں۔\n"
41
+ f"٤۔ ہر SLO کو مرحلہ وار واضح کریں تاکہ طلباء کو مکمل فہم حاصل ہو۔\n"
42
+ f"٥۔ سوال و جواب اور مختصر سرگرمیوں کے ذریعے طلباء کی سمجھ کو جانچیں۔"
43
  )
44
+
45
  assignment = (
46
+ f"طلباء {topic} پر مختصر نوٹس لکھیں گے اور روزمرہ زندگی سے دو مثالیں پیش کریں گے۔ "
47
+ f"اگلی کلاس کے لیے {topic} کی زبانی وضاحت تیار کریں گے۔"
48
  )
49
 
50
  return slos, content, assignment
51
 
52
 
53
+ # ✅ Generate Lesson Plan Function
54
  def generate_lesson_plan(grade, subject, topic, num_students, duration, teacher_name, date, language):
55
 
56
+ os.makedirs("/tmp", exist_ok=True)
 
 
57
 
 
58
  slos, content, assignment = auto_generate_sections(topic, subject, language)
59
 
60
  if language == "English":
61
+ file_path = "/tmp/SMART_Lesson_Plan_English.docx"
62
  doc = Document()
63
 
64
  # Header
65
  header = doc.add_paragraph("School Education Department, Gilgit-Baltistan")
66
  header.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
67
  run = header.runs[0]
 
 
68
  run.font.size = Pt(14)
69
+ run.bold = True
70
+ run.font.color.rgb = RGBColor(0, 128, 0)
71
 
72
  # Title
73
  title = doc.add_paragraph("SMART LESSON PLAN")
 
75
  title.runs[0].bold = True
76
  title.runs[0].font.size = Pt(16)
77
 
78
+ # Input table
79
+ doc.add_paragraph()
80
  table = doc.add_table(rows=6, cols=2)
81
+ data = [
82
+ ("Grade Level", grade),
83
+ ("Subject", subject),
84
+ ("Topic", topic),
85
+ ("Number of Students", str(num_students)),
86
+ ("Duration", duration),
87
+ ("Teacher Name", teacher_name or "")
88
  ]
89
+ for i, (key, val) in enumerate(data):
90
+ table.rows[i].cells[0].text = key
91
+ table.rows[i].cells[1].text = val
 
92
  doc.add_paragraph(f"Date: {date}")
93
 
94
  # SLOs
95
  p = doc.add_paragraph("\nSLOs (Student Learning Outcomes)")
96
  p.runs[0].bold = True
97
+ for i, s in enumerate(slos, 1):
98
+ doc.add_paragraph(f"{i}. {s}")
99
 
100
  # Content
101
  p = doc.add_paragraph("\nContent to be Delivered")
102
  p.runs[0].bold = True
103
  doc.add_paragraph(content)
104
 
105
+ # Assignment
106
+ p = doc.add_paragraph("\nHome Assignment (Optional)")
107
  p.runs[0].bold = True
108
  doc.add_paragraph(assignment)
109
 
110
+ # Feedback Section
111
  p = doc.add_paragraph("\nFeedback by the Mentor/Principal")
112
  p.runs[0].bold = True
113
+ for _ in range(3):
114
+ doc.add_paragraph("______________________________________________________________")
 
115
 
116
  # Footer
117
  section = doc.sections[0]
 
123
  return file_path
124
 
125
  else:
126
+ file_path = "/tmp/SMART_Lesson_Plan_Urdu.docx"
127
  doc = Document()
128
 
129
  # Header
130
  header = doc.add_paragraph("School Education Department, Gilgit-Baltistan")
131
  header.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
132
  run = header.runs[0]
 
 
133
  run.font.size = Pt(14)
134
+ run.bold = True
135
+ run.font.color.rgb = RGBColor(0, 128, 0)
136
 
137
  # Title
138
  title = doc.add_paragraph("اسمارٹ لیسن پلان")
 
140
  title.runs[0].bold = True
141
  title.runs[0].font.size = Pt(16)
142
 
143
+ # Input table aligned right
144
  table = doc.add_table(rows=6, cols=2)
145
+ data = [
146
+ ("درجہ", grade),
147
+ ("مضمون", subject),
148
+ ("موضوع", topic),
149
+ ("طلباء کی تعداد", str(num_students)),
150
+ ("دورانیہ", duration),
151
+ ("استاد کا نام", teacher_name or "")
152
  ]
153
+ for i, (key, val) in enumerate(data):
154
+ table.rows[i].cells[0].text = key
155
+ table.rows[i].cells[1].text = val
156
+ doc.add_paragraph(f"تاریخ: {date}").alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
 
157
 
158
  # SLOs
159
  p = doc.add_paragraph("\nتعلیمی مقاصد (SLOs)")
 
160
  p.runs[0].bold = True
161
+ p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
162
  for s in slos:
163
  doc.add_paragraph(s).alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
164
 
165
  # Content
166
  p = doc.add_paragraph("\nپڑھائے جانے والا مواد")
 
167
  p.runs[0].bold = True
168
+ p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
169
  doc.add_paragraph(content).alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
170
 
171
  # Assignment
172
+ p = doc.add_paragraph("\nگھریلو مشق (اختیاری)")
 
173
  p.runs[0].bold = True
174
+ p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
175
  doc.add_paragraph(assignment).alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
176
 
177
+ # Feedback section (full-width lines)
178
  p = doc.add_paragraph("\nمینٹر / پرنسپل کی رائے")
 
179
  p.runs[0].bold = True
180
+ p.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
181
  for _ in range(3):
182
+ line = "_" * 90
183
+ para = doc.add_paragraph(line)
184
+ para.alignment = WD_PARAGRAPH_ALIGNMENT.RIGHT
185
 
186
  # Footer
187
  section = doc.sections[0]
 
193
  return file_path
194
 
195
 
196
+ # ✅ Build Gradio Interface
197
  def build_ui():
198
  with gr.Blocks(title="SMART Lesson Plan Generator") as demo:
199
  gr.Markdown("### 🧠 **SMART Lesson Plan Generator** \nDeveloped by **Najaf Ali Sharqi**")
200
 
201
  with gr.Row():
202
+ grade = gr.Dropdown([f"Grade {i}" for i in range(1, 13)], label="Select Grade")
 
 
 
203
  subject = gr.Dropdown(
204
  [
205
  "Urdu", "English", "Mathematics", "Science", "Physics", "Chemistry",
 
209
  label="Select Subject"
210
  )
211
 
212
+ topic = gr.Textbox(label="Enter Topic", placeholder="e.g., Ionic Bond, Photosynthesis, Fractions")
213
  num_students = gr.Number(label="Number of Students", value=30)
214
  duration = gr.Textbox(label="Duration", placeholder="e.g., 40 minutes")
215
  teacher_name = gr.Textbox(label="Teacher Name", placeholder="Enter your name")
 
217
  language = gr.Dropdown(["English", "Urdu"], label="Select Language Version")
218
 
219
  generate_btn = gr.Button("Generate Lesson Plan")
220
+ output_file = gr.File(label="Download Lesson Plan")
221
 
222
  generate_btn.click(
223
  generate_lesson_plan,