Skip to content

fix: replace Math.random() mock in vision scanner with real BioScanner TensorFlow inference#690

Open
lofidebugger wants to merge 2 commits into
Shruti070107:mainfrom
lofidebugger:main
Open

fix: replace Math.random() mock in vision scanner with real BioScanner TensorFlow inference#690
lofidebugger wants to merge 2 commits into
Shruti070107:mainfrom
lofidebugger:main

Conversation

@lofidebugger

Copy link
Copy Markdown

The captureAndAnalyze function in src/vision-scanner.js was generating completely fake AI scores using Math.random()
to return a random number between 60 and 95 instead of performing any real analysis. The real TensorFlow.js MobileNet
implementation already existed in src/scanner.js and was exposed globally as window.BioScanner but was never connected to the vision scanner.

On top of that vision-scanner.js was not even included in index.html so the component was not loading in the app at all.

This fix connects the two by replacing the fake mock block with a real call to window.BioScanner.performScan() and adds the missing script tag to index.html. The captureAndAnalyze function is now async and handles edge cases like missing BioScanner, low confidence results, and non-organic waste classification following the same error handling pattern already used in this file.

Since the Trust Protocol and rewards system rely on accurate segregation scores this fix makes the entire platform integrity actually trustworthy.

What Changed

  1. Added script tag for vision-scanner.js in index.html
    after scanner.js so window.BioScanner is available
  2. Removed setTimeout and Math.random() fake block from
    captureAndAnalyze in vision-scanner.js
  3. Made captureAndAnalyze async to support real inference
  4. Added real call to await window.BioScanner.performScan(canvas)
  5. Added edge case handling for missing BioScanner,
    undefined results, low confidence below 30, and
    non-organic waste classification
  6. No other lines touched in either file

Related Issue

Fixes #689

Type of Change

  1. Bug Fix

Validation

  1. No syntax errors across all touched files
  2. Only two files modified
  3. No existing code deleted outside the fake mock block
  4. Edge cases handled matching existing file patterns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: AI Vision Scanner uses Math.random() instead of real TensorFlow model — generates fake scores

1 participant