Create profanity.py
Browse files- routers/profanity.py +31 -0
routers/profanity.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# routers/profanity.py
|
2 |
+
|
3 |
+
from fastapi import APIRouter, Query
|
4 |
+
from better_profanity import profanity
|
5 |
+
|
6 |
+
# Cria um roteador para a API de palavrões
|
7 |
+
router = APIRouter()
|
8 |
+
|
9 |
+
# Define a rota para verificar o texto
|
10 |
+
@router.get("/check-profanity/")
|
11 |
+
def check_profanity(text: str = Query(..., description="Texto a ser verificado")):
|
12 |
+
"""
|
13 |
+
Verifica se o texto contém palavrões e retorna detalhes.
|
14 |
+
"""
|
15 |
+
profanity.load_censor_words()
|
16 |
+
|
17 |
+
contains_profanity = profanity.contains_profanity(text)
|
18 |
+
censored_text = profanity.censor(text)
|
19 |
+
|
20 |
+
offensive_words = [
|
21 |
+
word for word in text.split()
|
22 |
+
if profanity.contains_profanity(word)
|
23 |
+
]
|
24 |
+
|
25 |
+
return {
|
26 |
+
"original_text": text,
|
27 |
+
"contains_profanity": contains_profanity,
|
28 |
+
"censored_text": censored_text,
|
29 |
+
"offensive_words": offensive_words,
|
30 |
+
"offensive_word_count": len(offensive_words)
|
31 |
+
}
|