• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • πŸ‘‰ Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • πŸ’Έ Purchase a Pro Subscription to get access to active software support and faster ticket response times.
  • Chevereto Support CLST

    Support response

    Support checklist

    • βœ… Confirm that the server meets the System Requirements
    • πŸ”₯ Check for any available Hotfix - your issue could be already reported/fixed
    • πŸ“š Read documentation - It will be required to Debug and understand Errors for a faster support response

Moderate images using AI

mkerala

πŸ‘½ Chevereto Freak
Since I use Google ads, every image had to be moderated before I could show ads. With Moderatecontent API, we could automate this task. However, the free version is pretty slow and support only 1000 images. Hence, it is impossible to send 10K images uploaded on my site every day.

Based on Auto detect Adult Content and hide thread, I have modified the script to add a few more features to best suite for my requirements. I am only sending those images with a view more than 20 for moderation before I place ads. So I get revenue for all the views generated on the site.

Features
  1. Mark all images as NSWF on upload.
  2. The hourly script will approve only images with more than 20 views. So that Google Ads can be shown on those images.
  3. The script will output results to an HTML file which can be viewed on the browser.
  4. Only sent 10 images for moderation per run to reduce failure.
  5. For an image with size larger than 10MB, the thumbnail is sent.
  6. Adult images detected will be added to the log.
  7. Click the image on the log will initiate a search for the image on the site with the image name.
  8. Image rating, size, upload date and uploader IP info added to log.
  9. IP is hyperlinked and clicking it will show all images uploaded from that IP.
Screenshot of html log page attached.

Phase 1: Mark all images uploaded as NSFW by default

After line 89 (before $uploaded_id = CHV\Image::uploadToWebsite($source, $logged_user, $_REQUEST);)
// Upload to website
$_REQUEST['nsfw'] = 1; //Set all images as NSFW by default on upload

of /app/routes/route.json.php and upload the new file to to /app/routes/overrides

Phase 2: Remove NSFW option from anywhere uploader and replace it with a warning.

Replace line 169 of /var/www/html/app/themes/Peafowl/snippets/anywhere_upload.php with below code. Upload the new file to /var/www/html/app/themes/Peafowl/overrides/snippets.

<div class="margin-10"><span rel="tooltip" data-tiptip="top" title="<?php _se('Adult contents uploaded will be deleted'); ?>"><name="upload-nsfw" id="upload-nsfw" class="margin-right-5" value="1"><label for="upload-nsfw"><?php _se('Note: Adult contents not allowed'); ?></label></span></div>


Phase 3: Add crontab job to run every hour

0 * * * * /usr/bin/php /var/www/html/moderate.php >> /var/www/html/log.html //Run moderation hourly
0 0 * * * mv /var/www/html/log.html /var/www/html/log/log_`date +\%d\%m\%y`.html //Archive log every day

Moderate.php

Code:
<html>
<?php
include('dbconnectfile.php'); //Your database config file
date_default_timezone_set('Asia/Kolkata'); // Your time zone
$time=date('Y-m-d H:i:s'); //Current date and time
$result = mysqli_query($link,"SELECT * FROM images where image_views > 20 and image_nsfw=1 and image_date > '2020-01-01 12:58:01' ORDER BY image_id DESC LIMIT 10"); //SQL query to pull images with more than 20 views and uploaded after 01-01-2020
$find=0;
echo '<h2>Mod time '.$time.'</h2>';  //Print cureent date and time to HTML
if (mysqli_num_rows($result)>0){
while($r=mysqli_fetch_array($result))
{
$find++;
$imageid=$r["image_id"];
$imagename=$r["image_name"];
$imageview=$r["image_views"];
$imagex=$r["image_extension"];
$ip=$r["image_uploader_ip"];
$imagedate=$r["image_date"];
$size=$r["image_size"];
$storid=$r["image_storage_id"];
$times=date("Y-m-d", strtotime($imagedate));
$timesp=explode('-',$times);
$search='https://gifyu.com/search/images/?as_q=&as_epq=%22'.$imagename.'%22&as_eq=&as_stor='.$storid.'';  //Search link to find image by anme
$storid--;
$imgurl='https://s'.$storid.'.gifyu.com/images/'.$imagename.'.'.$imagex.''; //Generate image URL for external storage server
$imgmd='https://s'.$storid.'.gifyu.com/images/'.$imagename.'.md.'.$imagex.''; //Image URL for thimbnail
$ipurl='https://gifyu.com/search/images/?as_ip='.$ip.'';  //Search link to find all images uploaded by this IP
$asize= number_format($size / 1048576, 2) . ' MB';  //Convert image size to MB
if($size < '10485760')  // If image size is less than 10MB sent directly for moderation
{
$links='https://www.moderatecontent.com/api/v2?key=yourAPI&url='.$imgurl.'';
}
else //If image size is greater than 10MB sent the thimbnail for moderation
{
    $links='https://www.moderatecontent.com/api/v2?key=yourAPI&url='.$imgmd.'';
}
$file_get_contents=file_get_contents($links);
$parse=json_decode($file_get_contents);
$rating=$parse->rating_label;
if ($rating === "everyone"){  //If the image is safe, remove NSFW tag
    mysqli_query($link,"UPDATE images SET image_nsfw='0' WHERE image_id='$imageid'") or die(mysql_error());
}
echo '<p><a href='.$search.'><img src='.$imgmd.'></a></p>';  //Display image thimbnail with hyper link to search image by name
echo '<p>'.$rating.' Size: '.$asize.'  '.$imagedate.' IP:<a href='.$ipurl.'>'.$ip.'</a> Views:'.$imageview.'<p>'; //Image rating, size, upload date and uploader IP info
}
}
?>
</html>

