feat: prefilter model for senstive content detection - #198
Open
Jassu7082 wants to merge 2 commits into
Open
Conversation
- Add PrefilterResult, PiiEntity, PiiEntityTypes models - Add PrefilterService with regex scan (light mode) and mode persistence - Add PrefilterMlService: GLiNER ONNX inference (deep mode) - Add PrefilterTokenizer: BPE tokenizer for GLiNER input - Add PrefilterModelDownloadService: HuggingFace ONNX model download - Extend Screenshot model with prefilterStatus and prefilterReason fields - Add onnxruntime ^1.4.0 dependency
Author
Fail-Safe: Missing AssetsIf Deep Mode is enabled but required assets are unavailable if (mode == 'deep' && !isDownloaded) {
_selectedMode = 'light';
PrefilterService.setMode('light');
}Source AttributionThe scanning engine uses optimized ONNX models provided by the onnx-community.
Used Dependencies
|
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.
Implementation of Issue #150
Model used https://huggingface.co/urchade/gliner_small-v2.1#citation
Model Download Flow
Overview
Deep Mode relies on external assets hosted on Hugging Face.
To keep the initial APK size lightweight, these assets are downloaded dynamically at runtime.
Download Pipeline & Logic
The download process is managed by
PrefilterModelDownloadService, which displays a weighted progress bar to improve user experience.Steps
Tokenizer (10%)
gliner_tokenizer.jsonModel (90%)
gliner_pii_small.onnxFlow Diagram
graph TD A[User Selects 'Deep' Mode] --> B{isModelDownloaded?} B -- "Files Exist in App Support Dir" --> C[Set Mode to 'Deep'] B -- "Files Missing" --> D[Show _PrefilterDownloadDialog] D --> E[startDownload] E --> F[Download Tokenizer: 0% → 10%] F --> G[Download Model: 10% → 100%] G --> H{HTTP 200?} H -- Yes --> I[Status: Completed] H -- No/Error --> J[Status: Error + Log Analytics] I --> K[Show 'Get Started' Button] J --> L[Show 'Retry' Button]