Soma Physics is a Physics tutor built on Uganda's NCDC lower-secondary syllabus. It runs on one laptop, with no internet:

  • Gemma 4 E4B runs locally through Ollama. After setup, nothing leaves the laptop.
  • Learners join from their phones over the classroom hotspot. The phone is only a screen.
  • They can ask by text, photo or voice.
  • It gives a hint first. The full worked answer appears only when the learner asks for it.
  • Every answer cites the syllabus topic it came from.
  • A calculator tool does the arithmetic, and a second pass checks the working.
  • Teachers can ask for an activity: a real-life task set in rural Uganda, using cheap local materials.

We won Best Use of Gemma 4. 🏆

Hacktoberfest 2026 certificate: Best Use of Gemma 4, Hacktoberfest Hack Day Kampala x GDG on Campus Makerere University, October 17, 2026
Never let a small model do arithmetic. Gemma decides what to calculate. Python does the calculation. The final answer is told to use the calculator's numbers exactly, and the UI shows those results so a learner (or teacher) can check them.

Structure beats clever prompting. Every answer comes back as JSON with the same fields: hint, answer, worked_steps, citation, check_question. That is what lets the UI hide the answer behind a button and always show where the answer came from.

Accuracy costs time, and I chose accuracy. On my laptop (RTX 3050 6 GB GPU), a worked calculation takes about a minute. The tutor makes several Gemma calls in a row: one to solve with the calculator, one to write the answer, one to check it. I could drop the check to make it faster. But for a tutor, a fast wrong answer is worse than a slow right one. It also means I can't yet say it runs well on a cheap school laptop. Testing that is next.

Small models love Markdown and LaTeX. If you look closely at the screenshots below, you'll see raw **bold** and $\frac{...}{...}$ in places. Gemma writes them, and my no-build UI shows them as plain text. The fix is either to render them or to ask the model for plain text only.

Hackathon setup bites. Partway through the day, ollama pull gemma4:e4b failed because my Ollama was too old for Gemma 4. Update your tools before the event, not during it.

Demo

🎥 Watch the demo video

💻 Code (MIT): github.com/blackbody256/soma-physics

The screenshots below are from a fresh run of the app, fully offline, using local Gemma 4 E4B.

Soma Physics home screen on a laptop: "Ask a question. Find the physics." with three starter questions and buttons for photo, voice and activity

A worked calculation. The learner gets a hint first. "Show full answer" reveals the working, the calculator results, a question to test themselves, and the syllabus topic. Answers like this take about a minute on my laptop.

Left: the learner's question and a hint. Right: the full answer with working, calculator results, a test-yourself question and the Topic 1 citation

An activity and voice input. I asked for an activity on heat transfer. It wrote a task about keeping a village cooking pot warm with clay, sand and foil. Voice questions are recorded on the phone and transcribed on the laptop.

Left: an activity of integration about saving heat when cooking in a village. Right: the voice recording state with "Stop and send" and a listening indicator

Partner Technologies

The whole project is built on Google's Gemma 4, run locally through Ollama. We also used the Gemini API to run a hosted Gemma 4 model from the same code. Here is how each piece works.

One local model for text, images and audio

Gemma 4 E4B is small enough to run on a laptop GPU, and it takes text, images and audio. So one model, gemma4:e4b in Ollama, handles all three ways of asking:

  • Text goes straight into the tutoring pipeline.
  • Photo: the phone shrinks the image, and Gemma 4 first reads the question out of it. The extracted question then goes through the same pipeline as text.
  • Voice: ffmpeg converts the recording to 16 kHz WAV, and Gemma 4 transcribes it. If audio input fails, it falls back to faster-whisper, which also runs locally.

Grounding answers in the syllabus

We load pages of the NCDC Physics syllabus PDF with PyMuPDF. If a page's text comes out garbled, Gemma 4 reads the page as an image instead. The chunks are embedded with EmbeddingGemma and stored in SQLite, alongside an FTS5 keyword index as a fallback.

When a question comes in, the closest chunks are retrieved. If none scores above a threshold, the tutor kindly says the question is outside the syllabus instead of guessing.

Hint first, calculator always, then a check

Gemma 4 answers in a fixed JSON schema (passed to Ollama's format=). For calculation questions, it first solves the problem with thinking turned on and a calculate tool. The tool is a small safe calculator: it parses the expression with Python's ast and allows only + - * / **.

def solve_with_tools(question, context, provider=LOCAL): messages = [ {"role": "system", "content": SOLVER_PROMPT}, {"role": "user", "content": f"SYLLABUS CONTEXT:\n{context}\n\nQUESTION: {question}"}, ] results = [] for _ in range(5): msg = chat(provider=provider, messages=messages, tools=[calculate], think=USE_THINKING, options=CALC_OPTIONS).message if not msg.tool_calls: return msg.content or "", results messages.append({"role": "assistant", "content": msg.content or "", "tool_calls": msg.tool_calls}) for call in msg.tool_calls: expr = str((call.function.arguments or {}).get("expression", "")) out = calculate(expr) results.append(f"{expr} = {out}") messages.append({"role": "tool", "content": out, "tool_name": call.function.name}) return "", results 

The calculator results are passed into the final answer prompt as CALCULATOR RESULTS (use exactly). Then a self-check call at low temperature (0.2) compares the worked steps against those results. If they disagree, the learner sees a warning with the correction.

Gemini API: the same harness on a bigger Gemma

To prototype quickly, we added a dropdown that switches from local Gemma to Gemma 4 26B A4B hosted on the Gemini API (using the google-genai SDK). We didn't want two copies of the tutoring logic, so model_router.py translates Ollama-style messages into Gemini API content. That includes images and tool calls, which become Part.from_function_call and Part.from_function_response. The calculator loop, the JSON schema and the self-check all run unchanged on either model.

Cloud mode is off unless the server has a GEMINI_API_KEY. The UI warns that cloud mode sends the question and photo to Google, while voice transcription and retrieval stay on the laptop.

An Agent Skill for the teaching rules

The teaching rules live in skills/ncdc-physics-tutor/SKILL.md, written in the open Agent Skills format. They include: short sentences (English is many learners' second language), SI units in every step, everyday Ugandan examples, and a hint before the answer. The same tutor behaviour can then be reused in other agent harnesses, not just this app.

Hackathon Experience

On 17 October 2026, we joined Hacktoberfest Hack Day Kampala, hosted by GDG on Campus Makerere University, powered by MLH × DEV, with DigitalOcean as presenting partner. This year Hacktoberfest focused on open-source AI. The question we set ourselves was simple: what can we build with an open model that actually helps a student in Uganda?

The day moved fast. We started by getting the pipeline running: loading syllabus pages, pulling the models, and fighting the Ollama version error. Then the first answer took over a minute, even with a GPU, and we had to decide whether to keep the self-check. We kept it. The afternoon and evening were a run of small commits: the mobile UI, photo and voice input, the name and new look, the local/cloud switch, conversation memory, and a recording animation so learners can see the app is listening. The last commit, at 19:40, added the demo video to the README.

What I'll remember most is that the idea came from home. It wasn't a generic AI demo. It came from a real gap I know from studying Physics here. Being named Best Use of Gemma 4 for something built around Uganda's own syllabus meant a lot.

Thank you to GDG on Campus Makerere University and MLH for running the Hack Day, to Tugume Keith for leading it, and to Terence for building this with me.

Soma Physics is still early. The next step is testing it with real learners and teachers, on the kind of laptops schools actually have. If you teach Physics or work with schools in Uganda, I'd love your feedback. Open an issue on the repo or message me.

mlhacks