Spaces:
No application file
No application file
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
| 7 |
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
| 8 |
import re
|
| 9 |
import random
|
|
@@ -16,99 +16,45 @@ grades = [f"Grade {i}" for i in range(1, 13)]
|
|
| 16 |
difficulty_levels = ["Pretest (Beginner)", "Intermediate", "Advanced"]
|
| 17 |
min_mcq, max_mcq = 5, 50
|
| 18 |
|
| 19 |
-
# Subjects and chapters by grade
|
| 20 |
chapters_by_subject_and_grade = {
|
| 21 |
-
"Grade 1": {
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
},
|
| 28 |
-
"Grade
|
| 29 |
-
"Mathematics": ["
|
| 30 |
-
"English": ["
|
| 31 |
-
"Urdu": ["
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
"
|
| 37 |
-
"
|
| 38 |
-
"Urdu": ["قواعد كا تعارف", "کہیں کہانیاں"],
|
| 39 |
-
"Science": ["Plants & Animals", "Human Body (basic)", "Materials & Uses"],
|
| 40 |
-
"Islamiyat": ["Seerat Stories & Morals", "Basic Akhlaq"]
|
| 41 |
-
},
|
| 42 |
-
"Grade 4": {
|
| 43 |
-
"Mathematics": ["Fractions & Decimals (intro)", "Geometry (angles, shapes)", "Data & Graphs", "Word Problems"],
|
| 44 |
-
"English": ["Grammar (parts of speech)", "Paragraph Writing", "Comprehension", "Listening & Speaking"],
|
| 45 |
-
"Urdu": ["نظم و نثر کا مطالعہ", "قواعد"],
|
| 46 |
-
"Science": ["Ecosystems", "Forces & Simple Machines", "Heat & Energy"],
|
| 47 |
-
"Islamiyat": ["Pillars of Islam", "Seerah Highlights"],
|
| 48 |
-
"Social Studies": ["Local Geography", "Community & Careers", "Citizenship"]
|
| 49 |
-
},
|
| 50 |
-
"Grade 5": {
|
| 51 |
-
"Mathematics": ["Number Operations", "Percentage & Ratio (intro)", "Geometry & Area", "Statistics (intro)"],
|
| 52 |
-
"English": ["Advanced Comprehension", "Essay & Letter Writing", "Grammar Consolidation"],
|
| 53 |
-
"Urdu": ["ادبی مطالعہ اور تحریر", "قواعد"],
|
| 54 |
-
"Science": ["Cells (intro)", "Matter & its Properties", "Energy & Sound"],
|
| 55 |
-
"Islamiyat": ["Quranic Stories & Morals"],
|
| 56 |
-
"Social Studies": ["History (local & national)", "Map Skills", "Basic Economics"]
|
| 57 |
-
},
|
| 58 |
-
"Grade 6": {
|
| 59 |
-
"Mathematics": ["Number System & Factors", "Algebraic Expressions (intro)", "Geometry Basics", "Data Handling"],
|
| 60 |
-
"English": ["Grammar & Usage", "Comprehension", "Writing Paragraphs", "Poetry & Prose"],
|
| 61 |
-
"Urdu": ["نثر و نظم", "قواعد ِاردو", "تحریر"],
|
| 62 |
-
"Science": ["Atoms & Molecules (intro)", "Human Body Systems", "Plants & Ecology"],
|
| 63 |
-
"Islamiyat": ["Seerah & Ahkam (intro)"],
|
| 64 |
-
"Social Studies": ["Physical Geography", "Early Civilizations", "Citizenship"]
|
| 65 |
-
},
|
| 66 |
-
"Grade 7": {
|
| 67 |
-
"Mathematics": ["Algebra (linear)", "Geometry (polygons, areas)", "Mensuration", "Graphs"],
|
| 68 |
-
"English": ["Advanced Grammar", "Comprehension Passages", "Composition"],
|
| 69 |
-
"Urdu": ["ادبی اور تنقیدی مطالعہ", "قواعد"],
|
| 70 |
-
"Science": ["Cell Biology", "Electricity & Magnetism (basic)", "Properties of Matter"],
|
| 71 |
-
"Islamiyat": ["Islamic History & Ethics"],
|
| 72 |
-
"Social Studies": ["Regional Geography", "Historical Events & Movements"],
|
| 73 |
-
"Computer": ["ICT Basics", "Introductory Coding Concepts"]
|
| 74 |
-
},
|
| 75 |
-
"Grade 8": {
|
| 76 |
-
"Mathematics": ["Linear Equations & Inequalities", "Coordinate Geometry", "Pythagoras & Trigonometry (intro)", "Probability"],
|
| 77 |
-
"English": ["Critical Reading", "Extended Writing", "Grammar Review"],
|
| 78 |
-
"Urdu": ["ادبی تنقید", "تحریر"],
|
| 79 |
-
"Science": ["Forces & Motion", "Heat & Temperature", "Waves & Optics (intro)"],
|
| 80 |
-
"Islamiyat": ["Fiqh Basics & Seerah"],
|
| 81 |
-
"Social Studies": ["Civics & Government", "Economic Concepts"],
|
| 82 |
-
"Computer": ["Algorithms & Flowcharts", "Application Software"]
|
| 83 |
-
},
|
| 84 |
-
"Grade 9": {
|
| 85 |
-
"Mathematics": ["Number Systems & Algebra", "Coordinate Geometry", "Trigonometry", "Graphs"],
|
| 86 |
-
"English": ["Advanced Grammar", "Comprehension", "Writing Skills"],
|
| 87 |
-
"Urdu": ["ادب اور نثر", "نظم", "مضامین"],
|
| 88 |
-
"Biology": ["INTRODUCTION TO BIOLOGY","SOLVING A BIOLOGICAL PROBLEM","BIODIVERSITY","CELLS AND TISSUES","CELL CYCLE","ENZYMES","BIOENERGETICS","NUTRITION","TRANSPORT"],
|
| 89 |
-
"Chemistry": ["FUNDAMENTALS OF CHEMISTRY","STRUCTURE OF ATOMS","PERIODIC TABLE AND PERIODICITY OF PROPERTIES","STRUCTURE OF MOLECULES","PHYSICAL STATES OF MATTER","SOLUTIONS","ELECTROCHEMISTRY","CHEMICAL REACTIVITY"],
|
| 90 |
-
"Physics": ["PHYSICAL QUANTITIES AND MEASUREMENT","KINEMATICS","DYNAMICS","TURNING EFFECT OF FORCES","GRAVITATION","WORK AND ENERGY","PROPERTIES OF MATTER","THERMAL PROPERTIES OF MATTER","TRANSFER OF HEAT"],
|
| 91 |
-
"Islamiyat": ["Seerat of Prophet", "Faith & Beliefs", "Worship Practices"],
|
| 92 |
-
"Pakistan Studies": ["IDEOLOGICAL BASIS OF PAKISTAN","MAKING OF PAKISTAN","LAND AND ENVIRONMENT","HISTORY OF PAKISTAN"],
|
| 93 |
-
"Computer": ["Fundamentals of Computing", "ICT Applications"]
|
| 94 |
-
},
|
| 95 |
-
"Grade 10": {
|
| 96 |
-
"Mathematics": ["Advanced Algebra", "Trigonometry", "Geometry", "Probability"],
|
| 97 |
-
"English": ["Literature", "Advanced Composition", "Comprehension"],
|
| 98 |
-
"Urdu": ["ادبِ جدید", "تحقیقی مضمون"],
|
| 99 |
-
"Biology": ["GASEOUS EXCHANGE","HOMEOSTASIS","COORDINATION","SUPPORT AND MOVEMENT","REPRODUCTION","INHERITANCE","MAN AND HIS ENVIRONMENT","BIOTECHNOLOGY","PHARMA"],
|
| 100 |
-
"Chemistry": ["CHEMICAL EQUILIBRIUM","ACIDS, BASES AND SALTS","ORGANIC CHEMISTRY","HYDROCARBONS","BIOCHEMISTRY","ENVIRONMENTAL CHEMISTRY I: THE ATMOSPHERE","ENVIRONMENTAL CHEMISTRY II: WATER","CHEMICAL INDUSTRIES"],
|
| 101 |
-
"Physics": ["SIMPLE HARMONIC MOTION AND WAVES","SOUND","GEOMETRICAL OPTICS","ELECTROSTATICS","CURRENT ELECTRICITY","ELECTROMAGNETISM","INTRODUCTORY ELECTRONICS","INFORMATION AND COMMUNICATION TECHNOLOGY","RADIOACTIVITY"],
|
| 102 |
-
"Islamiyat": ["Islamic Studies II", "Ethics & Society", "Fiqh Basics"],
|
| 103 |
-
"Pakistan Studies": ["HISTORY OF PAKISTAN-II","PAKISTAN IN WORLD AFFAIRS","ECONOMIC DEVELOPMENTS","POPULATION, SOCIETY AND CULTURE OF PAKISTAN"],
|
| 104 |
-
"Computer": ["Programming Basics", "ICT in Society"]
|
| 105 |
}
|
| 106 |
-
# Higher Secondary (Grades 11-12) can be similarly added
|
| 107 |
}
|
| 108 |
|
| 109 |
def generate_mcqs(grade, subject, chapter, difficulty, num_questions):
|
| 110 |
system_msg = "You are an educational expert. Generate MCQs strictly aligned with the Pakistani National Curriculum."
|
| 111 |
-
user_msg = f"Create {num_questions} MCQs for {grade} {subject} on the chapter '{chapter}' at '{difficulty}' level. Each question must have 4 options. Provide answer key separately."
|
| 112 |
|
| 113 |
response = client.chat.completions.create(
|
| 114 |
messages=[
|
|
@@ -127,6 +73,14 @@ def generate_mcqs(grade, subject, chapter, difficulty, num_questions):
|
|
| 127 |
|
| 128 |
def export_to_word(mcqs, answers, grade, subject, chapter, difficulty, num_questions):
|
| 129 |
doc = Document()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
# Table at top
|
| 131 |
table = doc.add_table(rows=6, cols=2)
|
| 132 |
table.style = 'Table Grid'
|
|
|
|
| 3 |
from groq import Groq
|
| 4 |
from datetime import datetime
|
| 5 |
from docx import Document
|
| 6 |
+
from docx.shared import Pt
|
| 7 |
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
| 8 |
import re
|
| 9 |
import random
|
|
|
|
| 16 |
difficulty_levels = ["Pretest (Beginner)", "Intermediate", "Advanced"]
|
| 17 |
min_mcq, max_mcq = 5, 50
|
| 18 |
|
| 19 |
+
# Subjects and chapters by grade (including Grades 11-12)
|
| 20 |
chapters_by_subject_and_grade = {
|
| 21 |
+
"Grade 1": {...}, # keep previous Grades 1-10 dict here
|
| 22 |
+
"Grade 2": {...},
|
| 23 |
+
"Grade 3": {...},
|
| 24 |
+
"Grade 4": {...},
|
| 25 |
+
"Grade 5": {...},
|
| 26 |
+
"Grade 6": {...},
|
| 27 |
+
"Grade 7": {...},
|
| 28 |
+
"Grade 8": {...},
|
| 29 |
+
"Grade 9": {...},
|
| 30 |
+
"Grade 10": {...},
|
| 31 |
+
"Grade 11": {
|
| 32 |
+
"Mathematics": ["Advanced Algebra & Calculus Intro", "Coordinate Geometry", "Trigonometry", "Vectors"],
|
| 33 |
+
"English": ["Academic Writing", "Literature Studies", "Critical Reading"],
|
| 34 |
+
"Urdu": ["ادبی مطالعہ", "نظم و نثر کی تشریح"],
|
| 35 |
+
"Biology": ["Cell Structure and Functions","Biological Molecules","Enzymes","Bioenergetics","Acellular Life & Microorganisms","Diversity of Plants","Diversity of Animals","Plant Form and Function","Digestion and Nutrition","Circulation and Respiration","Immunity"],
|
| 36 |
+
"Chemistry": ["Stoichiometry & Chemical Calculations","Atomic Structure & Periodicity","Bonding & Molecular Shape","States of Matter (Gases, Liquids, Solids)","Solutions & Colligative Properties","Thermochemistry","Chemical Kinetics","Electrochemistry & Redox"],
|
| 37 |
+
"Physics": ["Measurement & Vectors","Forces & Motion","Work & Energy","Rotational Motion","Fluid Mechanics","Oscillations & Waves","Geometrical Optics","Thermodynamics","Electrostatics","Current Electricity"],
|
| 38 |
+
"Computer": ["Programming Fundamentals","Data Structures Intro","Databases & File Systems"],
|
| 39 |
+
"Islamiyat": ["Advanced Seerah","Islamic Ethics"],
|
| 40 |
+
"Pakistan Studies": ["Pakistan in Geographical Perspective","Resources & Economy","Historical Overview","Political & Constitutional Development","Human Rights & Citizenship"]
|
| 41 |
},
|
| 42 |
+
"Grade 12": {
|
| 43 |
+
"Mathematics": ["Calculus", "Advanced Algebra", "Statistics", "Analytical Geometry"],
|
| 44 |
+
"English": ["Research Writing", "Advanced Literature", "Critical Analysis"],
|
| 45 |
+
"Urdu": ["تحقیق و تنقید", "ادبی شخصیات"],
|
| 46 |
+
"Biology": ["Respiration & Exchange","Homeostasis & Coordination (Nervous & Chemical)","Support, Movement & Musculoskeletal System","Reproduction & Development","Genetics & Inheritance","Evolution & Biodiversity","Man and His Environment","Biotechnology & Its Applications","Biology and Human Welfare"],
|
| 47 |
+
"Chemistry": ["s and p Block Elements","d Block & Transition Elements","Organic Reaction Mechanisms","Hydrocarbons & Functional Groups","Alcohols, Phenols, Ethers","Aldehydes & Ketones","Carboxylic Acids & Derivatives","Biochemistry (Carbohydrates, Proteins, Lipids)","Analytical & Industrial Chemistry","Environmental Chemistry"],
|
| 48 |
+
"Physics": ["Electromagnetism & EM Induction","Alternating Current Circuits","Electronics & Semiconductors","Atomic & Nuclear Physics","Modern Physics Topics","Optics & Waves (advanced)"],
|
| 49 |
+
"Computer": ["Advanced Programming Concepts","Web Technologies & Networks"],
|
| 50 |
+
"Islamiyat": ["Islamic Jurisprudence (Fiqh)","Contemporary Islamic Thought"],
|
| 51 |
+
"Pakistan Studies": ["Society & Culture","Foreign Relations","Economic Policies & Development","Contemporary Challenges & National Identity"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
}
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
def generate_mcqs(grade, subject, chapter, difficulty, num_questions):
|
| 56 |
system_msg = "You are an educational expert. Generate MCQs strictly aligned with the Pakistani National Curriculum."
|
| 57 |
+
user_msg = f"Create {num_questions} MCQs for {grade} {subject} on the chapter '{chapter}' at '{difficulty}' level. Each question must have 4 options. Provide answer key separately. Do not include any introductory text before MCQ 1."
|
| 58 |
|
| 59 |
response = client.chat.completions.create(
|
| 60 |
messages=[
|
|
|
|
| 73 |
|
| 74 |
def export_to_word(mcqs, answers, grade, subject, chapter, difficulty, num_questions):
|
| 75 |
doc = Document()
|
| 76 |
+
|
| 77 |
+
# Main heading
|
| 78 |
+
heading = doc.add_paragraph("MONTHLY/ WEEKLY TEST")
|
| 79 |
+
heading.alignment = WD_ALIGN_PARAGRAPH.CENTER
|
| 80 |
+
run = heading.runs[0]
|
| 81 |
+
run.bold = True
|
| 82 |
+
run.font.size = Pt(16)
|
| 83 |
+
|
| 84 |
# Table at top
|
| 85 |
table = doc.add_table(rows=6, cols=2)
|
| 86 |
table.style = 'Table Grid'
|