Turbiling commited on
Commit
fbef00b
·
verified ·
1 Parent(s): a0dad57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -54
app.py CHANGED
@@ -4,10 +4,10 @@ from datetime import datetime
4
  from docx.shared import Pt
5
 
6
  def generate_lesson_plan(language, grade, subject, topic, students, duration, teacher_name, date):
7
- # --------------------- ENGLISH VERSION ---------------------
8
  if language == "English":
 
9
  doc = Document()
10
-
11
  # Header
12
  section = doc.sections[0]
13
  header = section.header.paragraphs[0]
@@ -16,24 +16,29 @@ def generate_lesson_plan(language, grade, subject, topic, students, duration, te
16
 
17
  # Title
18
  doc.add_heading("SMART LESSON PLAN", level=1)
19
- doc.add_paragraph(f"Grade Level: {grade}")
20
- doc.add_paragraph(f"Subject: {subject}")
21
- doc.add_paragraph(f"Topic: {topic}")
22
- doc.add_paragraph(f"Number of Students: {students}")
23
- doc.add_paragraph(f"Duration: {duration}")
24
- doc.add_paragraph(f"Teacher Name: {teacher_name}")
25
- doc.add_paragraph(f"Date: {date}")
26
-
27
- # Content to be Delivered
28
- doc.add_heading("Content to be Delivered", level=2)
29
- doc.add_paragraph(
30
- "Explain the concept of Chemical Bonding by introducing ionic and covalent bonds. "
31
- "Use real-life examples such as sodium chloride and water molecules. "
32
- "Demonstrate bonding through molecular models and guide students to classify compounds. "
33
- "Encourage participation and conclude with a question-answer discussion."
34
- )
35
 
36
- # SLOs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  doc.add_heading("SLOs (Student Learning Outcomes)", level=2)
38
  doc.add_paragraph(
39
  "By the end of this lesson, students will be able to:\n"
@@ -42,82 +47,96 @@ def generate_lesson_plan(language, grade, subject, topic, students, duration, te
42
  "3. Predict the type of bond formed between given elements."
43
  )
44
 
45
- # Home Assignment
 
 
 
 
 
 
 
 
 
 
 
46
  doc.add_heading("Home Assignment", level=2)
47
  doc.add_paragraph(
48
- "1. Write short notes on types of chemical bonds.\n"
49
- "2. Draw Lewis structures for H₂O, CO₂, and NaCl.\n"
50
- "3. Explain how ionic and covalent bonds stabilize compounds.\n"
51
- "4. Align your responses with today’s SLOs."
52
  )
53
 
54
  # Feedback Section
55
  doc.add_heading("Feedback by the Mentor / Principal", level=2)
56
- doc.add_paragraph("\n" * 4) # Four blank lines for manual feedback
57
 
58
- # Footer (manual text for demonstration)
59
  footer = section.footer.paragraphs[0]
60
- footer.text = "Page 1 of 3"
61
- footer.alignment = 1 # center
62
 
63
- filename = "Lesson_Plan_English.docx"
64
  doc.save(filename)
65
  return filename
66
 
67
- # --------------------- URDU VERSION ---------------------
68
  else:
 
69
  content = f"""
70
  # سمارٹ سبق منصوبہ
71
 
72
- **کلاس:** {grade}
73
- **مضمون:** {subject}
74
- **موضوع:** {topic}
75
- **طلبہ کی تعداد:** {students}
76
- **دورانیہ:** {duration}
77
- **استاد کا نام:** {teacher_name}
78
- **تاریخ:** {date}
79
-
80
- ## مواد جو پڑھایا جائے گا
81
- کیمیائی بندش کے تصور کو سادہ مثالوں سے واضح کریں جیسے سوڈیم کلورائیڈ اور پانی کے سالمے۔ طلبہ کو گروپ سرگرمیوں کے ذریعے بندش کی اقسام پہچاننے کی ترغیب دیں۔ سبق کے آخر میں سوال و جواب کے ذریعے فہم کو جانچیں۔
82
 
83
  ## مقاصدِ سبق (SLOs)
84
- 1. طلبہ آئنک اور کوویلنٹ بندش میں فرق بیان کریں۔
 
85
  2. دونوں اقسام کی مثالیں پیش کریں۔
86
- 3. مختلف عناصر کے ملاپ سے بندش کی نوعیت بتائیں۔
 
 
 
87
 
88
  ## گھریلو کام
89
- 1. بندش کی اقسام پر مختصر نوٹ لکھیں۔
90
- 2. درج ذیل مرکبات کے لیوس اسٹرکچر بنائیں: H₂O، CO₂، NaCl۔
91
- 3. وضاحت کریں کہ آئنک اور کوویلنٹ بندش کس طرح مرکب کے استحکام میں مدد دیتی ہیں۔
92
 
93
- ## رائے برائے رہنمائی / پرنسپل کی طرف سے
94
- (چار سطور خالی جگہ برائے رائے)
95
 
96
  """
97
- filename = "Lesson_Plan_Urdu.md"
98
  with open(filename, "w", encoding="utf-8") as f:
99
  f.write(content)
100
  return filename
101
 
102
 
103
- # --------- Gradio UI ------------
104
  with gr.Blocks(theme="soft") as app:
105
- gr.Markdown("## SMART Lesson Plan Generator\nDeveloped by **Najaf Ali Sharqi**")
106
-
107
  with gr.Row():
108
  language = gr.Dropdown(["English", "Urdu"], label="Select Language")
109
  grade = gr.Dropdown([str(i) for i in range(1, 13)], label="Grade Level")
110
  subject = gr.Dropdown(["Chemistry", "Physics", "Biology", "Mathematics", "Urdu", "English"], label="Subject")
111
-
112
  topic = gr.Textbox(label="Topic")
113
  students = gr.Number(label="Number of Students", value=30)
114
  duration = gr.Dropdown(["30 minutes", "40 minutes", "45 minutes", "60 minutes"], label="Duration")
115
  teacher_name = gr.Textbox(label="Teacher Name")
116
  date = gr.Textbox(label="Date (YYYY-MM-DD)", value=str(datetime.now().date()))
117
-
118
  output = gr.File(label="Download Lesson Plan")
119
  generate_btn = gr.Button("Generate Lesson Plan")
120
-
121
  generate_btn.click(
122
  generate_lesson_plan,
123
  inputs=[language, grade, subject, topic, students, duration, teacher_name, date],
@@ -125,3 +144,6 @@ with gr.Blocks(theme="soft") as app:
125
  )
126
 
127
  app.launch()
 
 
 
 
4
  from docx.shared import Pt
5
 
6
  def generate_lesson_plan(language, grade, subject, topic, students, duration, teacher_name, date):
 
7
  if language == "English":
8
+ # ---------------- ENGLISH VERSION (.docx) ----------------
9
  doc = Document()
10
+
11
  # Header
12
  section = doc.sections[0]
13
  header = section.header.paragraphs[0]
 
16
 
17
  # Title
18
  doc.add_heading("SMART LESSON PLAN", level=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ # Input Table
21
+ table = doc.add_table(rows=7, cols=2)
22
+ table.style = 'Table Grid'
23
+ inputs = [
24
+ ("Grade Level", grade),
25
+ ("Subject", subject),
26
+ ("Topic", topic),
27
+ ("Number of Students", str(students)),
28
+ ("Duration", duration),
29
+ ("Teacher Name", teacher_name),
30
+ ("Date", date)
31
+ ]
32
+
33
+ for i, (label, value) in enumerate(inputs):
34
+ row_cells = table.rows[i].cells
35
+ row_cells[0].text = f"{label}:"
36
+ row_cells[1].text = value
37
+
38
+ # Add some space after the table
39
+ doc.add_paragraph("\n")
40
+
41
+ # SLOs Section
42
  doc.add_heading("SLOs (Student Learning Outcomes)", level=2)
43
  doc.add_paragraph(
44
  "By the end of this lesson, students will be able to:\n"
 
47
  "3. Predict the type of bond formed between given elements."
48
  )
49
 
50
+ # Content Section
51
+ doc.add_heading("Content to be Delivered", level=2)
52
+ doc.add_paragraph(
53
+ "Chemical bonding refers to the force that holds atoms together to form compounds. "
54
+ "In ionic bonding, atoms transfer electrons to achieve stability, forming positive and negative ions "
55
+ "that attract each other — for example, sodium and chlorine in NaCl. "
56
+ "In covalent bonding, atoms share electrons, as seen in H₂O. "
57
+ "This lesson includes diagrams, examples, and interactive activities to help students understand "
58
+ "how bonds form and why they are essential for compound stability."
59
+ )
60
+
61
+ # Home Assignment Section
62
  doc.add_heading("Home Assignment", level=2)
63
  doc.add_paragraph(
64
+ "1. Draw and label the diagram of an ionic bond between sodium and chlorine.\n"
65
+ "2. Write a short paragraph explaining how covalent bonds differ from ionic bonds.\n"
66
+ "3. Provide two examples each of ionic and covalent compounds and describe their uses.\n"
67
+ "4. Submit your assignment within 24 hours."
68
  )
69
 
70
  # Feedback Section
71
  doc.add_heading("Feedback by the Mentor / Principal", level=2)
72
+ doc.add_paragraph("\n\n\n\n") # Four blank lines for handwritten feedback
73
 
74
+ # Footer
75
  footer = section.footer.paragraphs[0]
76
+ footer.text = "School Education Department, Gilgit-Baltistan | Page 1 of 3"
77
+ footer.alignment = 1 # Center alignment
78
 
79
+ filename = f"Lesson_Plan_{subject}_{topic}_{date}.docx"
80
  doc.save(filename)
81
  return filename
82
 
 
83
  else:
84
+ # ---------------- URDU VERSION (.md) ----------------
85
  content = f"""
86
  # سمارٹ سبق منصوبہ
87
 
88
+ | فیلڈ | تفصیل |
89
+ |-------|--------|
90
+ | جماعت | {grade} |
91
+ | مضمون | {subject} |
92
+ | موضوع | {topic} |
93
+ | طلبہ کی تعداد | {students} |
94
+ | دورانیہ | {duration} |
95
+ | استاد کا نام | {teacher_name} |
96
+ | تاریخ | {date} |
 
97
 
98
  ## مقاصدِ سبق (SLOs)
99
+ سبق کے اختتام پر طلبہ قابل ہوں گے کہ:
100
+ 1. آئنک اور کوویلنٹ بندش کی تعریف کریں۔
101
  2. دونوں اقسام کی مثالیں پیش کریں۔
102
+ 3. دیے گئے عناصر کے درمیان بندش کی نوعیت بتائیں۔
103
+
104
+ ## مواد جو پڑھایا جائے گا
105
+ کیمیائی بندش وہ قوت ہے جو ایٹموں کو ایک ساتھ رکھتی ہے۔ آئنک بندش میں الیکٹرانوں کا تبادلہ ہوتا ہے جبکہ کوویلنٹ بندش میں ایٹم الیکٹرانوں کو بانٹتے ہیں۔ یہ سبق مثالوں، خاکوں اور عملی سرگرمیوں کے ذریعے طلبہ کو سمجھایا جائے گا تاکہ وہ بندش کی اقسام کو پہچان سکیں۔
106
 
107
  ## گھریلو کام
108
+ 1. سوڈیم اور کلورین کے درمیان آئنک بندش کا خاکہ بنائیں۔
109
+ 2. آئنک اور کوویلنٹ بندش کے فرق کو تین جملوں میں بیان کریں۔
110
+ 3. دونوں اقسام کے دو دو مرکبات کی مثالیں لکھیں اور ان کے استعمال بتائیں۔
111
 
112
+ ## رائے برائے رہنمائی / پرنسپل
113
+ (چار سطور خالی برائے تحریری رائے)
114
 
115
  """
116
+ filename = f"Lesson_Plan_{subject}_{topic}_{date}.md"
117
  with open(filename, "w", encoding="utf-8") as f:
118
  f.write(content)
119
  return filename
120
 
121
 
122
+ # ----------- GRADIO APP UI --------------
123
  with gr.Blocks(theme="soft") as app:
124
+ gr.Markdown("# SMART Lesson Plan Generator\nDeveloped by Najaf Ali Sharqi")
125
+
126
  with gr.Row():
127
  language = gr.Dropdown(["English", "Urdu"], label="Select Language")
128
  grade = gr.Dropdown([str(i) for i in range(1, 13)], label="Grade Level")
129
  subject = gr.Dropdown(["Chemistry", "Physics", "Biology", "Mathematics", "Urdu", "English"], label="Subject")
130
+
131
  topic = gr.Textbox(label="Topic")
132
  students = gr.Number(label="Number of Students", value=30)
133
  duration = gr.Dropdown(["30 minutes", "40 minutes", "45 minutes", "60 minutes"], label="Duration")
134
  teacher_name = gr.Textbox(label="Teacher Name")
135
  date = gr.Textbox(label="Date (YYYY-MM-DD)", value=str(datetime.now().date()))
136
+
137
  output = gr.File(label="Download Lesson Plan")
138
  generate_btn = gr.Button("Generate Lesson Plan")
139
+
140
  generate_btn.click(
141
  generate_lesson_plan,
142
  inputs=[language, grade, subject, topic, students, duration, teacher_name, date],
 
144
  )
145
 
146
  app.launch()
147
+
148
+
149
+