Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,318 +1,301 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from groq import Groq
|
| 4 |
-
from datetime import datetime
|
| 5 |
-
from docx import Document
|
| 6 |
-
from docx.shared import Pt, RGBColor
|
| 7 |
-
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
| 8 |
-
import re
|
| 9 |
import random
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# Grades and subjects
|
| 16 |
-
grades = [f"Grade {i}" for i in range(1, 13)]
|
| 17 |
-
subjects_by_grade = {
|
| 18 |
-
"Grade 1": ["Mathematics", "English", "Urdu", "Islamiyat", "General Knowledge"],
|
| 19 |
-
"Grade 2": ["Mathematics", "English", "Urdu", "Islamiyat", "General Knowledge"],
|
| 20 |
-
"Grade 3": ["Mathematics", "English", "Urdu", "Science", "Islamiyat", "General Knowledge"],
|
| 21 |
-
"Grade 4": ["Mathematics", "English", "Urdu", "Science", "Islamiyat", "General Knowledge"],
|
| 22 |
-
"Grade 5": ["Mathematics", "English", "Urdu", "Science", "Islamiyat", "Social Studies"],
|
| 23 |
-
"Grade 6": ["Mathematics", "English", "Urdu", "Science", "Islamiyat", "Social Studies"],
|
| 24 |
-
"Grade 7": ["Mathematics", "English", "Urdu", "Science", "Islamiyat", "Social Studies", "Computer"],
|
| 25 |
-
"Grade 8": ["Mathematics", "English", "Urdu", "Science", "Islamiyat", "Social Studies", "Computer"],
|
| 26 |
-
"Grade 9": ["Mathematics", "English", "Urdu", "Biology", "Chemistry", "Physics", "Islamiyat", "Pakistan Studies"],
|
| 27 |
-
"Grade 10": ["Mathematics", "English", "Urdu", "Biology", "Chemistry", "Physics", "Islamiyat", "Pakistan Studies"],
|
| 28 |
-
"Grade 11": ["Mathematics", "English", "Urdu", "Biology", "Chemistry", "Physics", "Computer", "Islamiyat", "Pakistan Studies"],
|
| 29 |
-
"Grade 12": ["Mathematics", "English", "Urdu", "Biology", "Chemistry", "Physics", "Computer", "Islamiyat", "Pakistan Studies"]
|
| 30 |
-
}
|
| 31 |
|
| 32 |
-
|
| 33 |
-
# For Grades 9 & 10, I used the exact chapters you supplied for Biology, Chemistry, Physics, Pakistan Studies.
|
| 34 |
-
chapters_by_subject_and_grade = {
|
| 35 |
-
"Grade 1": {
|
| 36 |
-
"Mathematics": ["Counting & Numbers", "Basic Addition", "Basic Subtraction", "Shapes", "Measurements"],
|
| 37 |
-
"English": ["Alphabet & Sounds", "Basic Words", "Simple Sentences", "Listening & Speaking", "Reading Short Texts"],
|
| 38 |
-
"Urdu": ["حروف", "الفاظ", "سادہ جملے", "پڑھنا", "لکھنا"],
|
| 39 |
-
"Islamiyat": ["Basic Beliefs", "Prophets Stories", "Good Manners", "Prayers & Worship"],
|
| 40 |
-
"General Knowledge": ["My Body", "My Home", "My School", "Seasons"]
|
| 41 |
-
},
|
| 42 |
-
"Grade 2": {
|
| 43 |
-
"Mathematics": ["Place Value", "Addition & Subtraction", "Money", "Time", "Shapes"],
|
| 44 |
-
"English": ["Parts of Speech Basics", "Simple Grammar", "Short Comprehension", "Vocabulary Building"],
|
| 45 |
-
"Urdu": ["الفاظ و جملے", "مختصر کہانیاں", "حروفِ صحیح"],
|
| 46 |
-
"Islamiyat": ["Prophets", "Good Deeds", "Mosque Etiquette"],
|
| 47 |
-
"General Knowledge": ["Plants & Animals", "Local Community", "Transport"]
|
| 48 |
-
},
|
| 49 |
-
"Grade 3": {
|
| 50 |
-
"Mathematics": ["Multiplication", "Division", "Fractions", "Geometry Basics", "Measurement"],
|
| 51 |
-
"English": ["Tenses (simple)", "Comprehension Passages", "Vocabulary", "Sentence Formation"],
|
| 52 |
-
"Urdu": ["کالم و مضامین", "قواعدِ اردو", "کہانیاں"],
|
| 53 |
-
"Science": ["Plants", "Animals", "Human Body", "Materials"],
|
| 54 |
-
"Islamiyat": ["Basics of Iman", "Seerat", "Manners"]
|
| 55 |
-
},
|
| 56 |
-
"Grade 4": {
|
| 57 |
-
"Mathematics": ["Fractions & Decimals", "Geometry", "Data Handling", "Word Problems"],
|
| 58 |
-
"English": ["Grammar (intermediate)", "Comprehension", "Writing Short Paragraphs"],
|
| 59 |
-
"Urdu": ["نظم و نثر", "قواعد", "مفردات"],
|
| 60 |
-
"Science": ["Ecosystems", "Forces", "Heat & Energy"],
|
| 61 |
-
"Islamiyat": ["Pillars of Islam", "Seerah Stories"]
|
| 62 |
-
},
|
| 63 |
-
"Grade 5": {
|
| 64 |
-
"Mathematics": ["Numbers & Operations", "Geometry", "Statistics", "Ratio & Proportion"],
|
| 65 |
-
"English": ["Advanced Grammar Basics", "Paragraph Writing", "Comprehension"],
|
| 66 |
-
"Urdu": ["ادبی مطالعہ", "تعبیر و تشریح"],
|
| 67 |
-
"Science": ["Cells & Life", "Matter", "Energy"],
|
| 68 |
-
"Islamiyat": ["Quranic Stories", "Akhlq"]
|
| 69 |
-
},
|
| 70 |
-
"Grade 6": {
|
| 71 |
-
"Mathematics": ["Number System", "Algebra Introduction", "Geometry", "Data Handling"],
|
| 72 |
-
"English": ["Grammar (complex)", "Essay Writing", "Comprehension Skills"],
|
| 73 |
-
"Urdu": ["ادب و نحو", "تحریر"],
|
| 74 |
-
"Science": ["Atoms & Molecules", "Human Body", "Plants"],
|
| 75 |
-
"Islamiyat": ["Seerah & Ahkam"]
|
| 76 |
-
},
|
| 77 |
-
"Grade 7": {
|
| 78 |
-
"Mathematics": ["Algebra", "Geometry", "Mensuration", "Statistics"],
|
| 79 |
-
"English": ["Poetry & Prose", "Grammar", "Comprehension"],
|
| 80 |
-
"Urdu": ["نثر و شاعری", "قواعد"],
|
| 81 |
-
"Science": ["Cell Biology", "Human Systems", "Electricity Basics"],
|
| 82 |
-
"Islamiyat": ["Islamic History", "Moral Teachings"],
|
| 83 |
-
"Social Studies": ["Geography Basics", "History", "Civics"],
|
| 84 |
-
"Computer": ["Basic ICT", "Computer Hardware", "Introduction to Coding"]
|
| 85 |
-
},
|
| 86 |
-
"Grade 8": {
|
| 87 |
-
"Mathematics": ["Linear Equations", "Geometry", "Pythagoras", "Graphs"],
|
| 88 |
-
"English": ["Advanced Comprehension", "Composition", "Grammar"],
|
| 89 |
-
"Urdu": ["تجزیہ ادب", "تحقیقِ مختصر"],
|
| 90 |
-
"Science": ["Forces & Motion", "Heat", "Waves Basics"],
|
| 91 |
-
"Islamiyat": ["Islamic Law Basics", "Seerah"],
|
| 92 |
-
"Social Studies": ["Regional Geography", "Historical Events"],
|
| 93 |
-
"Computer": ["Algorithms", "Basic Programming"]
|
| 94 |
-
},
|
| 95 |
"Grade 9": {
|
| 96 |
-
"Mathematics": ["Number Systems & Algebra", "Coordinate Geometry", "Trigonometry", "Graphs"],
|
| 97 |
-
"English": ["Advanced Grammar", "Comprehension", "Writing Skills"],
|
| 98 |
-
"Urdu": ["ادب اور نثر", "نظم", "مضامین"],
|
| 99 |
"Biology": [
|
| 100 |
-
"
|
| 101 |
-
"
|
| 102 |
-
"
|
| 103 |
-
"
|
| 104 |
-
"
|
| 105 |
-
"
|
| 106 |
-
"
|
| 107 |
-
"
|
| 108 |
-
"
|
| 109 |
],
|
| 110 |
"Chemistry": [
|
| 111 |
-
"
|
| 112 |
-
"
|
| 113 |
-
"
|
| 114 |
-
"
|
| 115 |
-
"
|
| 116 |
-
"
|
| 117 |
-
"
|
| 118 |
-
"
|
| 119 |
],
|
| 120 |
"Physics": [
|
| 121 |
-
"
|
| 122 |
-
"
|
| 123 |
-
"
|
| 124 |
"Turning Effect of Forces",
|
| 125 |
-
"
|
| 126 |
-
"
|
| 127 |
-
"
|
| 128 |
-
"
|
| 129 |
-
"
|
| 130 |
],
|
| 131 |
-
"Islamiyat": ["Seerat of Prophet", "Faith & Beliefs", "Worship Practices"],
|
| 132 |
"Pakistan Studies": [
|
| 133 |
-
"
|
| 134 |
-
"
|
| 135 |
-
"
|
| 136 |
-
"
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
},
|
|
|
|
| 139 |
"Grade 10": {
|
| 140 |
-
"Mathematics": ["Advanced Algebra", "Trigonometry", "Geometry", "Probability"],
|
| 141 |
-
"English": ["Literature", "Advanced Composition", "Comprehension"],
|
| 142 |
-
"Urdu": ["ادبِ جدید", "تحقیقی مضمون"],
|
| 143 |
"Biology": [
|
| 144 |
-
"
|
| 145 |
-
"
|
| 146 |
-
"
|
| 147 |
-
"
|
| 148 |
-
"
|
| 149 |
-
"
|
| 150 |
-
"
|
| 151 |
-
"
|
| 152 |
-
"
|
| 153 |
],
|
| 154 |
"Chemistry": [
|
| 155 |
-
"
|
| 156 |
-
"
|
| 157 |
-
"
|
| 158 |
-
"
|
| 159 |
-
"
|
| 160 |
-
"
|
| 161 |
-
"ENVIRONMENTAL CHEMISTRY II: WATER",
|
| 162 |
-
"CHEMICAL INDUSTRIES"
|
| 163 |
],
|
| 164 |
"Physics": [
|
| 165 |
-
"
|
| 166 |
-
"
|
| 167 |
-
"
|
| 168 |
-
"
|
| 169 |
-
"
|
| 170 |
-
"
|
| 171 |
-
"
|
| 172 |
-
"
|
| 173 |
-
"RADIOACTIVITY"
|
| 174 |
],
|
| 175 |
-
"Islamiyat": ["Islamic Studies II", "Ethics & Society", "Fiqh Basics"],
|
| 176 |
"Pakistan Studies": [
|
| 177 |
-
"
|
| 178 |
-
"
|
| 179 |
-
"
|
| 180 |
-
"
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
"
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
"
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
}
|
| 205 |
}
|
| 206 |
|
| 207 |
-
|
|
|
|
|
|
|
| 208 |
|
| 209 |
-
def generate_mcqs(grade, subject, chapter):
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
-
text = response.choices[0].message.content
|
| 223 |
-
mcqs = re.split(r'\n?\d+\.', text)
|
| 224 |
-
mcqs = [q.strip() for q in mcqs if q.strip()]
|
| 225 |
-
|
| 226 |
-
# Random answer key for demo
|
| 227 |
-
answer_key = [random.choice(["A","B","C","D"]) for _ in mcqs]
|
| 228 |
-
|
| 229 |
-
return mcqs[:20], answer_key[:20]
|
| 230 |
-
|
| 231 |
-
def export_to_word(mcqs, answers, grade, subject, chapter):
|
| 232 |
-
doc = Document()
|
| 233 |
-
|
| 234 |
-
# Heading
|
| 235 |
-
heading = doc.add_heading("WEEKLY/MONTHLY TEST", level=1)
|
| 236 |
-
heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 237 |
-
run = heading.runs[0]
|
| 238 |
-
run.bold = True
|
| 239 |
-
run.font.color.rgb = RGBColor(0, 128, 0)
|
| 240 |
-
run.font.size = Pt(18)
|
| 241 |
-
|
| 242 |
-
# Info table
|
| 243 |
-
table = doc.add_table(rows=5, cols=2)
|
| 244 |
-
table.style = 'Table Grid'
|
| 245 |
-
info = [
|
| 246 |
-
("Grade", grade),
|
| 247 |
-
("Subject", subject),
|
| 248 |
-
("Chapter", chapter),
|
| 249 |
-
("Date", datetime.now().strftime("%d-%m-%Y")),
|
| 250 |
-
("Medium", "English")
|
| 251 |
-
]
|
| 252 |
-
for row, (label, value) in zip(table.rows, info):
|
| 253 |
-
row.cells[0].text = label
|
| 254 |
-
row.cells[1].text = value
|
| 255 |
-
row.cells[0].paragraphs[0].runs[0].bold = True
|
| 256 |
-
|
| 257 |
-
# Add MCQs
|
| 258 |
-
for i, q in enumerate(mcqs, start=1):
|
| 259 |
-
p = doc.add_paragraph(f"{i}. {q}")
|
| 260 |
-
p.alignment = WD_ALIGN_PARAGRAPH.LEFT
|
| 261 |
-
|
| 262 |
-
# Answer key table
|
| 263 |
-
doc.add_paragraph("\nAnswer Key:")
|
| 264 |
-
ans_table = doc.add_table(rows=21, cols=5)
|
| 265 |
-
ans_table.style = 'Table Grid'
|
| 266 |
-
headers = ["Q#", "A", "B", "C", "D"]
|
| 267 |
-
for idx, text in enumerate(headers):
|
| 268 |
-
ans_table.cell(0, idx).text = text
|
| 269 |
-
ans_table.cell(0, idx).paragraphs[0].runs[0].bold = True
|
| 270 |
-
|
| 271 |
-
for r, ans in enumerate(answers, start=1):
|
| 272 |
-
ans_table.cell(r,0).text = str(r)
|
| 273 |
-
for c, option in enumerate(["A","B","C","D"], start=1):
|
| 274 |
-
ans_table.cell(r,c).text = "✔" if ans==option else ""
|
| 275 |
-
|
| 276 |
-
safe_chapter = re.sub(r'[\\/*?:"<>|]', "_", chapter)
|
| 277 |
-
file_path = f"{grade}_{subject}_{safe_chapter}_{datetime.now().strftime('%Y%m%d_%H%M%S')}.docx"
|
| 278 |
-
doc.save(file_path)
|
| 279 |
-
return file_path
|
| 280 |
-
|
| 281 |
-
def on_generate(grade, subject, chapter):
|
| 282 |
-
mcqs, answers = generate_mcqs(grade, subject, chapter)
|
| 283 |
-
file_path = export_to_word(mcqs, answers, grade, subject, chapter)
|
| 284 |
-
return f"Test ready: {file_path}", file_path
|
| 285 |
-
|
| 286 |
-
# Gradio UI
|
| 287 |
-
with gr.Blocks() as demo:
|
| 288 |
-
gr.Markdown("### **MCQ Test Generator - Developer: Najaf Ali Sharqi**")
|
| 289 |
with gr.Row():
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
)
|
| 317 |
|
| 318 |
-
demo.launch(
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import random
|
| 3 |
|
| 4 |
+
# ---------------------------------------------------------
|
| 5 |
+
# SUBJECTS + CHAPTERS (Existing + Newly Added)
|
| 6 |
+
# ---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
curriculum = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"Grade 9": {
|
|
|
|
|
|
|
|
|
|
| 10 |
"Biology": [
|
| 11 |
+
"Introduction to Biology",
|
| 12 |
+
"Solving a Biological Problem",
|
| 13 |
+
"Biodiversity",
|
| 14 |
+
"Cells and Tissues",
|
| 15 |
+
"Cell Cycle",
|
| 16 |
+
"Enzymes",
|
| 17 |
+
"Bioenergetics",
|
| 18 |
+
"Nutrition",
|
| 19 |
+
"Transport"
|
| 20 |
],
|
| 21 |
"Chemistry": [
|
| 22 |
+
"Fundamentals of Chemistry",
|
| 23 |
+
"Structure of Atoms",
|
| 24 |
+
"Periodic Table",
|
| 25 |
+
"Structure of Molecules",
|
| 26 |
+
"Physical States of Matter",
|
| 27 |
+
"Solutions",
|
| 28 |
+
"Electrochemistry",
|
| 29 |
+
"Chemical Reactivity"
|
| 30 |
],
|
| 31 |
"Physics": [
|
| 32 |
+
"Physical Quantities & Measurement",
|
| 33 |
+
"Kinematics",
|
| 34 |
+
"Dynamics",
|
| 35 |
"Turning Effect of Forces",
|
| 36 |
+
"Gravitation",
|
| 37 |
+
"Work and Energy",
|
| 38 |
+
"Properties of Matter",
|
| 39 |
+
"Thermal Properties of Matter",
|
| 40 |
+
"Transfer of Heat"
|
| 41 |
],
|
|
|
|
| 42 |
"Pakistan Studies": [
|
| 43 |
+
"Ideological Basis of Pakistan",
|
| 44 |
+
"Pakistan Movement",
|
| 45 |
+
"Land & Environment",
|
| 46 |
+
"History of Pakistan (1857–1947)",
|
| 47 |
+
"Economic Development"
|
| 48 |
+
],
|
| 49 |
+
|
| 50 |
+
# ======================
|
| 51 |
+
# NEW COMPULSORY SUBJECTS
|
| 52 |
+
# ======================
|
| 53 |
+
|
| 54 |
+
"Mathematics": [
|
| 55 |
+
"Matrices & Determinants",
|
| 56 |
+
"Real & Complex Numbers",
|
| 57 |
+
"Logarithms",
|
| 58 |
+
"Algebraic Expressions",
|
| 59 |
+
"Factorization",
|
| 60 |
+
"Linear Equations",
|
| 61 |
+
"Quadratic Equations",
|
| 62 |
+
"Ratio & Proportion",
|
| 63 |
+
"Financial Arithmetic",
|
| 64 |
+
"Geometry"
|
| 65 |
+
],
|
| 66 |
+
|
| 67 |
+
"English": [
|
| 68 |
+
"Reading Comprehension",
|
| 69 |
+
"Poetry",
|
| 70 |
+
"Grammar & Composition",
|
| 71 |
+
"Letter Writing",
|
| 72 |
+
"Story Writing",
|
| 73 |
+
"Tenses",
|
| 74 |
+
"Vocabulary"
|
| 75 |
+
],
|
| 76 |
+
|
| 77 |
+
"Urdu": [
|
| 78 |
+
"Nazms",
|
| 79 |
+
"Ghazals",
|
| 80 |
+
"Essays",
|
| 81 |
+
"Comprehension",
|
| 82 |
+
"Grammar",
|
| 83 |
+
"Muhavray",
|
| 84 |
+
"Tashreeh"
|
| 85 |
+
],
|
| 86 |
+
|
| 87 |
+
"Islamiyat": [
|
| 88 |
+
"Quranic Passages",
|
| 89 |
+
"Ahadith",
|
| 90 |
+
"Seerat-un-Nabi",
|
| 91 |
+
"Islamic Beliefs",
|
| 92 |
+
"Islamic History"
|
| 93 |
+
],
|
| 94 |
+
|
| 95 |
+
# Optional Subjects
|
| 96 |
+
"Computer Science": [
|
| 97 |
+
"Fundamentals of IT",
|
| 98 |
+
"Hardware & Software",
|
| 99 |
+
"Number Systems",
|
| 100 |
+
"Operating Systems",
|
| 101 |
+
"Introduction to Programming"
|
| 102 |
+
],
|
| 103 |
+
"General Science": [
|
| 104 |
+
"Our Universe",
|
| 105 |
+
"Matter & Energy",
|
| 106 |
+
"Life & Living Organisms",
|
| 107 |
+
"Environment",
|
| 108 |
+
"Technology in Everyday Life"
|
| 109 |
+
],
|
| 110 |
+
"Education": [
|
| 111 |
+
"Aims of Education",
|
| 112 |
+
"Curriculum",
|
| 113 |
+
"Teaching Methods",
|
| 114 |
+
"Assessment"
|
| 115 |
+
],
|
| 116 |
},
|
| 117 |
+
|
| 118 |
"Grade 10": {
|
|
|
|
|
|
|
|
|
|
| 119 |
"Biology": [
|
| 120 |
+
"Gaseous Exchange",
|
| 121 |
+
"Homeostasis",
|
| 122 |
+
"Coordination & Control",
|
| 123 |
+
"Support & Movement",
|
| 124 |
+
"Reproduction",
|
| 125 |
+
"Inheritance",
|
| 126 |
+
"Man & His Environment",
|
| 127 |
+
"Biotechnology",
|
| 128 |
+
"Pharmacology"
|
| 129 |
],
|
| 130 |
"Chemistry": [
|
| 131 |
+
"Chemical Equilibrium",
|
| 132 |
+
"Acids, Bases & Salts",
|
| 133 |
+
"Organic Chemistry",
|
| 134 |
+
"Hydrocarbons",
|
| 135 |
+
"Biochemistry",
|
| 136 |
+
"Environmental Chemistry"
|
|
|
|
|
|
|
| 137 |
],
|
| 138 |
"Physics": [
|
| 139 |
+
"Simple Harmonic Motion",
|
| 140 |
+
"Wave Motion",
|
| 141 |
+
"Sound",
|
| 142 |
+
"Geometrical Optics",
|
| 143 |
+
"Electrostatics",
|
| 144 |
+
"Current Electricity",
|
| 145 |
+
"Electromagnetism",
|
| 146 |
+
"Information & Communication Technology"
|
|
|
|
| 147 |
],
|
|
|
|
| 148 |
"Pakistan Studies": [
|
| 149 |
+
"Pakistan's Geography",
|
| 150 |
+
"Culture & Society",
|
| 151 |
+
"Civic Responsibilities",
|
| 152 |
+
"Government System",
|
| 153 |
+
"Economic Planning"
|
| 154 |
+
],
|
| 155 |
+
|
| 156 |
+
# NEW COMPULSORY SUBJECTS
|
| 157 |
+
|
| 158 |
+
"Mathematics": [
|
| 159 |
+
"Quadratic Equations",
|
| 160 |
+
"Theory of Quadratic Equations",
|
| 161 |
+
"Rational Expressions",
|
| 162 |
+
"Variation",
|
| 163 |
+
"Linear Graphs",
|
| 164 |
+
"Circles",
|
| 165 |
+
"Geometry",
|
| 166 |
+
"Statistics",
|
| 167 |
+
],
|
| 168 |
+
|
| 169 |
+
"English": [
|
| 170 |
+
"Prose",
|
| 171 |
+
"Poetry",
|
| 172 |
+
"Drama",
|
| 173 |
+
"Essay Writing",
|
| 174 |
+
"Tenses",
|
| 175 |
+
"Direct & Indirect",
|
| 176 |
+
"Active & Passive Voice"
|
| 177 |
+
],
|
| 178 |
+
|
| 179 |
+
"Urdu": [
|
| 180 |
+
"Ghazals",
|
| 181 |
+
"Nazms",
|
| 182 |
+
"Mazameen",
|
| 183 |
+
"Grammar",
|
| 184 |
+
"Muhavray",
|
| 185 |
+
"Takhlees"
|
| 186 |
+
],
|
| 187 |
+
|
| 188 |
+
"Islamiyat": [
|
| 189 |
+
"Quranic Teachings",
|
| 190 |
+
"Ahadith",
|
| 191 |
+
"Islamic System",
|
| 192 |
+
"Fiqh",
|
| 193 |
+
"Islamic History"
|
| 194 |
+
],
|
| 195 |
+
|
| 196 |
+
"Computer Science": [
|
| 197 |
+
"Programming Basics",
|
| 198 |
+
"Database Concepts",
|
| 199 |
+
"Computer Networks",
|
| 200 |
+
"Internet & Web",
|
| 201 |
+
"Algorithms"
|
| 202 |
+
],
|
| 203 |
+
|
| 204 |
+
"General Science": [
|
| 205 |
+
"Atoms & Molecules",
|
| 206 |
+
"Human Body Systems",
|
| 207 |
+
"Electricity",
|
| 208 |
+
"Magnetism",
|
| 209 |
+
"Environment"
|
| 210 |
+
],
|
| 211 |
+
|
| 212 |
+
"Education": [
|
| 213 |
+
"Educational Psychology",
|
| 214 |
+
"Learning Theories",
|
| 215 |
+
"Curriculum Development",
|
| 216 |
+
"Assessment in Education"
|
| 217 |
+
],
|
| 218 |
}
|
| 219 |
}
|
| 220 |
|
| 221 |
+
# ---------------------------------------------------------
|
| 222 |
+
# MCQ GENERATION FUNCTION
|
| 223 |
+
# ---------------------------------------------------------
|
| 224 |
|
| 225 |
+
def generate_mcqs(grade, subject, chapter, difficulty, mcq_count):
|
| 226 |
+
mcqs = []
|
| 227 |
+
for i in range(mcq_count):
|
| 228 |
+
mcq = f"{i+1}. ({difficulty}) MCQ from {chapter}, {subject}, {grade}"
|
| 229 |
+
options = ["A) Option 1", "B) Option 2", "C) Option 3", "D) Option 4"]
|
| 230 |
+
correct = random.choice(["A", "B", "C", "D"])
|
| 231 |
+
mcqs.append((mcq, options, correct))
|
| 232 |
|
| 233 |
+
# Format output
|
| 234 |
+
output = ""
|
| 235 |
+
for q, opts, _ in mcqs:
|
| 236 |
+
output += q + "\n"
|
| 237 |
+
for opt in opts:
|
| 238 |
+
output += opt + "\n"
|
| 239 |
+
output += "\n"
|
| 240 |
+
|
| 241 |
+
# Answer Key
|
| 242 |
+
output += "\nAnswer Key:\n"
|
| 243 |
+
for idx, (_, _, correct) in enumerate(mcqs, 1):
|
| 244 |
+
output += f"{idx}. {correct}\n"
|
| 245 |
+
|
| 246 |
+
return output
|
| 247 |
+
|
| 248 |
+
# ---------------------------------------------------------
|
| 249 |
+
# UPDATE CHAPTER LIST WHEN SUBJECT CHANGES
|
| 250 |
+
# ---------------------------------------------------------
|
| 251 |
+
|
| 252 |
+
def update_subjects(grade):
|
| 253 |
+
subjects = list(curriculum[grade].keys())
|
| 254 |
+
return gr.update(choices=subjects, value=subjects[0])
|
| 255 |
+
|
| 256 |
+
def update_chapters(grade, subject):
|
| 257 |
+
chapters = curriculum[grade][subject]
|
| 258 |
+
return gr.update(choices=chapters, value=chapters[0])
|
| 259 |
+
|
| 260 |
+
# ---------------------------------------------------------
|
| 261 |
+
# UI
|
| 262 |
+
# ---------------------------------------------------------
|
| 263 |
+
|
| 264 |
+
with gr.Blocks(title="Pakistan Curriculum MCQ Generator") as demo:
|
| 265 |
+
|
| 266 |
+
gr.Markdown("## **MCQs Generator (Grades 9 & 10 — National Curriculum 2006)**")
|
| 267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
with gr.Row():
|
| 269 |
+
grade = gr.Dropdown(choices=list(curriculum.keys()), label="Select Grade", value="Grade 9")
|
| 270 |
+
subject = gr.Dropdown(choices=list(curriculum["Grade 9"].keys()), label="Select Subject")
|
| 271 |
+
chapter = gr.Dropdown(choices=list(curriculum["Grade 9"]["Biology"]), label="Select Chapter")
|
| 272 |
+
|
| 273 |
+
difficulty = gr.Dropdown(
|
| 274 |
+
["Beginner (Pre-test)", "Intermediate", "Advanced"],
|
| 275 |
+
label="Difficulty Level",
|
| 276 |
+
value="Beginner (Pre-test)"
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
mcq_count = gr.Slider(
|
| 280 |
+
minimum=5,
|
| 281 |
+
maximum=50,
|
| 282 |
+
value=20,
|
| 283 |
+
step=1,
|
| 284 |
+
label="Number of MCQs"
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
generate_button = gr.Button("Generate MCQs")
|
| 288 |
+
|
| 289 |
+
output = gr.Textbox(label="Generated Test", lines=30)
|
| 290 |
+
|
| 291 |
+
# Events
|
| 292 |
+
grade.change(update_subjects, inputs=grade, outputs=subject)
|
| 293 |
+
subject.change(update_chapters, inputs=[grade, subject], outputs=chapter)
|
| 294 |
+
|
| 295 |
+
generate_button.click(
|
| 296 |
+
fn=generate_mcqs,
|
| 297 |
+
inputs=[grade, subject, chapter, difficulty, mcq_count],
|
| 298 |
+
outputs=output
|
| 299 |
)
|
| 300 |
|
| 301 |
+
demo.launch()
|