fnavales commited on
Commit
02fab3b
1 Parent(s): 64193f6

Add application file

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from detoxify import Detoxify
3
+
4
+ all_categories = {'all_categories': [
5
+ 'severe_toxicity',
6
+ 'obscene',
7
+ 'threat',
8
+ 'insult',
9
+ 'identity_attack',
10
+ 'sexual_explicit'
11
+ ]
12
+ }
13
+
14
+
15
+ examples = [
16
+ ['Yes indeed. She sort of reminds me of the elder lady that played the part in the movie "Titanic" who was telling her story!!! And I wouldn\'t have wanted to cover who I really am!! I would be proud!!!! WE should be proud of our race no matter what it is!!',
17
+ 50],
18
+ ['The trans women reading this tweet right now is beautiful', 50],
19
+ ["Question: These 4 broads who criticize America, what country did they flee to get here? And now they want to make OUR America like THEIR former HELL HOLE. I don't think so!!!!!!!!!! Let them explain their GRATITUDE for letting them in OUR country.",
20
+ 50],
21
+ ['Well being subtle you could not have been born because white people don\'t matter',
22
+ 50],
23
+ ["For starters bend over the one in pink and kick that ass and pussy to get a taste until she's begging for a dick inside her.",
24
+ 50]
25
+ ]
26
+
27
+
28
+ model = Detoxify('multilingual')
29
+
30
+
31
+ def toxicity(sentence, threshold):
32
+ predicts = model.predict(sentence)
33
+ return [ x for x in predicts if predicts[x] > threshold/100 ], all_categories
34
+
35
+ gr.Interface(fn=toxicity,
36
+ inputs=[
37
+ gr.Textbox(placeholder="Enter sentence here..."),
38
+ gr.Slider(0, 100)
39
+ ],
40
+ outputs=[
41
+ 'text',
42
+ gr.JSON(all_categories)
43
+ ],
44
+ examples=examples).launch()