|
|
from pprint import pprint
|
|
|
from detoxify import Detoxify
|
|
|
import pandas as pd
|
|
|
|
|
|
class DetoxifyModerator(object):
|
|
|
|
|
|
def detect_toxicity(self,text):
|
|
|
results = Detoxify('original').predict(text)
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_results(self,results):
|
|
|
|
|
|
df = pd.DataFrame(list(results.items()), columns=["Category", "Percentage"])
|
|
|
df["Percentage"] = df["Percentage"].apply(lambda x: f"{x:.2%}")
|
|
|
return df
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
detoxify_moderator = DetoxifyModerator()
|
|
|
result = detoxify_moderator.detect_toxicity('To let the user select the target language for translation, you can add a dropdown menu in the Gradio interface. This will allow users to choose the target language before processing the video. Here\'s how you can modify the script to include this feature')
|
|
|
report = detoxify_moderator.get_toxicity_report(result)
|
|
|
pprint(report)
|
|
|
|
|
|
|
|
|
|