RootFacts is a Progressive Web App (PWA) that combines two on-device AI technologies:
- π Computer Vision β Real-time vegetable detection via camera using TensorFlow.js
- π¬ Generative AI β Unique fun facts generated for each detected vegetable using Transformers.js
All AI inference runs 100% in the browser β no backend server, no data sent to the cloud. Works fully offline after the first load.
Built as a submission for Dicoding β Belajar Penerapan AI di Aplikasi Web
| Feature | Details |
|---|---|
| Detects 18 vegetables | Beetroot, Carrot, Cucumber, Garlic, Ginger, Spinach, and more |
| Adaptive Backend | Auto-selects WebGPU β WebGL β CPU |
| Configurable FPS Limit | UI slider from 15β60 FPS to balance performance |
| Real-time Loading Indicator | Progress bar 0β100% during model initialization |
| Memory Management | tf.tidy() on every prediction cycle |
| Feature | Details |
|---|---|
| Dynamic Fun Facts | Unique fact generated per detected vegetable |
| 5 Dynamic Personas | Normal Β· Funny Β· Professional Β· Historical Β· Kids |
| Tuned Parameters | temperature, top_p, max_new_tokens, do_sample |
| Copy to Clipboard | One-click copy with toast notification |
| Share | Native Share API (mobile) / WhatsApp & Telegram (desktop) |
| Adaptive Backend | WebGPU β WASM (self-hosted, offline-safe) |
| Feature | Details |
|---|---|
| Web App Manifest | Complete with 10 icon sizes + 2 screenshots |
| Service Worker | Workbox generateSW with precaching |
| Offline TF Model | model.json + weights.bin precached via Workbox |
| Self-hosted WASM | ONNX .wasm files served from /public/wasm/ |
| Installable | Install button appears in browser address bar |
| Offline Banner | Auto-shown when connection is lost |
| Deployed | β Live on Vercel |
| Technology | Version | Purpose |
|---|---|---|
| React | 19.x | UI Framework |
| Vite | 6.x | Build tool & dev server |
| TensorFlow.js | 4.x | On-device Computer Vision |
| @xenova/transformers | 2.x | On-device Generative AI |
| vite-plugin-pwa | 1.x | PWA & Service Worker generation |
| Workbox | 7.x | Caching strategies |
| SweetAlert2 | 11.x | Loading modals & toast notifications |
| Lucide React | 0.5x | UI icons |
RootFacts/
βββ public/
β βββ icons/ # PWA icons (72px to 512px + apple-touch-icon)
β βββ model/ # TensorFlow.js model files (model.json + weights.bin)
β βββ screenshots/ # PWA screenshots (wide + narrow)
β βββ wasm/ # Self-hosted WASM files (ort-wasm.wasm etc.)
β βββ favicon.ico
β βββ manifest.json # Web App Manifest
βββ src/
β βββ components/
β β βββ CameraSection.jsx # Camera feed + FPS slider + persona dropdown
β β βββ Header.jsx # App header + model status indicator
β β βββ InfoPanel.jsx # Detection result + fun fact card
β βββ hooks/
β β βββ useAppState.js # Global state management (useReducer)
β β βββ useOnlineStatus.js # Online/offline connection detector
β βββ services/
β β βββ CameraService.js # MediaStream API + FPS limiter
β β βββ DetectionService.js # TensorFlow.js inference + adaptive backend
β β βββ RootFactsService.js # Transformers.js inference + persona system
β βββ utils/
β β βββ common.js # Shared utility functions
β β βββ config.js # App configuration constants
β β βββ ui.js # UI helper utilities
β βββ App.jsx # Main orchestrator component
β βββ index.css # Global styles
β βββ main.jsx # React entry point
β βββ sw.js # Service Worker (Workbox template)
βββ copy-wasm.js # Script: copies WASM files to public/wasm/
βββ vite.config.js # Vite + PWA plugin configuration
βββ eslint.config.mjs # ESLint configuration
βββ index.html # HTML entry point
βββ package.json
βββ STUDENT.txt # Deployment URL (Dicoding requirement)
- Node.js v18+
- npm v9+
git clone https://github.com/ranggautama47/RootFacts.git
cd RootFactsnpm installnode copy-wasm.jsThis copies
.wasmfiles fromnode_modules/@xenova/transformers/dist/topublic/wasm/so Transformers.js never needs to fetch from a CDN when offline.
npm run dev
β οΈ Note: The Service Worker is disabled in dev mode. To test PWA and offline features, use the production preview below.
npm run build
npm run previewnpm run lint- Open
http://localhost:4173in Chrome or Edge - DevTools β Application β Manifest
- Confirm: app name, icons, theme color, and start URL are all shown β
- Look for the Install button in the address bar β click β confirm
- Open the app online and wait for both models to finish loading
- DevTools β Network β check Offline
- Refresh the page β app still opens β
- Vegetable detection still works (model served from cache) β
DevTools β Application β Cache Storage should show:
workbox-precache-v2β HTML, CSS, JS, iconstensorflow-model-v1β TF.js model fileshf-model-cache-v1β Transformers.js model files
- First online load required β The AI model (~80MB) is downloaded from HuggingFace and cached in the browser on first use
- After caching β The app runs fully offline including vegetable detection and fun fact generation
- COOP/COEP headers β Required for WebGPU and SharedArrayBuffer; already configured in
vite.config.jsandnetlify.toml
Rangga Utama
- GitHub: @ranggautama47
- Project: root-facts.vercel.app
This project was built for the Dicoding β Belajar Penerapan AI di Aplikasi Web course submission.