fixed code

This commit is contained in:
SlimusMinus
2026-08-05 01:44:29 +03:00
parent 72159dbe4a
commit d33f0eaa78
30 changed files with 143 additions and 375 deletions

View File

@@ -16,28 +16,21 @@ class TextModerationService:
self.classifier = classifier
self.profanity_detector = profanity_detector
def moderate(
self,
text: str
) -> PredictionResult:
if text is None or not text.strip():
raise InvalidTextException(
"Text is empty"
)
detected_words = (
self.profanity_detector.detect(text)
)
if detected_words:
return PredictionResult(
label="PROFANITY",
@@ -54,23 +47,17 @@ class TextModerationService:
)
prediction = self.classifier.predict(text)
prediction.approved = (
prediction.score <
settings.TEXT_TOXIC_THRESHOLD
)
prediction.reason = (
"OK"
if prediction.approved
else "TOXIC"
)
return prediction
return prediction