DEV Community

Cover image for My mom spends hours every week making test papers. I built her a generator that runs offline on Gemma 4
Nirav Neve
Nirav Neve

Posted on AI-assisted

My mom spends hours every week making test papers. I built her a generator that runs offline on Gemma 4

Hacktoberfest Weekend Challenge: Build for a Friend Submission 🤝

This is a submission for the Hacktoberfest Weekend Challenge: Build for a Friend

What I Built

My mom is my first friend. She is also a Class 8 maths teacher, and for as long as I can remember, test week at our house has looked the same.

The dining table disappears under the NCERT textbook, a stack of old question papers, a folder of worksheets and one notebook with a pencil tucked in it. She picks a question from one source, changes the numbers so the class can't copy last year's answers, works it out, writes the answer key, and moves on to the next one. A 40-mark paper is an evening. If she spots one bad question at the end, the whole thing gets retyped.

When I asked how I could help, her answer was simple: "I don't need new questions from the internet. I need questions from my books, in my style, and the answers have to be right."

So I built her a test paper generator that runs on her laptop.

She fills in a short form: total marks, how many MCQs, short answers, case studies and so on, the chapters, and a line like "more word problems, keep numbers simple". She presses one button. About twenty minutes later she has two Word files: the question paper and a separate answer key with a step-by-step marking scheme.

What it does for her:

  • Writes new questions from her own material. It reads her textbook chapters, 9 past papers and 15 worksheets, then writes fresh questions in the same style. Different numbers, new contexts, same chapter.
  • Checks every numeric answer key with code before it reaches her. If a key doesn't match the working, the question is rewritten.
  • Balances difficulty. By default a paper is 20% easy, 60% medium and 20% hard, the split most school papers follow, and she can change it.
  • Lets her replace one question without touching the rest. "Too hard", "too easy", "out of syllabus", or a note of her own, and only that question is rewritten.
  • Hands her real Word files, with proper fractions, powers and roots as Word equations, ready for her school's header.
  • Never loses work. The paper is saved after every question, so closing the laptop halfway through costs nothing.
  • Runs offline. Her books and her school's papers never leave the laptop.

Test week: before and after

Before (by hand) After (the generator)
Making a 40-mark paper An evening at the dining table ~35–40 min of laptop time, a few minutes of hers
Finding questions Flipping through the textbook, old papers and worksheets Searches all 13 chapters and 681 of her questions automatically
Fresh questions Changing numbers one by one New numbers and contexts, with a check that nothing is copied
Answer key Solved and written by hand Written with every step, and checked by code
Difficulty balance By feel 20% easy / 60% medium / 20% hard by default
One bad question Retype the paper Press Replace, about 1.5 minutes, nothing else moves
Formatting Typing fractions and powers into Word Word files with real equations, ready for the school header
If she stops halfway Start again from her notes Saved after every question, press Resume
Cost and privacy — Free, offline, her books never leave the laptop

Demo

Describe the paper, press Generate. The summary turns green when the rows add up to the total marks.

New paper form with live marks summary

Review it, download it, or replace a single question.

Finished paper with the Replace panel open

What lands in Word. The question paper first, then the answer key with every step. No LaTeX symbols, no cleanup.

Generated question paper in Word
Answer key with step-by-step working

Here's one question from a generated 20-mark paper, exactly as it came out:

Q12. A shopkeeper purchased a refrigerator for ₹ 8,000 and a washing machine for ₹ 12,000. He sold the refrigerator at a profit of 10% and the washing machine at a loss of 5%. Find the overall profit or loss percent on the entire transaction. [3]

Key: SP = 8,800 + 11,400 = ₹ 20,200, CP = ₹ 20,000, profit ₹ 200, so 1% profit.

That paper had 13 questions, and all 13 answer keys were confirmed by the code checker on the first try.

Code

Offline Test Paper Generator (Class 8 Maths)

A local tool for a Class 8 (CBSE) maths teacher. Describe a paper ("6 MCQs of 1 mark, 3 short answers of 2 marks chapters 7 to 10, more word problems") and get back a Word question paper and a separate answer key with marking schemes. Questions are new, written from the teacher's own textbooks, worksheets and past papers (RAG), and every numeric answer key is checked by code. One bad question can be replaced without touching the rest.

Everything runs on the laptop: a local open-weight model (Gemma 4 12B through Ollama). No internet, no hosting.


