Auto detect Adult Content and hide

imgyukle

Network license
License owner
Joined
Aug 29, 2016
Messages
23
Likes
5
Points
53
#1
https://chevereto.com/community/thr...-for-nudity-detection-tagging-and-more.10046/

After See this topic, i wrote a sample code using Realtime Image Moderation API of https://www.moderatecontent.com/

PHP:
<?php
include('dbconnectfile.php'); //Your database config file
date_default_timezone_set('Europe/Moskov'); // Your time zone
$time=date('Y-m-d H:i:s');
$ptime=date('Y-m-d H:i:s',strtotime('-5 minute')); // You should set your time interval for which content check
$result = mysqli_query($link,"SELECT * FROM chv_images WHERE image_date BETWEEN '$ptime' AND '$time'");
$find=0;
if (mysqli_num_rows($result)>0){
while($r=mysqli_fetch_array($result))
{
$find++;
$imageid=$r["image_id"];
$imagename=$r["image_name"];
$imagex=$r["image_extension"];
$imagedate=$r["image_date"];
$times=date("Y-m-d", strtotime($imagedate));
$timesp=explode('-',$times);
$imgurl='https://i.imgyukle.com/'.$timesp[0].'/'.$timesp[1].'/'.$timesp[2].'/'.$imagename.'.'.$imagex.''; //change to your image direct link and folder type
$links='https://www.moderatecontent.com/api/v2?face=true&key=YOUR API KEY&url='.$imgurl.'';
$file_get_contents=file_get_contents($links);
$parse=json_decode($file_get_contents);
$rating=$parse->rating_label;
if ($rating === "adult"){
mysqli_query($link,"UPDATE chv_images SET image_nsfw='1' WHERE image_id='$imageid'") or die(mysql_error());
}
echo '<p>'.$rating.'</p>';
}
}
Get your key from https://www.moderatecontent.com/documentation/signup

Customize this code for your prefer and implement Api key

After create a cronjob for this file with same time interval.

That's all ;)

Also,image detecting keep 1 or 2 second per image, therefore image detecting can keep long time if you give long time interval, i think short time interval good for this
 

lovedigit

Core license
License owner
Joined
Mar 13, 2016
Messages
274
Likes
72
Points
100
#2
Can you share sample of dbconnectfile.php
 

imgyukle

Network license
License owner
Joined
Aug 29, 2016
Messages
23
Likes
5
Points
53
#3
Can you share sample of dbconnectfile.php
PHP:
<?php
$link = mysqli_connect("localhost", "DBuser", "DBuserpass", "DBname");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}
mysqli_select_db($link, 'DBname') or die("Could not open the db 'DBname'");
?>
here, you can use this for Mysqli ;)