Dataset Viewer

The dataset viewer is not available because its heuristics could not detect any supported data files. You can try uploading some data files, or configuring the data files location manually.

YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

Naija Waste Bot

Community reporting of illegal dump sites in Nigeria via Telegram, a public map, and an installable offline-first PWA. Zero-budget, open-source: photo + GPS pin (or typed landmark) + category + description/voice note → SQLite → trackable report codes, verified by volunteer moderators, cleaned up by community claimers with photo proof.

Inspired by CleanSweep, TrashOut, Delta Waste Tracker, StreetGov and similar tools — built to be runnable by one volunteer on a free-tier VPS.

🚀 Going live?

Read PRODUCTION.md — a complete step-by-step guide for beginners: create the Telegram bot, get a free Oracle Cloud server, run the one-command installer, set up HTTPS and moderators, run a pilot, and maintain it. Everything costs $0 on the free tier.

The repo ships the full deployment kit: deploy.sh (interactive installer), naija-waste-bot.service / naija-waste-server.service (systemd, auto-restart, boot persistence), update.sh (one command to update from this repo), backup.sh (nightly consistent backups, keeps 14).

Files

File What it is
bot.py Telegram bot: report flow, moderation, claim/proof workflow, Green Points, English/Pidgin, optional AI, /link codes
server.py Flask API: map read endpoints + PWA write endpoint (POST /api/reports, rate-limited per IP) + /api/link (throttled) + photo proxying (bot token never exposed) + local photo storage + admin-group notification for web reports
index.html Full PWA: Map + Report tabs, Telegram connect, works offline (IndexedDB queue + service worker)
sw.js Service worker: app-shell/tile/photo caching, background sync of queued reports (single-owner flush)
manifest.json / icon.svg PWA installability (served by server.py)
schema.sql SQLite schema — portable, with Postgres migration notes inline (synced with the code's runtime schema)
train_waste_classifier.py Colab/Kaggle training script for the photo classifier (free GPU)
deploy.sh / update.sh / backup.sh Production installer / updater / backups
*.service systemd units (auto-start, survive reboots)
PRODUCTION.md Beginner go-live guide — start here

Media handling: bot photos are proxied through server.py (fetched from Telegram's CDN server-side — the bot token is never sent to a browser); PWA photos are compressed client-side and stored in uploads/. Nothing big touches your disk.

Quick start (developer testing)

pip install -r requirements.txt
export BOT_TOKEN="123456:ABC..."       # create a bot with @BotFather, paste the token
python bot.py                          # user reporting works with just this

# PWA + map (second terminal, same machine):
export BOT_TOKEN="123456:ABC..."
python server.py                       # http://0.0.0.0:8000

Users can then open the site and install it as an app (browser menu → "Install app" / "Add to Home Screen"). Either process can start first — server.py creates the full base schema, bot.py migrates older databases.

Device linking (PWA ⇄ Telegram)

Web reports can earn Green Points and send status updates to Telegram once the user links their device:

  1. In the PWA (Report tab → Connect Telegram), the user reads the hint: send /link to the bot.
  2. The bot replies with a one-time 6-character code (uppercase letters + digits), valid 15 minutes, single use. Only one unused code exists per user at a time; sending /link again voids the previous one.
  3. The user types the code in the PWA → POST /api/link checks it against the link_codes table (unused + unexpired), marks it used, and returns the Telegram id + display name, which the PWA stores locally.
  4. From then on, web reports carry the Telegram id; the server validates it exists in users (issued via /link) and uses the Telegram display name. Points and notifications flow as if the report came from the bot.

Security properties: single-use, 15-minute expiry, ~2 billion possible codes (brute force is impractical in the window, and the endpoint is additionally throttled to 20 attempts per 5 minutes per IP), id acceptance restricted to bot-created accounts, endpoint meant to sit behind HTTPS. Disconnecting is one tap on the device (clears local storage only — no server state to undo).

Offline reporting (the PWA)

  • Report tab: camera capture (photo compressed to ≤ ~300 KB on-device), GPS button, typed landmark, category chips, description, optional display name, optional Telegram link. The manual name field disappears once linked (Telegram's name is authoritative).
  • Offline: if there's no network, the report goes into an on-device IndexedDB queue with a badge counter; it auto-uploads when connectivity returns. Flushes are single-owner (the page when open, the service worker when closed) and single-flight, so nothing is submitted twice; non-retryable responses (4xx) drop the item instead of retrying forever.
  • Map tab: cached tiles + last-known report data render offline; live data loads when online.

Feature-by-feature setup

Everything is optional. Remove the env var and the feature simply switches off.

1. Moderator layer — NWB_ADMIN_CHAT_ID

  1. Create a private Telegram group (e.g. "Naija Waste Bot — Moderators"), add the bot.
  2. Get the group chat id (negative number, e.g. -1001234567890) via @userinfobot or the bot's logs.
  3. export NWB_ADMIN_CHAT_ID="-100..." in both processes and restart — bot.py posts bot reports and proof photos there; server.py posts new web reports (summary + photo) there. Without it, web reports still land in the database but moderators only find them via /pending.

New reports (from the bot and the PWA) are auto-posted to that group; moderators run: /pending, /approve NWB-000123 [note], /reject ..., /wip ..., /resolve ..., /release .... Commands only work inside the admin chat.

2. Claim / cleanup workflow

  1. A moderator /approves a report → it goes on the map and is broadcast to the LGA groups.
  2. Any member of the admin group or an LGA group runs /claim NWB-000123 — status flips to in_progress, the claimer is recorded and DM'd instructions.
  3. The claimer sends a photo with the caption /proof NWB-000123 → stored in the proofs audit table, becomes the map photo, posted to the admin group.
  4. A moderator verifies with /resolve NWB-000123 → claimer +40 Green Points, reporter +15.
  5. /release NWB-000123 (admin) reopens a cold claim.

3. Green Points + leaderboard — no setup

+10 report, +25 approved, +15 resolved, +40 cleanup. /points, /leaderboard. Linked PWA devices earn points too; unlinked web reports earn nothing (no ghost accounts — anonymous reports are never credited).

4. English + Pidgin — no setup

/lang pcm / /lang en per user. Add languages by appending strings to MESSAGES in bot.py.

5. LGA broadcasting — NWB_BROADCAST_GROUPS

export NWB_BROADCAST_GROUPS="-100111,-100222" — approved reports post to each listed group; these are also the /claim surfaces.

6. AI photo suggestion — HF_TOKEN (+ NWB_CLASSIFIER_MODEL)

  • Trained classifier (better): run train_waste_classifier.py on free Colab (~20 min, see its header), then export NWB_CLASSIFIER_MODEL="<you>/naija-waste-classifier".
  • CLIP zero-shot fallback: default, no training.
  • Mapping: biodegradable→Organic, plastic→Plastic, trash→Mixed, others→Other. Construction/Hazardous need bot-collected photos (see "Retraining loop").

7. Voice-note transcription — optional install

pip install "faster-whisper>=1.0" — voice notes ≤3 min transcribed on CPU; else audio-only.

Abuse control

  • Telegram reports: max 5 per user per 24 h (MAX_REPORTS_PER_DAY in bot.py).
  • Web reports: max 10 per client IP per hour (MAX_WEB_REPORTS_PER_HOUR in server.py; the limiter reads X-Forwarded-For so it works correctly behind Caddy or another reverse proxy).
  • Link redemption: max 20 attempts per IP per 5 minutes.
  • All submissions land in pending — nothing reaches the public map without moderator approval.

Hosting notes

  • Any free-tier VM (Oracle Cloud Always Free, GCP free tier, donated VPS): run bot.py and server.py as separate processes — or just use deploy.sh which does it all.
  • HTTPS is required for the PWA (service workers and camera/GPS need a secure context — localhost works for testing). deploy.sh installs Caddy for automatic HTTPS when you give it a domain.
  • A static HF Space can show the app shell but cannot run server.py, so its fetches fail there — host the PWA on the same VM as the server.
  • Back up reports.db (backup.sh does this safely with WAL) and the uploads/ folder.

Database choice (SQLite WAL → Postgres)

Two low-frequency writers on one machine: SQLite WAL mode (enabled automatically at startup in both processes) is the right call. Switch to PostgreSQL/Supabase when you have multiple machines or heavy concurrent writers — schema.sql carries inline Postgres type notes. Existing databases are migrated automatically (local_photo, claim columns, link_codes table).

Status lifecycle

pending → approved → in_progress (claimed) → resolved (or rejected), appended to the report_events audit table; reporters (Telegram or linked PWA users) notified via Telegram.

Retraining loop (how the model improves)

Bot photos + user-confirmed categories accumulate in the reports table. Export, download via Telegram's getFile, add to the training mix in train_waste_classifier.py — Construction/Hazardous coverage arrives from your own data, for free.

Roadmap

  • Waste-to-wealth: recyclable value estimates + buyer connections
  • Deeper WhatsApp bridge (fragile — Telegram + PWA stay primary)
  • /points inside the PWA (currently Telegram-only)
Downloads last month
180