mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-11 12:23:20 +00:00
ban slurs from being said
This commit is contained in:
1 parent
d5ed1d9c3b
commit
3aded66c09
6 files changed
+55
-1
No files matched your search
@@ -0,0 +1,8 @@
|
||||
# This file serves to remove racial slurs and epithets from usage with vocodes.
|
||||
# There's probably more than this that we'll want to remove.
|
||||
# I need to investigate.
|
||||
fag
|
||||
faggot
|
||||
fags
|
||||
nigger
|
||||
niggers
|
||||
@@ -192,7 +192,7 @@ mod tests {
|
||||
fn test_tts_synthesizer_path() {
|
||||
let paths = get_instance();
|
||||
assert_eq!(paths.tts_synthesizer_path("foobar").to_str().unwrap(),
|
||||
"/test_path_synthesizers/f/o/o/foobar.pth");
|
||||
"/test_path_synthesizers/f/o/o/foobar.pt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -19,6 +19,7 @@ use sqlx::error::DatabaseError;
|
||||
use sqlx::error::Error::Database;
|
||||
use sqlx::mysql::MySqlDatabaseError;
|
||||
use std::sync::Arc;
|
||||
use crate::validations::check_for_slurs::contains_slurs;
|
||||
|
||||
const NEW_USER_ROLE: &'static str = "new-user";
|
||||
|
||||
@@ -102,6 +103,10 @@ pub async fn infer_tts_handler(
|
||||
return Err(InferTtsError::BadInput(reason));
|
||||
}
|
||||
|
||||
if contains_slurs(&inference_text) {
|
||||
return Err(InferTtsError::BadInput("text contains slurs".to_string()));
|
||||
}
|
||||
|
||||
// TODO(bt): CHECK DATABASE!
|
||||
let model_token = request.tts_model_token.to_string();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
pub const RESERVED_USERNAMES : &'static str = include_str!("../db/reserved_usernames.txt");
|
||||
pub const RESERVED_SUBSTRINGS : &'static str = include_str!("../db/reserved_usernames_including.txt");
|
||||
pub const BANNED_SLURS : &'static str = include_str!("../db/banned_slurs.txt");
|
||||
|
||||
pub mod buckets;
|
||||
pub mod common_queries;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
use std::collections::HashSet;
|
||||
use crate::BANNED_SLURS;
|
||||
|
||||
pub fn contains_slurs(unparsed_text: &str) -> bool {
|
||||
lazy_static! {
|
||||
static ref BANNED_SLURS_SET : HashSet<String> = BANNED_SLURS.lines()
|
||||
.map(|line| line.trim())
|
||||
.filter(|line| !(line.starts_with("#") || line.is_empty()))
|
||||
.map(|line| line.to_string())
|
||||
.collect::<HashSet<String>>();
|
||||
}
|
||||
|
||||
for wordlike in unparsed_text.split_ascii_whitespace() {
|
||||
if BANNED_SLURS_SET.contains(wordlike) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::validations::check_for_slurs::contains_slurs;
|
||||
|
||||
#[test]
|
||||
fn valid_text_passes() {
|
||||
assert_eq!(contains_slurs(""), false);
|
||||
assert_eq!(contains_slurs("this is a test."), false);
|
||||
assert_eq!(contains_slurs("this\nis\na\ntest\n\n"), false);
|
||||
assert_eq!(contains_slurs(" this is a test"), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn text_with_slurs_fails() {
|
||||
assert_eq!(contains_slurs("a sentence containing fag is banned"), true);
|
||||
assert_eq!(contains_slurs("a\nsentence\ncontaining fags\nis banned"), true);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod check_for_slurs;
|
||||
pub mod model_uploads;
|
||||
pub mod passwords;
|
||||
pub mod username;
|
||||
|
||||
Reference in new issue
Block a user