Last updated:
0 purchases
nsfw detector flutter
๐ nsfw_detector_flutter #
A Flutter package to detect NSFW ๐ (Not Safe For Work / NUDE / adults) contents and classify SAFE ๐ก๏ธ contents without downloading or setting any assets
๐ ๏ธ Installation #
flutter pub add nsfw_detector_flutter
copied to clipboard
That's it! You don't need any assets. ๐
๐ Simple usage #
import 'package:nsfw_detector_flutter/nsfw_detector_flutter.dart';
File imageFile = File('path/to/image.jpg');
NsfwDetector detector = await NsfwDetector.load();
NsfwResult? result = await detector.detectNSFWFromFile(imageFile);
// whether it is over threshold (default: 0.7)
print("NSFW detected: ${result?.isNsfw}");
// float value from 0 to 1
print("NSFW score: ${result?.score}");
copied to clipboard
๐ Usage #
Load and initialize the detector #
The NsfwDetector can be initialized with default parameters:
NsfwDetector detector = await NsfwDetector.load(); // default threshold: 0.7
copied to clipboard
Parameter
Type
Default
Description
threshold
Float
0.7
The threshold to classify an image as NSFW
NsfwResult #
The NsfwResult class contains the following properties:
Parameter
Type
Description
score
Float
The NSFW score of the image (0 to 1, higher indicates more NSFW)
isNsfw
Boolean
Indicates if the image is classified as NSFW based on the threshold
Detect NSFW content #
// from bytes
final ByteData data = await rootBundle.load('assets/nsfw.jpeg');
final Uint8List imageData = data.buffer.asUint8List();
NsfwResult? result = await detector.detectNSFWFromBytes(imageData);
// from file
File imageFile = File('path/to/image.jpg');
NsfwResult? result = await detector.detectNSFWFromFile(imageFile);
// from image
import 'package:image/image.dart' as img;
img.Image image = img.decodeImage(File('path/to/image.jpg').readAsBytesSync())!;
NsfwResult? result = await detector.detectNSFWFromImage(image);
copied to clipboard
โ ๏ธ Warnings #
iOS #
If there are issues related to the library on iOS and it doesn't work, check the following setting in XCode:
Ensure that XCode > Build Settings > Deployment > Strip Linked Product is set to No.
Android #
This package uses the flutter_lints package, so the Android minSdkVersion must be set to 26 or higher. Check the following setting in the android/app/build.gradle file:
android {
defaultConfig {
minSdkVersion 26
}
}
copied to clipboard
๐งช Test #
For information on how to run integration tests for this package, please refer to the example README.
๐ณ License #
This project is licensed under the MIT License - see the LICENSE file for details.
Model Information #
The default model used in this package is referenced from the open_nsfw_android repository, which is a port of the yahoo/open_nsfw model. This package complies with the license terms of the yahoo/open_nsfw repository.
BSD 3-Clause License #
Copyright 2016, Yahoo Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the Yahoo Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.