# CropGuard GH — Standalone HTML App Documentation
**The self-contained, single-file browser application.**
Final Year Project · Oppong David · BTech Computer Technology, Kumasi Technical University
---
## 1. What this is
A complete crop disease detection front end in **one HTML file** — no install, no build step, no server required to open it. A user takes or chooses a photo of a crop leaf and immediately gets a disease name, a confidence score, a severity level (with colour), an urgency level, ordered treatment steps and suggested products.
It is the most accessible deliverable in the project: email the file, host it on any static link, or open it straight from a phone's storage. It works on a basic Android phone with no app-store download.
### The three files
| File | Language | Notes |
|---|---|---|
| `cropguard.html` | **Bilingual** | English ⇄ Twi toggle in the header. This is the main app. |
| `cropguard-en.html` | English only | Same app, no toggle — for English-only deployment. |
| `cropguard-tw.html` | Twi only | Same app, no toggle — for Twi-only deployment. |
All three are byte-for-byte self-contained: HTML, CSS and JavaScript in a single file, fonts from Google Fonts, no other external dependencies.
### Coverage
14 Ghanaian crops, 55 disease/healthy classes: maize, cassava, tomato, cocoa, cashew, plantain, yam, pepper, cowpea, groundnut, rice, okra, garden egg, mango.
---
## 2. How to use it
1. **Open** the file in any modern browser (phone or computer) — double-click it, or host it and visit the link.
2. **Take a photo** ("Take a photo of a leaf") or **Choose from gallery**. On a phone the camera button opens the rear camera directly.
3. **Check the photo** on the preview screen — the app reminds the user to fill the frame with the diseased leaf in good light — then tap **Analyse crop**.
4. **Read the result:** crop + disease, confidence bar, severity badge (green/amber/red), urgency, a numbered treatment list (most urgent first), suggested products and a short "about this disease" note.
5. **Scan another leaf** or **Share result** (uses the device share sheet, or copies to clipboard).
A **Help** sheet on the home screen explains all of this to first-time users, in the selected language.
---
## 3. The four-screen flow
The app is a single-page application with four screens (`home → preview → loading → result`) toggled by a small `show()` function — there is no routing library and no page reload.
```
HOME ──tap camera/gallery──▶ PREVIEW ──tap Analyse──▶ LOADING ──result ready──▶ RESULT
▲ │
└───────────────────────────── "Scan another leaf" ────────────────────────────┘
```
---
## 4. How the diagnosis works — two modes
The app is designed to **never be broken**, so it has two inference paths and picks automatically:
### Mode A — Connected to the trained model (accurate)
If an API URL is configured, the app sends the photo to the backend (`POST /predict`) and shows the real CNN prediction. This is the accurate mode and the one to use for real diagnosis. Set it by either:
- running `localStorage.setItem('cropguard_api', 'https://your-server:8000')` in the browser console, or
- hosting the app and pointing it at your deployed FastAPI server (see the backend documentation).
The footer shows **"Connected to AI model"** with a live dot when an API URL is set.
### Mode B — On-device estimate (offline fallback)
When **no** API URL is set, the app runs a genuine on-device image analysis in JavaScript using an HTML `