Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,301 +1,304 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
|
| 4 |
-
# ---------------------------------------------------------
|
| 5 |
-
#
|
| 6 |
-
# ---------------------------------------------------------
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
"
|
| 10 |
-
"Biology"
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
"
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
"
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
"
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 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 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 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 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 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 |
-
|
| 253 |
-
subjects = list(curriculum[grade].keys())
|
| 254 |
-
return gr.update(choices=subjects, value=subjects[0])
|
| 255 |
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
# ---------------------------------------------------------
|
| 263 |
|
| 264 |
-
with gr.Blocks(title="
|
| 265 |
|
| 266 |
-
gr.Markdown("## **
|
| 267 |
|
| 268 |
with gr.Row():
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
difficulty = gr.Dropdown(
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
)
|
| 278 |
|
| 279 |
-
|
|
|
|
| 280 |
minimum=5,
|
| 281 |
-
maximum=
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
label="Number of MCQs"
|
| 285 |
)
|
| 286 |
|
| 287 |
-
|
| 288 |
|
| 289 |
-
output = gr.Textbox(label="Generated Test", lines=30)
|
| 290 |
|
| 291 |
-
|
| 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=[
|
| 298 |
outputs=output
|
| 299 |
)
|
| 300 |
|
| 301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
|
| 4 |
+
# -----------------------------------------------------------------------------------
|
| 5 |
+
# FIXED BOOKS & CHAPTERS for Grade 9 & 10 (given earlier, unchanged)
|
| 6 |
+
# -----------------------------------------------------------------------------------
|
| 7 |
+
|
| 8 |
+
subjects_chapters = {
|
| 9 |
+
"Biology 9": [
|
| 10 |
+
"Introduction to Biology",
|
| 11 |
+
"Solving a Biological Problem",
|
| 12 |
+
"Biodiversity",
|
| 13 |
+
"Cells and Tissues",
|
| 14 |
+
"Cell Cycle",
|
| 15 |
+
"Enzymes",
|
| 16 |
+
"Bioenergetics",
|
| 17 |
+
"Nutrition",
|
| 18 |
+
"Transport",
|
| 19 |
+
"Gaseous Exchange"
|
| 20 |
+
],
|
| 21 |
+
"Biology 10": [
|
| 22 |
+
"Homeostasis",
|
| 23 |
+
"Coordination and Control",
|
| 24 |
+
"Support and Movement",
|
| 25 |
+
"Reproduction",
|
| 26 |
+
"Inheritance",
|
| 27 |
+
"Man and His Environment",
|
| 28 |
+
"Biotechnology",
|
| 29 |
+
"Pharmacology"
|
| 30 |
+
],
|
| 31 |
+
|
| 32 |
+
"Chemistry 9": [
|
| 33 |
+
"Fundamentals of Chemistry",
|
| 34 |
+
"Structure of Atoms",
|
| 35 |
+
"Periodic Table",
|
| 36 |
+
"Structure of Molecules",
|
| 37 |
+
"Physical States of Matter",
|
| 38 |
+
"Solutions",
|
| 39 |
+
"Electrochemistry",
|
| 40 |
+
"Chemical Reactivity"
|
| 41 |
+
],
|
| 42 |
+
"Chemistry 10": [
|
| 43 |
+
"Chemical Equilibrium",
|
| 44 |
+
"Acids, Bases and Salts",
|
| 45 |
+
"Organic Chemistry",
|
| 46 |
+
"Hydrocarbons",
|
| 47 |
+
"Biochemistry",
|
| 48 |
+
"Environmental Chemistry",
|
| 49 |
+
"Chemical Industries"
|
| 50 |
+
],
|
| 51 |
+
|
| 52 |
+
"Physics 9": [
|
| 53 |
+
"Physical Quantities & Measurements",
|
| 54 |
+
"Kinematics",
|
| 55 |
+
"Dynamics",
|
| 56 |
+
"Turning Effect of Forces",
|
| 57 |
+
"Gravitation",
|
| 58 |
+
"Work & Energy",
|
| 59 |
+
"Properties of Matter",
|
| 60 |
+
"Thermal Properties of Matter",
|
| 61 |
+
"Transfer of Heat"
|
| 62 |
+
],
|
| 63 |
+
"Physics 10": [
|
| 64 |
+
"Sound",
|
| 65 |
+
"Electrostatics",
|
| 66 |
+
"Current Electricity",
|
| 67 |
+
"Electromagnetism",
|
| 68 |
+
"Basic Electronics",
|
| 69 |
+
"Information & Communication Technology",
|
| 70 |
+
"Atomic & Nuclear Physics"
|
| 71 |
+
],
|
| 72 |
+
|
| 73 |
+
"Pakistan Studies 9": [
|
| 74 |
+
"Ideological Basis of Pakistan",
|
| 75 |
+
"Pakistan Movement",
|
| 76 |
+
"Land & Environment",
|
| 77 |
+
"History of Pakistan (1947β1971)"
|
| 78 |
+
],
|
| 79 |
+
"Pakistan Studies 10": [
|
| 80 |
+
"Culture of Pakistan",
|
| 81 |
+
"Economy of Pakistan",
|
| 82 |
+
"Government of Pakistan",
|
| 83 |
+
"Human Rights in Pakistan"
|
| 84 |
+
],
|
| 85 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
+
# -----------------------------------------------------------------------------------
|
| 88 |
+
# NEWLY ADDED SECONDARY + HIGHER SECONDARY SUBJECTS (2006 Curriculum)
|
| 89 |
+
# -----------------------------------------------------------------------------------
|
| 90 |
+
|
| 91 |
+
subjects_chapters.update({
|
| 92 |
+
# -----------------------------------------
|
| 93 |
+
# English Compulsory (9β10)
|
| 94 |
+
# -----------------------------------------
|
| 95 |
+
"English 9β10": [
|
| 96 |
+
"Reading Comprehension",
|
| 97 |
+
"Writing Skills",
|
| 98 |
+
"Grammar & Vocabulary",
|
| 99 |
+
"Formal & Informal Letters",
|
| 100 |
+
"Dialogue Writing",
|
| 101 |
+
"Story Writing",
|
| 102 |
+
"Essay Writing",
|
| 103 |
+
"Translation Skills"
|
| 104 |
+
],
|
| 105 |
+
|
| 106 |
+
# -----------------------------------------
|
| 107 |
+
# Urdu Compulsory (9β10)
|
| 108 |
+
# -----------------------------------------
|
| 109 |
+
"Urdu 9β10": [
|
| 110 |
+
"Ghazaal",
|
| 111 |
+
"Nazam",
|
| 112 |
+
"Novel / Afsana",
|
| 113 |
+
"Drama",
|
| 114 |
+
"Grammar",
|
| 115 |
+
"Khulasa Nigar",
|
| 116 |
+
"Mazmoon Nigar",
|
| 117 |
+
"Takhleeqi Nigarish"
|
| 118 |
+
],
|
| 119 |
+
|
| 120 |
+
# -----------------------------------------
|
| 121 |
+
# Islamiyat Compulsory (9β10)
|
| 122 |
+
# -----------------------------------------
|
| 123 |
+
"Islamiyat 9β10": [
|
| 124 |
+
"Quranic Verses",
|
| 125 |
+
"Ahadith",
|
| 126 |
+
"Seerat-un-Nabi",
|
| 127 |
+
"Islamic Beliefs",
|
| 128 |
+
"Ibadat",
|
| 129 |
+
"Islamic Moral Values",
|
| 130 |
+
"Islamic Social System"
|
| 131 |
+
],
|
| 132 |
+
|
| 133 |
+
# -----------------------------------------
|
| 134 |
+
# Mathematics Science Group (9β10)
|
| 135 |
+
# -----------------------------------------
|
| 136 |
+
"Mathematics 9β10": [
|
| 137 |
+
"Algebraic Expressions",
|
| 138 |
+
"Factorization",
|
| 139 |
+
"Quadratic Equations",
|
| 140 |
+
"Matrices & Determinants",
|
| 141 |
+
"Geometry",
|
| 142 |
+
"Trigonometry",
|
| 143 |
+
"Statistics"
|
| 144 |
+
],
|
| 145 |
+
|
| 146 |
+
# -----------------------------------------
|
| 147 |
+
# Computer Science (9β10)
|
| 148 |
+
# -----------------------------------------
|
| 149 |
+
"Computer Science 9β10": [
|
| 150 |
+
"Introduction to Computers",
|
| 151 |
+
"Hardware Components",
|
| 152 |
+
"Software & Operating Systems",
|
| 153 |
+
"Basics of Programming",
|
| 154 |
+
"MS Office Applications",
|
| 155 |
+
"Computer Networks",
|
| 156 |
+
"Internet & IT Ethics"
|
| 157 |
+
],
|
| 158 |
+
|
| 159 |
+
# -----------------------------------------------------------------------------------
|
| 160 |
+
# HIGHER SECONDARY (11β12)
|
| 161 |
+
# -----------------------------------------------------------------------------------
|
| 162 |
+
|
| 163 |
+
"Biology 11β12": [
|
| 164 |
+
"Cell Structure & Function",
|
| 165 |
+
"Biological Molecules",
|
| 166 |
+
"Plant Physiology",
|
| 167 |
+
"Animal Physiology",
|
| 168 |
+
"Reproduction",
|
| 169 |
+
"Genetics",
|
| 170 |
+
"Evolution",
|
| 171 |
+
"Biotechnology"
|
| 172 |
+
],
|
| 173 |
+
"Chemistry 11β12": [
|
| 174 |
+
"Stoichiometry",
|
| 175 |
+
"Thermochemistry",
|
| 176 |
+
"Chemical Kinetics",
|
| 177 |
+
"Electrochemistry",
|
| 178 |
+
"s & p Block Elements",
|
| 179 |
+
"Transition Elements",
|
| 180 |
+
"Alcohols & Phenols",
|
| 181 |
+
"Carboxylic Acids"
|
| 182 |
+
],
|
| 183 |
+
"Physics 11β12": [
|
| 184 |
+
"Vectors & Motion",
|
| 185 |
+
"Circular Motion",
|
| 186 |
+
"Fluid Dynamics",
|
| 187 |
+
"Oscillations & Waves",
|
| 188 |
+
"Electromagnetism",
|
| 189 |
+
"Optics",
|
| 190 |
+
"Modern Physics",
|
| 191 |
+
"Nuclear Physics"
|
| 192 |
+
],
|
| 193 |
+
"Pakistan Studies 11β12": [
|
| 194 |
+
"Historical Perspectives",
|
| 195 |
+
"Constitutional Development",
|
| 196 |
+
"Foreign Policy of Pakistan",
|
| 197 |
+
"Economy & Resources"
|
| 198 |
+
],
|
| 199 |
+
"Mathematics 11β12": [
|
| 200 |
+
"Functions & Limits",
|
| 201 |
+
"Differentiation",
|
| 202 |
+
"Integration",
|
| 203 |
+
"Linear Algebra",
|
| 204 |
+
"Trigonometric Identities",
|
| 205 |
+
"Conic Sections",
|
| 206 |
+
"Vectors"
|
| 207 |
+
],
|
| 208 |
+
"English 11β12": [
|
| 209 |
+
"Reading & Comprehension",
|
| 210 |
+
"Essay Writing",
|
| 211 |
+
"Grammar",
|
| 212 |
+
"Poetry",
|
| 213 |
+
"Short Stories",
|
| 214 |
+
"Drama"
|
| 215 |
+
],
|
| 216 |
+
})
|
| 217 |
+
|
| 218 |
+
# -----------------------------------------------------------------------------------
|
| 219 |
+
# MCQ GENERATOR FUNCTION
|
| 220 |
+
# -----------------------------------------------------------------------------------
|
| 221 |
+
|
| 222 |
+
def generate_mcqs(subject, chapter, difficulty, mcq_count):
|
| 223 |
+
if not subject or not chapter:
|
| 224 |
+
return "Please select subject and chapter."
|
| 225 |
+
|
| 226 |
+
difficulty_text = {
|
| 227 |
+
"Pretest (Absolute Beginner)": "Very easy MCQs based strictly on recall-level knowledge.",
|
| 228 |
+
"Intermediate": "Moderate difficulty MCQs based on understanding and conceptual clarity.",
|
| 229 |
+
"Advanced": "Challenging MCQs requiring analysis and higher-order thinking."
|
| 230 |
}
|
|
|
|
| 231 |
|
| 232 |
+
prompt_style = difficulty_text[difficulty]
|
|
|
|
|
|
|
| 233 |
|
|
|
|
| 234 |
mcqs = []
|
| 235 |
+
for i in range(1, mcq_count + 1):
|
| 236 |
+
mcqs.append(
|
| 237 |
+
f"{i}. (Difficulty: {difficulty}) {prompt_style} β MCQ from '{chapter}'\n"
|
| 238 |
+
f"A. Option 1\nB. Option 2\nC. Option 3\nD. Option 4\n"
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
answer_key = "\n".join([f"{i}. {random.choice(['A','B','C','D'])}" for i in range(1, mcq_count + 1)])
|
| 242 |
+
|
| 243 |
+
test_output = "\n".join(mcqs)
|
| 244 |
+
final_output = (
|
| 245 |
+
"MCQ TEST\n\n"
|
| 246 |
+
+ test_output
|
| 247 |
+
+ "\n\nANSWER KEY\n"
|
| 248 |
+
+ answer_key
|
| 249 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
+
return final_output
|
|
|
|
|
|
|
| 252 |
|
| 253 |
+
# -----------------------------------------------------------------------------------
|
| 254 |
+
# GRADIO UI
|
| 255 |
+
# -----------------------------------------------------------------------------------
|
| 256 |
|
| 257 |
+
def get_chapters(subject):
|
| 258 |
+
return gr.update(choices=subjects_chapters.get(subject, []), value=None)
|
|
|
|
| 259 |
|
| 260 |
+
with gr.Blocks(title="MCQ Test Generator for Grades 9β12") as demo:
|
| 261 |
|
| 262 |
+
gr.Markdown("## **MCQ Test Generator (Pakistan National Curriculum 2006)**")
|
| 263 |
|
| 264 |
with gr.Row():
|
| 265 |
+
subject = gr.Dropdown(
|
| 266 |
+
label="Select Subject",
|
| 267 |
+
choices=list(subjects_chapters.keys())
|
| 268 |
+
)
|
| 269 |
+
chapter = gr.Dropdown(label="Select Chapter")
|
| 270 |
+
|
| 271 |
+
subject.change(fn=get_chapters, inputs=subject, outputs=chapter)
|
| 272 |
|
| 273 |
difficulty = gr.Dropdown(
|
| 274 |
+
label="Select Test Difficulty Level",
|
| 275 |
+
choices=[
|
| 276 |
+
"Pretest (Absolute Beginner)",
|
| 277 |
+
"Intermediate",
|
| 278 |
+
"Advanced"
|
| 279 |
+
],
|
| 280 |
+
value="Intermediate"
|
| 281 |
)
|
| 282 |
|
| 283 |
+
mcq_slider = gr.Slider(
|
| 284 |
+
label="Select Number of MCQs",
|
| 285 |
minimum=5,
|
| 286 |
+
maximum=100,
|
| 287 |
+
step=5,
|
| 288 |
+
value=20
|
|
|
|
| 289 |
)
|
| 290 |
|
| 291 |
+
generate_btn = gr.Button("Generate MCQs")
|
| 292 |
|
| 293 |
+
output = gr.Textbox(label="Generated MCQ Test", lines=30)
|
| 294 |
|
| 295 |
+
generate_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
fn=generate_mcqs,
|
| 297 |
+
inputs=[subject, chapter, difficulty, mcq_slider],
|
| 298 |
outputs=output
|
| 299 |
)
|
| 300 |
|
| 301 |
+
# -----------------------------------------------------------------------------------
|
| 302 |
+
|
| 303 |
+
if __name__ == "__main__":
|
| 304 |
+
demo.launch()
|