Quick start (teacher)

  1. Make sure Ollama is installed (the page starts it if needed).
  2. Double-click start.bat. A browser page opens.
  3. New paper: title, total marks, question rows (type, count, marks each), chapters, optional instructions and difficulty split (default 20% easy / 60%…

Double-click start.bat, and the page opens in the browser. When she closes the tab, the app shuts itself down.

How I Built It

The whole thing runs on a normal laptop: 16 GB RAM and an NVIDIA card with 6 GB of VRAM. The heart of it is Gemma 4 12B running locally through Ollama. What surprised me most is that one open model did three very different jobs.

How Gemma 4 reads, sorts and writes questions

Job 1: Gemma read her books
The textbooks are PDFs full of fractions and exponents. Plain text extraction turns ³⁄₂ into a "3" and a "2" on separate lines, and that would have poisoned everything downstream.

So every page with maths on it is rendered to an image and handed to Gemma 4's vision side, which writes it back as clean Markdown with LaTeX. It read tables, it read a line graph correctly (all four values, both axes), and it kept every fraction in one piece. A small checker compares the digits Gemma wrote against the raw PDF text and re-reads any page that doesn't match.

37 files went through, all on the laptop, in one overnight run. Nothing was uploaded anywhere.

Job 2: Gemma sorted the questions
Past papers don't say which chapter a question belongs to, and the generator needs that to find good examples. Gemma tagged 460 questions with a chapter, using structured output limited to the 13 chapter numbers. Not one of those calls returned broken JSON.

Later I went through all 681 questions by hand and tagged each one with its chapter, a Bloom level and a difficulty. On chapters, I agreed with Gemma 94% of the time.

Job 3: Gemma writes the questions
For each question slot, the app pulls a couple of textbook passages for that chapter and three real questions from her papers with the same marks, type and difficulty. Gemma sees them as style references and writes one new question.

A few things made Gemma really shine here:

  • A JSON schema per question type. An MCQ must return four options and a correct letter. An assertion-reason question returns the two statements and three true/false flags, and the code builds the standard four options from them.
  • A scratchpad field. The schema starts with a working field that students never see. Giving Gemma room to solve the problem first made the final answers noticeably cleaner.
  • Thinking off, 16K context. Fast enough to write a question in about 90 seconds at roughly 10 tokens per second, on a 6 GB card.

Code checks the answers, not the model
A wrong answer key is the one mistake a teacher can't afford. So Gemma also returns the calculation behind its answer, in a form a computer can run:

{"compute": "((8000*1.1) + (12000*0.95)) - (8000 + 12000)", "claimed": "200"}
Enter fullscreen mode Exit fullscreen mode

The app evaluates that with sympy, checks it matches the claim, and checks the claimed value is really the final answer in the key, or really the correct MCQ option. If anything disagrees, the question is rewritten. If it still can't be confirmed, it stays in the paper with a "check" badge so she knows exactly where to look.

The same idea runs through the Word export. After every file is written, a checker reads it back and makes sure no LaTeX symbol slipped into the text and no number went missing on the way into Word.

Replace one question
Each question has a Replace button. Her reason ("too hard", "out of syllabus", or anything she types) goes into the prompt together with the question she rejected, the difficulty moves a step if she asked for easier or harder, and every check runs again. The other questions don't move. Every replacement is also saved to a feedback log, which is a lovely little dataset if I ever fine-tune Gemma on her taste.

The stack, all open
Gemma 4 12B and bge-m3 through Ollama, ChromaDB for search, sympy for the answer checks, pandoc for Word equations, and Streamlit for the page.

Why Does Open Innovation Matter?

For this project, open wasn't a nice-to-have. It was the only way it could exist.

  • Her material stays hers. Textbooks and school question papers aren't mine to upload to someone else's server. With Gemma running locally, nothing leaves the laptop.
  • It works with no internet. Test week doesn't wait for the Wi-Fi.
  • It costs nothing per paper. No subscription, no API bill, no limit on how many times she presses Replace.
  • I could shape the model's output exactly. Per-type JSON schemas, a hidden scratchpad, my own retry rules. Every model call goes through one small file, so swapping or upgrading the model is a one-line change.
  • It's gentle on resources. It runs on a laptop she already owns, with no data-center round trip for every question. Replace rewrites one question instead of a whole paper. And because answer keys are checked before anything is printed, she isn't printing draft after draft to catch mistakes.

Prize Categories

Best Use of Gemma.
Gemma 4 12B is the core of the project, and it does three separate jobs, all running locally on a 6 GB laptop GPU:

  1. Reading: Gemma 4's vision turned every textbook, worksheet and past-paper page into clean Markdown and LaTeX.
  2. Sorting: it tagged 460 questions by chapter with structured output.
  3. Writing: it writes every question, answer and marking scheme.

I went in expecting to stitch together three different models. Gemma did all three, offline, with structured output I could rely on.

To the Gemma team at Google
Thank you for putting a model this capable into a size that fits on a teacher's laptop. It turned "maybe one day" into a weekend project I could hand to my mom.

This week it is going to be me and my mom enjoying tea while the test paper generator does all the hard work 😉

Voice Note From my Mom

"It generated a test paper in a few minutes, which usually took me hours. It is a great help for me, and I am really proud of my son."
— my mom, after trying it for the first time

Top comments (0)