A PWA that helps low-literacy users fill forms and understand contracts — powered by Gemma 4 via the Gemini API.
Built for the dev.to Gemma 4 Challenge.
- 📝 Voice-guided form filling — asks one question at a time, validates answers, works with your voice
- ⚖️ Document comparison — upload two T&Cs, get a plain-language side-by-side breakdown using Gemma 4's thinking mode
- 🔍 Explain any clause — tap any difference to get a 3rd-grade explanation read aloud
- 💬 Streaming chat — ask anything about your documents, answers stream in real time
- 📲 PWA — installable, works offline for cached content
- 🖼️ Native image/PDF input — passes scanned forms directly to Gemma 4 vision (no OCR needed)
- 🔒 Server-side API key — key lives in Vercel environment variables, never exposed to the browser
| Layer | What |
|---|---|
| Frontend | React 18 + Vite |
| Styling | Tailwind CSS (Syne + Instrument Sans fonts) |
| AI | Gemma 4 (gemma-4-26b-a4b-it) via Gemini API |
| Proxy | Vercel Edge Function (/api/gemma.js) |
| PWA | vite-plugin-pwa + Workbox |
| Storage | IndexedDB (documents) + localStorage (progress) |
| Speech | Web Speech API (STT) + SpeechSynthesis (TTS) |
| pdf.js (text extraction + page rendering) |
- Uses
gemma-4-26b-a4b-it(MoE) for most calls — best efficiency/quality ratio - Uses
gemma-4-31b-it(dense) for T&C comparison — heavier reasoning task - Thinking mode enabled for document comparison (
thinkingBudget: 1024) - Native system prompt support — Gemma 4's
system_instructionfield used properly - Streaming for chat — answers appear word by word for a natural feel
- Native vision — images and scanned PDFs sent directly to the model, no Tesseract
- Temperature 1.0 enforced when thinking mode is on (required by the API)
- JSON mode for structured outputs (field extraction, comparisons)
git clone https://github.com/yourusername/clearform
cd clearform
npm install- Go to Google AI Studio
- Click Get API Key → Create new key
- Make sure Gemma 4 models are available in your region
Create .env.local:
GOOGLE_AI_KEY=your_key_here
Start the Vercel dev server (needed to run the API proxy locally):
npx vercel devDo not use
npm run devalone — it won't run the/api/gemma.jsproxy.
If you just want to test the frontend, you can temporarily hardcode the key inapi/gemma.js(never commit this).
npm install -g vercel
vercel login
vercel- Go to your project in the Vercel dashboard
- Settings → Environment Variables
- Add:
- Name:
GOOGLE_AI_KEY - Value: your Google AI Studio key
- Environments: Production, Preview, Development
- Name:
- Redeploy
clearform/
├── api/
│ └── gemma.js # Vercel Edge Function — API proxy (key lives here)
├── src/
│ ├── App.jsx # Root + tab navigation
│ ├── components/
│ │ ├── FormFiller.jsx # Step-by-step voice form filling
│ │ ├── TCCompare.jsx # Document comparison + explain
│ │ ├── ChatWindow.jsx # Streaming conversational chat
│ │ ├── DocumentUploader.jsx # Drag-drop PDF/image upload
│ │ ├── VoiceInput.jsx # Mic button + Web Speech API
│ │ ├── ProgressIndicator.jsx
│ │ └── InstallPrompt.jsx # PWA install banner
│ ├── hooks/
│ │ ├── useGeminiAPI.js # All Gemma 4 API calls + streaming
│ │ ├── useSpeechRecognition.js
│ │ ├── useTTS.js
│ │ └── useOfflineCache.js # IndexedDB + localStorage
│ └── utils/
│ ├── prompts.js # All Gemma 4 prompt templates
│ ├── documentParser.js # PDF text + image extraction
│ └── validators.js # Field validation
├── vercel.json
└── vite.config.js
- All interactive elements have
aria-label aria-liveon dynamic content (questions, chat, errors)- Keyboard navigable with visible focus rings
- Respects
prefers-reduced-motion forced-colors(high contrast) supported- Font sizes use
rem— respects user browser font settings - Voice fallback for every action
- The Google AI key is stored only in Vercel environment variables
- The
/api/gemma.jsedge function proxies all requests — the key is never in the client bundle - No user data is sent to any third party beyond the Gemini API (no analytics, no tracking)
- Documents are stored locally in IndexedDB only
MIT