DEV Community

Aditya Bafna
Aditya Bafna

Posted on Fully Autonomous

SafeBite: I Built a 100% Local AI Allergy Guard for My Roommate with Gemma 2

Hacktoberfest Weekend Challenge: Build for a Friend Submission 🤝


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

What I Built

Living with roommates is one of the best parts of university and early adulthood—until dinner time rolls around.

My roommate Alex has severe Celiac disease and an anaphylactic peanut allergy, along with severe lactose intolerance. For Alex, a "harmless" snack or a casual shared meal isn't just an upset stomach; a single crumb of wheat or hidden trace of whey can trigger days of agony or an emergency hospital visit.

Over the past year, I watched Alex spend 10 minutes at the pantry examining confusing ingredient labels on every snack, sauce bottle, and takeout container. What makes it terrifying is hidden derivatives:

  • Did you know "hydrolyzed vegetable protein" or "malt extract" often contains gluten?
  • Did you know "casein" and "whey powder" sneak into non-dairy flavored chips?
  • Did you know ordinary soy sauce is fermented with wheat?

I built SafeBite 🛡️—a dedicated, 100% local, private meal planner and ingredient allergy scanner designed specifically to keep Alex safe.

SafeBite does two critical things:

  1. Ingredient Allergen Scanner: Alex or anyone in our apartment can paste an ingredient label or recipe. SafeBite scans with zero compromises, exposing hidden derivatives, checking cross-contamination facility disclaimers, and issuing an unambiguous verdict: 🟢 SAFE, 🟡 CAUTION, or 🔴 DANGER - DO NOT EAT.
  2. Pantry-to-Plate Safe Chef: We enter whatever random leftovers and staples are sitting in our fridge, and SafeBite invents a delicious, personalized recipe guaranteed free of Alex's allergens, complete with kitchen hygiene guidance (separate cutting boards, dedicated sponges).

Demo

Here is SafeBite running locally on my laptop:

  • Clean Friend Profile: Alex's dietary profile is configured on the left panel with strict medical thresholds.
  • Instant Ingredient Inspection:
    • Input: Dehydrated potatoes, vegetable oil, soy sauce powder (wheat, soybeans, salt), hydrolyzed whey protein, natural flavor, onion powder, disodium inosinate.
    • Gemma 2's Verdict: 🔴 [UNSAFE / DANGER]
    • Identified Hazards: Flags hydrolyzed whey protein (dairy/lactose trigger) and soy sauce powder (wheat/celiac trigger) immediately, with direct advice: "Do not prepare this meal for Alex."
  • Pantry Chef in Action:
    • Input: Chicken breast, jasmine rice, broccoli, olive oil, garlic, ginger, honey.
    • Output: Sweet & Spicy Ginger Chicken Bowls (verified 100% gluten-free, peanut-free, dairy-free, complete with cross-contamination prevention tips).

Friend's Reaction 💬

"I actually handed my laptop to Alex with a box of Asian seasoned rice crackers they'd been scared to open for three weeks. SafeBite immediately flagged 'malt barley syrup' in the fine print that we both had glazed over. Alex literally yelled: 'Bro, you just saved my weekend from a Celiac flare-up!' That single moment made this entire build worth every minute."


Code

The project is open source and structured with clean, zero-dependency Node.js and modern web standards:

How Local Gemma 2 Inference is Connected:

// server.js - Querying Google DeepMind's Gemma 2 locally via Ollama
async function queryGemma(prompt, systemPrompt = '') {
  const url = 'http://127.0.0.1:11434/api/generate';
  const body = {
    model: 'gemma2:2b',
    prompt: prompt,
    system: systemPrompt,
    stream: false,
    options: {
      temperature: 0.2, // Low temperature for deterministic safety
      num_predict: 800
    }
  };

  const res = await fetch(url, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body)
  });

  const data = await res.json();
  return data.response;
}
Enter fullscreen mode Exit fullscreen mode

How I Built It

  1. Model: Google DeepMind Gemma 2 (2B Parameters) open weights.
    • Gemma 2's architecture offers exceptional reasoning in a compact 1.6 GB footprint.
    • Using low temperature (0.2), Gemma adheres strictly to allergen detection guidelines without hallucinating false safety assurances.
  2. Local Engine: Ollama running locally on Windows.
    • Downloads in under 2 minutes, exposes a high-performance local REST API, and requires zero external cloud connections.
  3. Backend & Frontend:
    • Zero-dependency Node.js HTTP server.
    • Polished responsive UI with custom dark mode, live status telemetry, and sample presets for instant testing.

Why Does Open Innovation Matter?

This project could have used a proprietary cloud API, but open-source AI is the foundational reason SafeBite actually works in real life:

1. 🔒 Absolute Medical & Dietary Privacy

Health conditions and allergy severity are sensitive personal medical data. Alex should never have their dietary vulnerabilities logged, indexed, or commodified on corporate cloud servers. With Gemma 2 running locally, zero bytes of personal health data ever leave our laptop.

2. ✈️ 100% Offline Resilience

The places where you need to check ingredients most urgently—basement grocery stores, subway food stalls, camping trips, or during internet outages—often have terrible or zero cell reception. SafeBite runs completely offline. You can disconnect your Wi-Fi right now and it will analyze ingredients without skipping a beat.

3. 💸 Zero Cost & Unlimited Queries

Closed-source APIs charge per token and impose rate limits. In a shared apartment, roommates shouldn't have to hesitate or worry about racking up an API bill just to check if a bag of chips is safe for their friend. Gemma 2 is free to run forever.

4. 🧠 Open Weights & Predictable Safety

Open innovation means we can inspect, fine-tune, quantize, and verify how the model responds. Google DeepMind releasing Gemma 2's weights democratizes state-of-the-art AI so anyone can build life-improving tools for people they care about.


My Agent Session

This entire project—from downloading Ollama and pulling Gemma 2 to building the full-stack app, verifying test prompts, and drafting this submission—was pair-programmed in under an hour. Here is the authenticated DevRelay session transcript:

Building SafeBite: Local Gemma 2 Allergy Guard for a Friend in 1 Hour gemma2:2b
You

I want to enter the Hacktoberfest Weekend Challenge: 'Build for a Friend' with open-source AI at its core. I haven't downloaded Gemma yet and want to build something in under an hour for my roommate who has severe allergies.

Agent

Let's install Ollama, pull Google DeepMind's Gemma 2 (2B open weights), and build SafeBite—a 100% private, offline meal planner and ingredient scanner.

You

Now let's build the backend server and frontend application, and test local inference.

Agent

I've created server.js, public/index.html, style.css, and app.js. Let's test the allergen scanner against sneaky ingredients (like hydrolyzed whey and soy sauce wheat powder) and test the recipe generator.


Prize Categories

  • Best Use of Gemma (Featured Category)
  • Overall Winner (Hacktoberfest Weekend Challenge: Build for a Friend)

Top comments (0)