Permalink
Browse files

started working on auto-moderation

  • Loading branch information...
cloutier committed Feb 14, 2017
1 parent 3c36db1 commit f8d05376ec847c0da15a3dd50774a754ca9cab1c
Showing with 70 additions and 1 deletion.
  1. +2 −1 composer.json
  2. +68 −0 utils/auto-moderate.php
View
@@ -1,6 +1,7 @@
{
"license": "AGPLv3+",
"require": {
- "cloutier/php-ipfs-api": "dev-master"
+ "cloutier/php-ipfs-api": "dev-master",
+ "google/cloud": "^0.20.2"
}
}
View
@@ -0,0 +1,68 @@
+<?php
+/*
+ Removes banned pictures
+ Copyright (C) 2015 IpfsPics Team
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+error_reporting(1);
+
+require __DIR__ . '/../vendor/autoload.php';
+include __DIR__ ."/../pswd.php";
+
+use Cloutier\PhpIpfsApi\IPFS;
+# Imports the Google Cloud client library
+use Google\Cloud\Vision\VisionClient;
+
+# Your Google Cloud Platform project ID
+$projectId = $google_cloud_project;
+
+# Instantiates a client
+$vision = new VisionClient([
+ 'projectId' => $projectId,
+ 'keyFilePath' => '/var/www/html/cloud_auth.json'
+]);
+
+
+print("gc \n \n");
+
+$db = new PDO('mysql:host=localhost;dbname=hashes;charset=utf8', $db_user, $db_pswd);
+$ipfs = new IPFS("localhost", "8080", "5001");
+
+
+$unmoderated = $db->query("SElECT * FROM hash_info WHERE banned = 0 AND sfw = 0 AND nsfw = 0;")->fetchAll();

This comment has been minimized.

Show comment
Hide comment
@scriptzteam

scriptzteam Jun 18, 2017

SElECT should ne SELECT
:)

@scriptzteam

scriptzteam Jun 18, 2017

SElECT should ne SELECT
:)

+
+foreach($unmoderated as $i) {
+ $hash = $i['hash'];
+ # The name of the image file to annotate
+ $fileName = "https://ipfs.pics/ipfs/" . $hash;
+echo $hash;
+
+ $content = file_get_contents($fileName);
+ if ($content) {
+ # Prepare the image to be annotated
+ $image = $vision->image($content, [
+ "SAFE_SEARCH_DETECTION"
+ ]);
+
+ # Performs label detection on the image file
+ $annotations = $vision->annotate($image);
+ $safe = $annotations->safeSearch();
+ echo $safe->adult();
+ } else {
+
+ print "Could now download hash: $hash \n";
+ }
+}
+

0 comments on commit f8d0537

Please sign in to comment.