DEV Community

Cover image for Solace: A Global Mental Health First Responder Built with Gemma 4
OLALEKAN OGUNDIMU
OLALEKAN OGUNDIMU

Posted on

Solace: A Global Mental Health First Responder Built with Gemma 4

Gemma 4 Challenge: Build With Gemma 4 Submission

The Problem Nobody Talks About

970 million people worldwide live with mental health disorders.

But almost every mental health tool built with AI assumes the same user: fast internet, English as a first language, a US or UK phone number to call in a crisis.

That's not 970 million people. That's maybe 50 million.

I'm a developer based in Lagos, Nigeria. When I looked at the mental health AI tools being built, I kept asking the same question: what happens when someone in Accra, Nairobi, Manila, or São Paulo needs help at 2am?

They get a chatbot that tells them to call 988.

That's the gap Solace was built to close.

What is Solace?

Solace is a voice-first, privacy-focused mental health companion powered by Gemma 4. It listens, assesses, and connects people to real help — wherever they are in the world.

🔗 Live app: https://slcai-sm9m.vercel.app/

💻 GitHub: https://github.com/sam-the-champ/SLCAI

Demo Video:

What makes Solace different

1. 🌍 Localized crisis resources for 13+ countries

Most mental health AI tools are built with US resources baked in. If you're not American, you're on your own.

Solace auto-detects your country from your browser timezone and immediately surfaces the right crisis lines, text lines, and chat services for Nigeria, Ghana, Kenya, South Africa, Zimbabwe, India, UK, USA, Canada, Australia, Philippines, Singapore, Brazil — and falls back to international resources for everywhere else.

No settings. No configuration. It just knows.

export function getResourcesByTimezone(): CountryResources {
  const tz = Intl.DateTimeFormat().resolvedOptions().timeZone
  const tzToCountry: Record<string, string> = {
    'Africa/Lagos': 'NG',
    'Africa/Accra': 'GH',
    'Africa/Nairobi': 'KE',
    // ...13+ countries
  }
  const code = tzToCountry[tz]
  return resourcesByCountry[code] ?? resourcesByCountry.DEFAULT
}
Enter fullscreen mode Exit fullscreen mode

2. 🎤 Voice-first input

When someone is in distress, typing is a barrier. Solace has a one-tap voice input powered by the Web Speech API — speak your feelings, Solace listens.

No third-party API. No extra cost. Works in the browser natively.

const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition
recognition.continuous = true
recognition.interimResults = true
Enter fullscreen mode Exit fullscreen mode

3. 🧠 Trauma-informed triage with Gemma 4

Every message is assessed across four triage levels: Low → Moderate → High → Crisis.

Gemma 4's 128K context window and deep instruction-following made it the right model for this. The system prompt is carefully crafted to avoid clinical coldness while still being precise enough to catch crisis signals:

// Triage levels:
// low: mild everyday stress, general worry
// moderate: persistent sadness, sleep issues, social withdrawal  
// high: panic attacks, trauma symptoms, major crisis
// crisis: suicidal ideation, self-harm, immediate danger
Enter fullscreen mode Exit fullscreen mode

At crisis level, the entire UI shifts — emergency resources move to the top, the call button becomes prominent, and the AI's tone changes to prioritize connection to real help over conversation.

4. 📔 Private mood journal

Every check-in is saved to a local mood journal — stored entirely in localStorage. No server. No account. No data leaving the device.

Users can track patterns across sessions: when they tend to feel worse, whether things are improving, what their check-ins look like over time.

5. 📱 Installable PWA

Solace is a Progressive Web App. On mobile, users can install it directly to their home screen — no app store, no download, works in low-bandwidth conditions.

This matters enormously in markets like Nigeria where data costs are high and storage is limited. A 2MB installable app beats a 200MB download every time.

Why Gemma 4 specifically?

This is the question that matters most, so let me be direct.

I chose Gemma 4 31B because:

1. The 128K context window means Solace can hold a full therapeutic conversation — not just one or two turns. Mental health support isn't transactional. People circle back. They contradict themselves. They need to feel heard across a long exchange.

2. Instruction-following precision — the triage system depends on Gemma 4 returning structured JSON reliably, with emotional nuance baked into the summary, patterns, strategies, and affirmation fields. I tested with smaller models. The quality gap was significant.

3. It's open. Gemma 4 can be self-hosted. That means a clinic in Lagos or a NGO in Nairobi could eventually run this on their own infrastructure, with no API costs and full data sovereignty. That's a future worth building toward.

4. Privacy story. Every conversation stays between the user and the model. Solace doesn't log, store, or transmit conversation data. For mental health, that's not a feature — it's a requirement.

Technical Stack

  • Frontend: React + Vite + TypeScript
  • Styling: CSS custom properties, glassmorphism UI, no component library
  • AI: Gemma 4 31B via OpenRouter
  • Voice: Web Speech API (native browser)
  • Storage: localStorage (journal, no server)
  • PWA: Web App Manifest + service worker ready
  • Deploy: Vercel

The hardest part

Building the crisis response flow was the hardest and most important part of this project.

When Gemma 4 returns triageLevel: "crisis", everything changes. The UI shifts to red. The emergency number for the user's country moves above the fold. The AI's system prompt switches to a mode focused entirely on staying present and bridging to real help — not providing therapy.

Getting that balance right — compassionate but not clinical, urgent but not alarming — took more iteration than anything else in the codebase.

What's next

  • Offline-first fallback responses — cached grounding techniques that work with no internet
  • More languages — French, Hausa, Swahili, Portuguese
  • More countries — currently 13, targeting 30+
  • NGO partnership mode — white-label for mental health organizations

Try it

🔗 https://slcai-sm9m.vercel.app/

Open it on your phone. Tap a mood. Speak how you're feeling. See what country resources appear for you.

If you're building in the mental health space or you work with communities that are underserved by current AI tools — I'd love to hear from you in the comments.

Solace is an AI companion, not a therapist or medical service. If you are in crisis, please contact your local emergency services.

Top comments (1)

Collapse
 
tanimola_david_2c0b0ddcaf profile image
Tanimola David

Great Job Well done 🙌