Fix: add confidence threshold and prevent UI freezing on empty states#7
Open
khushanuma-shabbir wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves real-time prediction stability and fixes a bug where the
UI freezes when a hand leaves the camera frame.
Problem
Two issues existed in the prediction pipeline:
No confidence threshold — The model accepted the top prediction even
at very low confidence (e.g., 15%). During hand transitions or random
movements, the UI rapidly flickered with incorrect letters, and the
5-second auto-add timer could trigger erroneously.
UI freezing on empty state — When a hand left the frame,
detector.findHands()returned empty and the backend responded with{"success": False}. The frontend ignored this response, leaving thelast detected letter permanently frozen on screen.
Changes Made
app.pyCONFIDENCE_THRESHOLD = 0.70constant (70% minimum confidence)"Unsure"and reset theauto-add timer, preventing false letter triggers
success: Truewith"Waiting..."so the frontend clears the screen properly
imgCrop.size == 0), statevariables are now reset before returning
templates/index.html"Waiting..."and"Unsure"cleanly withoutappending
(0%)to the stringTesting Steps
python app.pyand openhttp://127.0.0.1:5000"Unsure"insteadof a random letter
"Waiting..."immediately instead of freezingcorrectly for high-confidence predictions
Why This Improves the Project