Prashn Patra:以 Gemma 3 (4B) 離線生成可列印練習試卷
प्रश्न पत्र
Prashn Patra 以 Gemma 3 (4B) 經 Ollama 在本機把章節內容轉成可列印的練習試卷和答案卷。每條答案均附上章節原句作依據,教師可逐題審閲、編輯或重新生成,確認後下載兩份 PDF。工具支援 PDF、書頁相片或筆記,並可生成印地語、英文或雙語版本;設定後可離線使用。
It's 11:47 PM in Patna. Classes ended hours ago, and a coaching teacher is typing tomorrow's practice test:
Q1. Which Article abolishes untouchability?
Then they type it again, because half the batch studies in Hindi:
प्र.1 कौन-सा अनुच्छेद अस्पृश्यता का अंत करता है?
Twenty-five questions, twice, every week. Paid question banks don't match their own notes, and cloud AI tools charge per use, need good internet, and send the institute's notes to someone else's server.
So for "Side Hustle", I built the tool a small coaching centre would actually pay for.
What I Built
Prashn Patra (प्रश्न पत्र, "question paper") turns a chapter into a ready-to-print practice test:
- In: a chapter PDF, photos of book pages, or the teacher's own notes
- Out: a student paper and an answer key, in Hindi, English or bilingual (both on one sheet, same answer letters)
- Question types: MCQ, true/false, fill in the blank, short answer, at easy, medium or hard difficulty, 5 to 50 questions
The part I care about most: every answer has to cite the chapter. Each question carries the exact sentence it came from, the code checks that sentence really is in the chapter, and the answer key prints it beside the answer. A wrong answer key costs a teacher their credibility in front of students, so accuracy beats quantity.
It runs Gemma 3 (4B) locally through Ollama, on the institute's own laptop. No API bill, no internet after setup, and the notes never leave the room.
Who it's for: coaching institute owners with 1–5 teachers and 50–500 students, and home tutors teaching several classes. In Patna that mostly means school boards (Bihar Board), BPSC, SSC and Railway exam prep.
Demo
The flow is four steps:
- Add the chapter (PDF, photos or pasted notes).
- Pick the number of questions, types, difficulty and language, then press Generate test · टेस्ट बनाएं.
- Review every question, with its ✅ answer and 📖 source line. Edit, delete or regenerate any of them.
- Tick "I have reviewed all questions" and download two PDFs: the student paper and the answer key.
Export stays locked until step 4. The app never prints a question the teacher hasn't seen.
Code
ThePlator
/
Coaching_Test_Generator-
Turn a chapter into a printable practice test in Hindi, English or both — with an answer key that cites the source line. Runs offline with Gemma via Ollama.
Coaching Test Generator · प्रश्न पत्र
Turn a chapter into a ready-to-print practice test in Hindi, English or both, with an answer key that shows where each answer comes from. It runs fully offline on your own laptop.
Built for small coaching institutes and home tutors preparing students for school boards, BPSC, SSC and Railway exams. Upload a chapter PDF, photos of book pages, or your own notes. Pick how many questions you want. A few minutes later you have a student paper and an answer key to print.
🏁 Built for the DEV Hacktoberfest Open-Source AI Challenge, Week 2 — "Side Hustle". Uses Gemma running locally through Ollama.
Why
- Writing 25 good questions for one chapter takes hours. Translating them for Hindi-medium students doubles the work.
- Paid question banks are generic and don't match your notes.
- Cloud AI tools charge per use, need good internet, and send your notes…
Setup is one script (scripts/setup.sh on Linux/macOS, scripts/setup.ps1 on Windows), or by hand:
ollama pull gemma3:4b
pip install -r requirements.txt
streamlit run app.py
How I Built It
| Part | Choice | Why |
|---|---|---|
| Model | Gemma 3 4B via Ollama | Open weights, runs on a laptop CPU, reads photos too |
| App | Python + Streamlit | Upload, review and edit on one page |
| Reading |
pypdf for text PDFs, Gemma vision for photos and scanned pages |
Many coaching notes are phone photos |
| Output checks | Pydantic + rapidfuzz | Catch broken JSON and made-up answers in code |
| Jinja2 + WeasyPrint, embedded Noto Sans Devanagari | Hindi has to print correctly |
There are already tools that turn notes into quizzes, like PageLM, and cloud question-paper generators built on Gemini and Document AI. What I wanted was narrower: one printed paper, in exam Hindi and English, where a teacher can verify every answer in seconds, on hardware they already own.
1. One small chunk at a time
The chapter is split into topic-sized chunks of about 1,500 characters, at headings and paragraph breaks. Gemma only ever sees one chunk and is told to use only facts from it. A small model hallucinates far less with a narrow context, and it gives every question exactly one piece of text to be checked against.
Gemma answers in JSON. Ollama's structured outputs take a JSON schema, so the model can't skip the Hindi block in bilingual mode or forget the source_quote. Hindi and English come from one call, so they share one answer_index by construction. Both versions always have the same correct letter, and the Hindi is written as exam Hindi, not translated word by word afterwards.
2. The check that matters: is the quote really in the chapter?
# ctg/textutil.py
def quote_score(quote: str, chunk: str) -> int:
"""0-100 score for how well `quote` appears in `chunk` (100 = exact substring)."""
q, c = norm(quote), norm(chunk)
if not q:
return 0
if q in c:
return 100
return round(fuzz.partial_ratio(q, c))
norm() does the Hindi-specific work. It applies Unicode NFC, strips zero-width joiners, maps । to ., and drops punctuation while keeping matras and the virama, so a quote with slightly different punctuation still matches. Below 90, the question fails as quote_not_found.
The same validator also checks for:
- exactly 4 distinct options, with the answer among them
- no "all of the above" (or उपरोक्त सभी / इनमें से कोई नहीं)
- Hindi that's actually in Devanagari
- matching option counts in Hindi and English
- a real
____in fill-in-the-blank questions
3. Retry once, then drop, and tell the teacher
# ctg/pipeline.py (trimmed)
k = math.ceil(c.quota * settings.overgen_factor) # ask for ~30% extra
cands, lost = generate_for_chunk(llm, c, expand_plan(plan, k, cfg.qtypes), cfg, ...)
good, failures = _screen(cands, c, cfg, settings, existing, report)
missing = c.quota - len(good)
if missing > 0: # retry ONCE for this chunk
cands2, lost2 = generate_for_chunk(..., feedback=failures[:FEEDBACK_LIMIT], ...)
good2, _ = _screen(cands2, c, cfg, settings, existing + good, report)
good += good2
return good[:c.quota]
The retry prompt tells Gemma exactly what failed ("source not found in chapter", "repeated options"). Anything still failing is dropped, and the review screen says so honestly, for example: "Kept 9 of 10 — dropped: 1 source not found in chapter".
4. A dedupe bug I'm glad I caught early
My first duplicate filter used rapidfuzz's token_set_ratio. It scored these two stems at 88, over my threshold:
- "Which Articles deal with the Right to **Equality?"
- "Which Articles deal with the Right to **Freedom?"
Set-based matching mostly ignores the one word that makes them different questions, and on an exam paper that word is the whole point. token_sort_ratio at 90 still catches real repeats and reordered wording, but keeps these apart.
5. Hindi that actually prints
Devanagari isn't just characters. Conjuncts like क्ष, त्र, श्र and matras need OpenType shaping, and drawing text without it can print broken Hindi. That's a disaster on a paper students will read. Rendering HTML through WeasyPrint gets shaping from HarfBuzz (via Pango), with Noto Sans Devanagari embedded in the PDF. On Windows, where WeasyPrint's GTK libraries are hard to install, the same HTML prints through Chromium instead.
Who Would Pay
These are the prices I'm testing:
| Plan | Who | Price |
|---|---|---|
| Free | Try it | 3 tests / month |
| Tutor | Home tutors | ₹199 / month |
| Institute | Coaching centres | ₹999 / month, unlimited, set up on their laptop |
| One-time setup | Institutes without tech help | ₹1,500 install + training |
The software itself is MIT-licensed. People pay for setup, support and not having to do it themselves, which is how a lot of small-town software actually gets bought. These prices only work because running cost is close to zero: the model runs on a laptop the institute already owns.
My First User
[FILL — after the session, from docs/first-user.md. Suggested shape:
- Who: a coaching teacher or tutor in Patna (name only with permission), the subject and exam they teach.
- They uploaded their own chapter and made a 10-question bilingual test in [time]. Normally that takes them [their answer].
- Of 10 questions: kept [k], edited [e], marked [w] wrong, and why.
- Their verdict on the Hindi.
- "Would you pay ₹199 a month? ₹999 for the institute?" Their exact words.
- What they asked for next.
- Photo of the printed paper (no student names).]
Why Does Open Innovation Matter?
For this business, open weights aren't a nice extra. They're what makes the price possible.
- Near-zero running cost. A cloud API bills every question, every week, for every teacher. On the institute's own laptop, the hundredth test costs the same as the first: nothing. That's the difference between ₹199 a month being a business and being a loss.
- The notes stay theirs. A teacher's notes are their competitive edge in a crowded coaching market. Here they never leave the laptop, and you can check that: turn off the Wi-Fi and it still works.
- Built for bad internet. Power cuts and patchy mobile data are normal. Once set up, this needs neither.
- Tunable for exam styles. Open weights mean the model can later be fine-tuned on BPSC/SSC-style questions written by teachers themselves, a niche a general-purpose API handles poorly.
-
No lock-in. The model is one setting (
CTG_MODEL). If a better open model comes out, or a smaller one runs faster on an old laptop, the institute switches without asking anyone.
Honest Limits
- Speed depends on the laptop. On a CPU-only machine, writing 10 bilingual questions takes [FILL — measured time]. Start with 10–15 questions.
- A 4B model still makes mistakes. That's why review is required and the key shows the source line. The checks catch made-up quotes, but not every awkward distractor.
- Text subjects only, for now. GK, history, polity, science theory, English and Hindi work. Maths with diagrams or long derivations doesn't.
- Photos are slower and less reliable than text PDFs or pasted notes.
- Tested with a stand-in model. The automated tests use a fake model so they run without Ollama. The real-model numbers above come from the first-user session.
Prize Categories
Best Use of Gemma. Gemma 3 4B writes every question in Hindi and English and reads photos of book pages and scanned PDFs, fully offline, on one laptop.
हर अध्याय के साथ, देर रात की मेहनत थोड़ी कम हो। (With every chapter, a little less late-night work.) 📝
— Sameer
來源:DEV Community · dev.to