From 0653725dd70a0fddd19cf1fcee95ce2b96de8cd9 Mon Sep 17 00:00:00 2001 From: Aaron Ang <67321817+aaron-ang@users.noreply.github.com> Date: Sun, 16 Oct 2022 08:01:23 -0400 Subject: [PATCH] add content safety warning --- browser_index.js | 38 ++++++++++++++++++++++++++++---------- index.js | 4 ++-- index.ts | 4 ++-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/browser_index.js b/browser_index.js index 059c7da..92e4646 100644 --- a/browser_index.js +++ b/browser_index.js @@ -22,12 +22,12 @@ const getTranscription = () => { async function (tabs) { setLoadingState(); - let link = tabs[0].url; - let isFiltered = document.getElementById("filterProfanities").checked; + const link = tabs[0].url; + const isFiltered = document.getElementById("filterProfanities").checked; // Call the AssemblyAI api to transcribe video. try { - let response = await fetch("http://localhost:3000", { + const response = await fetch("http://localhost:3000", { method: "POST", headers: { "Content-Type": "application/json", @@ -38,14 +38,32 @@ const getTranscription = () => { }), }); - let data = await response.json(); + const data = await response.json(); - // Download the text received as a text file. - let blob = new Blob([data.text], { type: "text/plain" }); - let url = URL.createObjectURL(blob); - chrome.downloads.download({ - url: url, - }); + // analyze sentiment of the transcription. + const safety = data.content_safety_labels.summary; + if (safety.profanity > 0.5 || safety.nsfw > 0.5) { + if ( + confirm( + "This video contains profanity or NSFW content. Continue downloading transcript?" + ) + ) { + // Download the text received as a text file. + const blob = new Blob([data.text], { type: "text/plain" }); + const url = URL.createObjectURL(blob); + chrome.downloads.download({ + url: url, + }); + } else { + return; + } + } else { + const blob = new Blob([data.text], { type: "text/plain" }); + const url = URL.createObjectURL(blob); + chrome.downloads.download({ + url: url, + }); + } } catch (e) { console.log(e); } finally { diff --git a/index.js b/index.js index 37a13e8..cfed276 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ app.post("/", async (req, res) => { assembly .post("/transcript", { audio_url: audioURL, - sentiment_analysis: true, + content_safety: true, filter_profanity: profanityFilter, }) .then((response) => { @@ -54,7 +54,7 @@ app.post("/", async (req, res) => { status = response.data.status; while (status !== "completed") { await sleep(2000); - let response = await assembly.get(`/transcript/${transcriptId}`); + const response = await assembly.get(`/transcript/${transcriptId}`); status = response.data.status; if (status === "completed") { fs.unlink(audioFile, (err) => { diff --git a/index.ts b/index.ts index 28ea4ac..cb97111 100644 --- a/index.ts +++ b/index.ts @@ -50,7 +50,7 @@ app.post("/", async (req, res) => { assembly .post("/transcript", { audio_url: audioURL, - sentiment_analysis: true, + content_safety: true, filter_profanity: profanityFilter, }) .then((response) => { @@ -63,7 +63,7 @@ app.post("/", async (req, res) => { while (status !== "completed") { await sleep(2000); - let response = await assembly.get( + const response = await assembly.get( `/transcript/${transcriptId}` ); status = response.data.status;