From e7a9d37ce4b6ac9658fb3313da08d18037096140 Mon Sep 17 00:00:00 2001 From: Pranshul Date: Sat, 19 Sep 2020 10:43:14 +0530 Subject: [PATCH 1/5] APIs added --- NSFW_classify/classify.js | 66 +++++++++++++++++++++++++++++++++++++++ NSFW_classify/test.js | 12 +++++++ 2 files changed, 78 insertions(+) create mode 100644 NSFW_classify/classify.js create mode 100644 NSFW_classify/test.js diff --git a/NSFW_classify/classify.js b/NSFW_classify/classify.js new file mode 100644 index 0000000..3d15fb8 --- /dev/null +++ b/NSFW_classify/classify.js @@ -0,0 +1,66 @@ +function classify_comment(comment){ + const {google} = require('googleapis'); + + API_KEY = 'AIzaSyDvG3vlovfaGB-ZxN27LHIIFbuzIRr6sz0'; + DISCOVERY_URL = + 'https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1'; + + google.discoverAPI(DISCOVERY_URL) + .then(client => { + const analyzeRequest = { + comment: { + text: comment, + }, + requestedAttributes: { + TOXICITY: {}, + }, + }; + + client.comments.analyze( + { + key: API_KEY, + resource: analyzeRequest, + }, + (err, response) => { + if (err) throw err; + if(response.data.attributeScores.TOXICITY.spanScores[0].score.value>0.45){ + return true + } + else { + return false + } + }); + }) + .catch(err => { + throw err; + }); + +} + +function classify_image(img_link) +{ + var request = require('request'); // install request module by - 'npm install request' + var querystring = require('querystring') + + const form_data = { + 'modelId' : 'e4745b0e-70fb-447e-8870-61566137c8ab', + 'urls': img_link + } + + const options = { + url : 'https://app.nanonets.com/api/v2/ImageCategorization/LabelUrls/', + body: querystring.stringify(form_data), + headers: { + 'Authorization' : 'Basic ' + Buffer.from('-haYmFRR1siZGxd6GqF0fB3frdMLXqV5' + ':').toString('base64'), + 'Content-Type': 'application/x-www-form-urlencoded' + } + } + request.post(options, function(err, httpResponse, body) { + body = JSON.parse(body) + if(body.result[0].prediction[0].probability<0.6) + return true + else + return false + }); +} +module.exports = {classify_comment, classify_image} diff --git a/NSFW_classify/test.js b/NSFW_classify/test.js new file mode 100644 index 0000000..410c590 --- /dev/null +++ b/NSFW_classify/test.js @@ -0,0 +1,12 @@ +const nlp = require('./classify') +const a = nlp.classify_comment("Trump is an idiot") +console.log(a) +if( a == true){ + console.log("Toxic") +} +else if(a == false) { + console.log("Not Toxic") +} +const link = 'https://miro.medium.com/max/875/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg' + +console.log(nlp.classify_image(link)) From a60b1cbc737270f41297357d16cfe5c89b4f4f25 Mon Sep 17 00:00:00 2001 From: Pranshul Date: Sun, 20 Sep 2020 01:02:04 +0530 Subject: [PATCH 2/5] Fixed errors --- NSFW_classify/classify.js | 109 +++++++++++++++++--------------------- NSFW_classify/test.js | 20 ++++--- 2 files changed, 62 insertions(+), 67 deletions(-) diff --git a/NSFW_classify/classify.js b/NSFW_classify/classify.js index 3d15fb8..16ed47c 100644 --- a/NSFW_classify/classify.js +++ b/NSFW_classify/classify.js @@ -1,66 +1,57 @@ -function classify_comment(comment){ - const {google} = require('googleapis'); - - API_KEY = 'AIzaSyDvG3vlovfaGB-ZxN27LHIIFbuzIRr6sz0'; - DISCOVERY_URL = - 'https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1'; - - google.discoverAPI(DISCOVERY_URL) - .then(client => { - const analyzeRequest = { - comment: { - text: comment, - }, - requestedAttributes: { - TOXICITY: {}, - }, - }; - - client.comments.analyze( - { - key: API_KEY, - resource: analyzeRequest, - }, - (err, response) => { - if (err) throw err; - if(response.data.attributeScores.TOXICITY.spanScores[0].score.value>0.45){ - return true - } - else { - return false - } - }); - }) - .catch(err => { - throw err; - }); +async function classify_comment(comment) { + const { google } = require("googleapis"); + const API_KEY = "AIzaSyDvG3vlovfaGB-ZxN27LHIIFbuzIRr6sz0"; + const DISCOVERY_URL = + "https://commentanalyzer.googleapis.com/$discovery/rest?version=v1alpha1"; + const client = await google.discoverAPI(DISCOVERY_URL); + const resp = await client.comments.analyze({ + key: API_KEY, + resource: { + comment: { + text: "Trump is an idiot", + }, + requestedAttributes: { + TOXICITY: {}, + }, + }, + requestedAttributes: { + TOXICITY: {}, + }, + }); + if (resp.data.attributeScores.TOXICITY.spanScores[0].score.value > 0.45) { + return true; + } else { + return false; + } } +async function classify_image(img_link) { + const axios = require("axios").default; // install request module by - 'npm install request' + const querystring = require("querystring"); -function classify_image(img_link) -{ - var request = require('request'); // install request module by - 'npm install request' - var querystring = require('querystring') + const form_data = { + modelId: "e4745b0e-70fb-447e-8870-61566137c8ab", + urls: img_link, + }; - const form_data = { - 'modelId' : 'e4745b0e-70fb-447e-8870-61566137c8ab', - 'urls': img_link - } + const options = { + headers: { + Authorization: + "Basic " + + Buffer.from("-haYmFRR1siZGxd6GqF0fB3frdMLXqV5" + ":").toString( + "base64" + ), + "Content-Type": "application/x-www-form-urlencoded", + }, + }; - const options = { - url : 'https://app.nanonets.com/api/v2/ImageCategorization/LabelUrls/', - body: querystring.stringify(form_data), - headers: { - 'Authorization' : 'Basic ' + Buffer.from('-haYmFRR1siZGxd6GqF0fB3frdMLXqV5' + ':').toString('base64'), - 'Content-Type': 'application/x-www-form-urlencoded' - } - } - request.post(options, function(err, httpResponse, body) { - body = JSON.parse(body) - if(body.result[0].prediction[0].probability<0.6) - return true - else - return false - }); + const resp = await axios.post( + "https://app.nanonets.com/api/v2/ImageCategorization/LabelUrls/", + querystring.stringify(form_data), + options + ); + const body = resp.data; + if (body.result[0].prediction[0].probability < 0.6) return true; + return false; } module.exports = {classify_comment, classify_image} diff --git a/NSFW_classify/test.js b/NSFW_classify/test.js index 410c590..f97d67e 100644 --- a/NSFW_classify/test.js +++ b/NSFW_classify/test.js @@ -1,12 +1,16 @@ const nlp = require('./classify') -const a = nlp.classify_comment("Trump is an idiot") -console.log(a) -if( a == true){ - console.log("Toxic") -} -else if(a == false) { + +async function main() { + const a = await nlp.classify_comment("Trump is an idiot") + if( a == true){ + console.log("Toxic") + } + else if(a == false) { console.log("Not Toxic") + } + const link = 'https://miro.medium.com/max/875/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg' + b = await nlp.classify_image(link) + console.log(b) } -const link = 'https://miro.medium.com/max/875/1*mk1-6aYaf_Bes1E3Imhc0A.jpeg' -console.log(nlp.classify_image(link)) +main() From eaa8b4ce8cd92aa42aa1cea592c1a7a6993197f0 Mon Sep 17 00:00:00 2001 From: Saumitra Joshi <39857101+Saumitra1Joshi@users.noreply.github.com> Date: Sun, 20 Sep 2020 10:57:52 +0530 Subject: [PATCH 3/5] Delete README.md --- README.md | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 47a9802..0000000 --- a/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Resident_App -This app lets users be aware of, and make others be aware of their surroundings. -This app enables users to be aware of their surroundings. It relies on a community of people who put up information that is relevant and pertinent for the people in that area. People can make posts with images and description anonymously which can then be read by other users of the app so that they are aware of their surroundings, make informed decisions and know what to expect. With this app people can be more aware of surroundings and save themselves from and avoid any harm that might come their way. - -This app uses GPS location to fetch all the active posts on surrounding events, which will be displayed on their feed according to an algorithm that shows the most important posts first. The user would also have filter capabilities which would allow for better information intake and lead to the user feeling more informed about their surroundings. - -The primary purpose of this app is to make sure people can avoid bad, unfavourable and dangerous situations, and help them feel more empowered and confident in being out and about. - -There are multiple options alongside the posts, including upvoting, downvoting and flagging for inappropriate entries. The posts also have a certain lifetime, after the time has expired and they are no longer relevant or useful, the posts automatically disappear. This helps with user getting to know only what is relevant to them at the moment of time and in and around the area that they are in. - -Our goals for this app are to up the awareness, providing knowledge of one's surroundings, letting people feel like they are in control, and subsequently upping quality of life of the people who use our service. \ No newline at end of file From 887c5b0d35fd3863a3cd40afee666061587492bf Mon Sep 17 00:00:00 2001 From: Saumitra Joshi <39857101+Saumitra1Joshi@users.noreply.github.com> Date: Sun, 20 Sep 2020 10:58:03 +0530 Subject: [PATCH 4/5] Delete index.js --- index.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 index.js diff --git a/index.js b/index.js deleted file mode 100644 index e69de29..0000000 From d8bb10c4865de10ab3e8f295b7e63d056de0a616 Mon Sep 17 00:00:00 2001 From: Saumitra Joshi <39857101+Saumitra1Joshi@users.noreply.github.com> Date: Sun, 20 Sep 2020 10:58:13 +0530 Subject: [PATCH 5/5] Delete package.json --- package.json | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 package.json diff --git a/package.json b/package.json deleted file mode 100644 index 9c7d096..0000000 --- a/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "resident_app", - "version": "1.0.0", - "description": "This app lets users be aware of, and make others be aware of their surroundings", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/Saumitra1Joshi/Resident_App.git" - }, - "author": "Team Phoenix", - "license": "ISC", - "bugs": { - "url": "https://github.com/Saumitra1Joshi/Resident_App/issues" - }, - "homepage": "https://github.com/Saumitra1Joshi/Resident_App#readme" -}