fnavales commited on
Commit
8235435
1 Parent(s): 2a04af3

Upload Detoxify model

Browse files
Files changed (2) hide show
  1. app.py +8 -3
  2. requirements.txt +3 -2
app.py CHANGED
@@ -1,4 +1,7 @@
1
  import gradio as gr
 
 
 
2
  import torch.nn as nn
3
  import torch
4
  from transformers import BertTokenizerFast as BertTokenizer, BertModel
@@ -103,6 +106,7 @@ model = ToxicCommentTagger.load_from_checkpoint(
103
  model.eval()
104
  model.freeze()
105
 
 
106
 
107
  all_categories = {'all_categories': [
108
  'toxicity',
@@ -128,8 +132,11 @@ examples = [
128
  ]
129
 
130
 
 
 
 
131
  def toxicity(sentence, threshold):
132
- predicts = predict(model, tokenizer, sentence)
133
  return [ x for x in predicts if predicts[x] > threshold/100 ], all_categories
134
 
135
  gr.Interface(fn=toxicity,
@@ -142,5 +149,3 @@ gr.Interface(fn=toxicity,
142
  gr.JSON(all_categories)
143
  ],
144
  examples=examples).launch()
145
-
146
-
 
1
  import gradio as gr
2
+ <<<<<<< HEAD
3
+ from detoxify import Detoxify
4
+ =======
5
  import torch.nn as nn
6
  import torch
7
  from transformers import BertTokenizerFast as BertTokenizer, BertModel
 
106
  model.eval()
107
  model.freeze()
108
 
109
+ >>>>>>> 2a04af3d9d5ddbaa3eb1631c0e56d215462a7e36
110
 
111
  all_categories = {'all_categories': [
112
  'toxicity',
 
132
  ]
133
 
134
 
135
+ model = Detoxify('multilingual')
136
+
137
+
138
  def toxicity(sentence, threshold):
139
+ predicts = model.predict(sentence)
140
  return [ x for x in predicts if predicts[x] > threshold/100 ], all_categories
141
 
142
  gr.Interface(fn=toxicity,
 
149
  gr.JSON(all_categories)
150
  ],
151
  examples=examples).launch()
 
 
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
- transformers==4.23.1
2
- pytorch-lightning==1.7.7
 
 
1
+ detoxify==0.5.0
2
+
3
+