Your Secrets Stay on Your GPU: Building a Private, Local Mental Health AI with WebLLM and React A developer built a private, local mental health AI assistant using WebLLM and React, running Llama-3-8B entirely on the user's GPU via WebGPU. The approach ensures sensitive data never leaves the device, eliminating server-side privacy risks. The project demonstrates local-first LLM execution in the browser for privacy-preserving AI applications. Privacy is the final frontier of the AI revolution. When it comes to sensitive topics like mental health , users are rightfully hesitant to send their deepest thoughts to a distant server. This is where Edge AI , WebLLM , and WebGPU change the game. In this tutorial, we are building a "Zero-Knowledge" style mental health assistant. By leveraging privacy-preserving AI and local LLM execution , we ensure that sensitive data never leaves the user's device. We’ll be using WebLLM to run Llama-3-8B directly in the browser, accelerated by WebGPU , and managed via a React frontend. If you've been looking for a way to implement local-first LLMs or want to understand how to bridge Wasm and WebGPU for production apps, you're in the right place. 🚀 Traditional AI apps follow a Client-Server model. Our approach flips the script. The browser becomes the inference engine. php graph TD A User Input: Sensitive Query -- B{React UI State} B -- C WebLLM Engine C -- D WebGPU / Wasm Runtime D -- E Local GPU - Llama-3-8B E -- D D -- C C -- F Generated Response F -- B B -- G IndexedDB: Encrypted History subgraph Browser Environment B C D E G end style Browser Environment fill: f9f,stroke: 333,stroke-width:2px By keeping the inference on the local GPU , we eliminate latency after the initial model load and, more importantly, we eliminate the risk of data breaches at the transport or server level. Before we dive into the code, ensure your environment meets these requirements: The heart of our application is the MLCEngine . It handles the orchestration between the model weights, the WebGPU pipeline, and the user's prompt. js import { CreateMLCEngine, MLCEngine } from "@mlc-ai/web-llm"; // We use Llama-3-8B-Instruct for high-quality psychological nuances const selectedModel = "Llama-3-8B-Instruct-v0.1-q4f16 1-MLC"; export async function initializeEngine onProgress: progress: number = void { const engine = await CreateMLCEngine selectedModel, { initProgressCallback: report = { // Track download progress of the 5GB+ model onProgress Math.round report.progress 100 ; }, } ; return engine; } Since loading an LLM is expensive, we want to maintain a single instance across our app using React Context. python import React, { createContext, useContext, useState } from 'react'; import { MLCEngine } from "@mlc-ai/web-llm"; const AIContext = createContext<{ engine: MLCEngine | null, loading: boolean } | null null ; export const AIProvider: React.FC<{ children: React.ReactNode } = { children } = { const engine, setEngine = useState