dbconnectfile.php
Code:
<?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'");
?>

After implementing this, my revenue jumped by 150% as ads get placed on images with good view within 1 hour of being uploaded.
 

Attachments

  • Capture.JPG
    Capture.JPG
    96 KB · Views: 58
Last edited:
Thanks for this. Do you know if this moderation api can scan the current library of uploaded images and mark/delete unwanted images?

Would something like this do the trick?

Code:
$result = mysqli_query($link,"SELECT * FROM images where image_views > 1 and image_date > '2018-01-01 12:00:00' ORDER BY image_id DESC");
 
Thanks for this. Do you know if this moderation api can scan the current library of uploaded images and mark/delete unwanted images?

Would something like this do the trick?

Code:
$result = mysqli_query($link,"SELECT * FROM images where image_views > 1 and image_date > '2018-01-01 12:00:00' ORDER BY image_id DESC");


These APIs are week, slow and not that reliable. It takes around 5-10 seconds per image and images larger than 10MB fails. Also getting a lot of false positives and negatives. So I decided to give it just 10 images and size <10MB. Also, have to keep a close eye on the log files.

I would love to send all my images for moderation. But the technology is still not ready and still costly if we look at other paid services like Google Vision.
 
Last edited:
Yeah, best option would be to leave the adult content as is and just run a db command to mark everything as nfsw and "start fresh"

Btw,
Add $_REQUEST['nsfw'] = 1; after line 82 of /app/routes/route.json.php and upload the new file to to /app/routes/overrides

I think it's below line 92 now, not 82? :)
 
Yeah, best option would be to leave the adult content as is and just run a db command to mark everything as nfsw and "start fresh"

Btw,

I think it's below line 92 now, not 82? :)
Thanks. Corrected it.
 
Last edited:
Tried implementing this, but it throws a warning:
Code:
Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in /path/to/moderate.php on line 9

Line 9:
Code:
if (mysqli_num_rows($result)>0){

What am I missing here, you got it working with the example above?
 
Tried implementing this, but it throws a warning:
Code:
Warning:  mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in /path/to/moderate.php on line 9

Line 9:
Code:
if (mysqli_num_rows($result)>0){

What am I missing here, you got it working with the example above?
This error came up when the SQL query did not return any results. Trying running the query on MySQL and see if it generates any result.
 
Dang. Found this issue, it's stupid. I didn't think of the table name. You probably dont use the default "chv_" once I changed images to chv_images it works :)
 
$storid is only used and will work if I used external storage right?
I can remove it if I'm not using?

Thanks for this guide.
 
What to do with this error?
I'm using PHP 7.4.4
HTML:
<html>
<h2>Mod time 2020-03-26 18:40:31</h2>PHP Notice:  Undefined property: stdClass::$rating_label in /home/nginx/domains/doma.in/moderate.php on line 39
<p><a href=https://doma.in/search/images/?as_q=&as_epq=%22Screenshot_20200326-190503%22&as_eq=&as_stor=><img src=https://doma.in/images/Screenshot_20200326-190503.md.png></a></p><p> Size: 0.19 MB  2020-03-26 08:15:07 IP:<a href=https://doma.in/search/images/?as_ip=8.8.8.8>8.8.8.8</a> Views:5<p></html>
 
Code:
$imgurl='https://s'.$storid.'.gifyu.com/images/'.$imagename.'.'.$imagex.''; //Generate image URL for external storage server
This doesn't work on my new install though.
Why is it your images seems direct link?
You didn't use timestamp?
 
$storid is only used and will work if I used external storage right?
I can remove it if I'm not using?

Thanks for this guide.
Yes, only for external storage.

What to do with this error?
I'm using PHP 7.4.4
HTML:
<html>
<h2>Mod time 2020-03-26 18:40:31</h2>PHP Notice:  Undefined property: stdClass::$rating_label in /home/nginx/domains/doma.in/moderate.php on line 39
<p><a href=https://doma.in/search/images/?as_q=&as_epq=%22Screenshot_20200326-190503%22&as_eq=&as_stor=><img src=https://doma.in/images/Screenshot_20200326-190503.md.png></a></p><p> Size: 0.19 MB  2020-03-26 08:15:07 IP:<a href=https://doma.in/search/images/?as_ip=8.8.8.8>8.8.8.8</a> Views:5<p></html>
The rating label was not returned. I think the passed URL might be incorrect.

Code:
$imgurl='https://s'.$storid.'.gifyu.com/images/'.$imagename.'.'.$imagex.''; //Generate image URL for external storage server
This doesn't work on my new install though.
Why is it your images seems direct link?
You didn't use timestamp?
Yes only we can retrieve direct link and it need to be sent for moderation.
 
  • Like
Reactions: rdn
No log has been written also, maybe because of that error.
Are you on PHP 7.4.4 also?
 
Back
Top