Skip to content

ranggautama47/RootFacts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌿 RootFacts β€” AI Vegetable Detection & Fun Facts

RootFacts Logo

Scan vegetables with your camera. Get AI-powered fun facts instantly.

Live Demo

React TensorFlow.js Transformers.js PWA Vite Netlify


πŸ“– About

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


✨ Features

πŸ€– Criteria 1 β€” Computer Vision (TensorFlow.js)

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

πŸ’‘ Criteria 2 β€” Generative AI (Transformers.js)

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)

πŸ“± Criteria 3 β€” PWA & Offline Capability

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

πŸš€ Live Demo

πŸ”— root-facts.vercel.app


πŸ› οΈ Tech Stack

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

πŸ“‚ Project Structure

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)

βš™οΈ Getting Started

Prerequisites

  • Node.js v18+
  • npm v9+

1. Clone the repository

git clone https://github.com/ranggautama47/RootFacts.git
cd RootFacts

2. Install dependencies

npm install

3. Copy WASM files for offline support

node copy-wasm.js

This copies .wasm files from node_modules/@xenova/transformers/dist/ to public/wasm/ so Transformers.js never needs to fetch from a CDN when offline.

4. Run development server

npm run dev

Open http://localhost:5173

⚠️ Note: The Service Worker is disabled in dev mode. To test PWA and offline features, use the production preview below.

5. Build & preview production (required for PWA testing)

npm run build
npm run preview

Open http://localhost:4173

6. Lint

npm run lint

πŸ§ͺ Testing the PWA

Verify Manifest & Install

  1. Open http://localhost:4173 in Chrome or Edge
  2. DevTools β†’ Application β†’ Manifest
  3. Confirm: app name, icons, theme color, and start URL are all shown βœ…
  4. Look for the Install button in the address bar β†’ click β†’ confirm

Test Offline Mode

  1. Open the app online and wait for both models to finish loading
  2. DevTools β†’ Network β†’ check Offline
  3. Refresh the page β€” app still opens βœ…
  4. Vegetable detection still works (model served from cache) βœ…

Verify Cache Storage

DevTools β†’ Application β†’ Cache Storage should show:

  • workbox-precache-v2 β€” HTML, CSS, JS, icons
  • tensorflow-model-v1 β€” TF.js model files
  • hf-model-cache-v1 β€” Transformers.js model files

πŸ“ Notes

  • 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.js and netlify.toml

πŸ‘€ Author

Rangga Utama


πŸ“„ License

This project was built for the Dicoding β€” Belajar Penerapan AI di Aplikasi Web course submission.

About

🌿 Real-time vegetable detection with AI-powered fun facts. Built with TensorFlow.js, Transformers.js & React as a PWA β€” works fully offline.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages