Gemini Profanity Filter
A Python module for detecting and filtering profanity in text using Google's Gemini API. The module can identify standard and obfuscated profanity across multiple languages.
Features
- Detects standard profanity in multiple languages
- Identifies obfuscated profanity (character substitutions, leetspeak, etc.)
- Handles stretched or repeated characters
- Detects deliberately fragmented words
- Works with mixed case patterns
- Processes context-sensitive profanity
- Language-specific profanity patterns including Cyrillic, Asian scripts, etc.
Installation
pip install gemini-profanity-filter
Usage
from profanity_filter import ProfanityFilter
import pandas as pd
import traceback
def run_batch_tests(pf):
test_inputs = [
"Ebl@NiShe nahui ti che delaesh?",
"kon4ennyj ublYd0k idi nax",
"ty dur@k ili 4to?",
"suka bly@t idi v sr@ku",
"govn0ed pozornyj",
"pid0rasina ti proklyataya",
"naxui idi s etim",
"zh0p0lik bl9t",
"mraz0ta gnid@",
"hohol eb@n@y",
"4mo bly@dsk@ya",
"d@un ubly@dnij",
"pizd@nutij shelobok",
"ebanut@ya ovca",
"k@kazec ebanij",
"g0vni4e ty prost@k",
"nax d@unish4e",
"ni4ego ti ne ponim@esh",
"s0sni d@",
"nahu9 provalis"
]
rows = []
for i, text in enumerate(test_inputs, 1):
try:
result = pf.filter_text(text)
if result and result.detected_profanity:
for entry in result.detected_profanity:
rows.append({
"Тест #": i,
"Текст": text,
"Оригинал": entry.original_form,
"Нормализовано": entry.normalized_form,
"Метод": entry.detection_method,
"Уверенность": round(entry.confidence_score, 2),
"Объяснение": entry.reasoning[:100] + "..." if entry.reasoning else ""
})
else:
rows.append({
"Тест #": i,
"Текст": text,
"Оригинал": "-",
"Нормализовано": "-",
"Метод": "-",
"Уверенность": 0,
"Объяснение": "Нецензурная лексика не найдена"
})
except Exception as e:
rows.append({
"Тест #": i,
"Текст": text,
"Оригинал": "❌ Ошибка",
"Нормализовано": "-",
"Метод": "-",
"Уверенность": 0,
"Объяснение": str(e)
})
df = pd.DataFrame(rows)
print("\n=== Сводка по результатам ===\n")
print(df.to_string(index=False))
def main():
try:
print("=== Запуск авто-тестов ===")
api_key = "AIzaSyCs3Bbjq_7PeGTAEHJkkSsUtYZvj4Fbbwo"
pf = ProfanityFilter(api_key)
run_batch_tests(pf)
except Exception as e:
print(f"❌ Ошибка: {e}")
traceback.print_exc()
if __name__ == "__main__":
main()
Requirements
- Python 3.7 or higher
- Google GenerativeAI Python library
- A valid Google Gemini API key
License
MIT
Metadata
Release files for gemini-profanity-filter 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gemini_profanity_filter-1.2.0.tar.gz | 23.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gemini_profanity_filter-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 47.1 kB
Release files / gemini_profanity_filter-1.2.0.tar.gz
| Download URL | gemini_profanity_filter-1.2.0.tar.gz |
|---|---|
| Size | 23.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42b552bec7163e3d92435a221539f44f4198f8a5770a91ed9a9783044b3425d7
|
|
BLAKE2b-256 checksum How to use checksums |
feefca6c6c2e076f3131cdfd184d3abb0bafacbeb63aad4e9fdb06029f30ef96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / gemini_profanity_filter-1.2.0-py3-none-any.whl
| Download URL | gemini_profanity_filter-1.2.0-py3-none-any.whl |
|---|---|
| Size | 23.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e3bf19120a054bc0148e36c7dc97891ea2e83930e73cbde95330eaa2bbd40901
|
|
BLAKE2b-256 checksum How to use checksums |
6b8da227dc0891edd55a0cb0c2b618787808dce3b31320a2f1075012653ce74b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|