diff --git a/NSFW_classify/classify.js b/NSFW_classify/classify.js new file mode 100644 index 0000000..16ed47c --- /dev/null +++ b/NSFW_classify/classify.js @@ -0,0 +1,57 @@ +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"); + + 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 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 new file mode 100644 index 0000000..f97d67e --- /dev/null +++ b/NSFW_classify/test.js @@ -0,0 +1,16 @@ +const nlp = require('./classify') + +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) +} + +main() 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 diff --git a/index.js b/index.js deleted file mode 100644 index e69de29..0000000 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" -}