fixed code
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user