Skip to content

Commit

Permalink
add content safety warning
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-ang committed Oct 16, 2022
1 parent 30368be commit 0653725
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
38 changes: 28 additions & 10 deletions browser_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down

0 comments on commit 0653725

Please sign in to comment.