Spaces:
Runtime error
Runtime error
Commit ·
bde20b1
1
Parent(s): dec356f
Upload 4 files
Browse files- app.py +28 -0
- requirements.txt +5 -0
- tokenizer.pickle +3 -0
- toxic.h5 +3 -0
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import pickle
|
| 5 |
+
from keras.utils import pad_sequences
|
| 6 |
+
|
| 7 |
+
max_len = 200
|
| 8 |
+
|
| 9 |
+
# set the vocabulary mapping on a new TextVectorization layer
|
| 10 |
+
with open('tokenizer.pickle', 'rb') as handle:
|
| 11 |
+
tokenizer = pickle.load(handle)
|
| 12 |
+
model = tf.keras.models.load_model('toxic.h5')
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
arr=["toxic","severe_toxic","obscene threat","insult","identity_hate"]
|
| 16 |
+
def score_comment(comment):
|
| 17 |
+
sequences = tokenizer.texts_to_sequences([comment])
|
| 18 |
+
input = pad_sequences(sequences,maxlen=max_len)
|
| 19 |
+
results = model.predict(input)
|
| 20 |
+
text = ''
|
| 21 |
+
for i in range(len(arr)):
|
| 22 |
+
text += '{}: {}\n'.format(arr[i], results[0][i]>0.5)
|
| 23 |
+
return text
|
| 24 |
+
|
| 25 |
+
interface = gr.Interface(fn=score_comment,
|
| 26 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder='Comment to score'),
|
| 27 |
+
outputs='text')
|
| 28 |
+
interface.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==3.36.1
|
| 2 |
+
keras==2.13.1
|
| 3 |
+
pandas==2.0.3
|
| 4 |
+
Pillow==10.0.0
|
| 5 |
+
tensorflow==2.13.0
|
tokenizer.pickle
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d77d70fdcb351caea5ee6d9dfbd607f61ac419b4a04ec521d84605bbc9f41165
|
| 3 |
+
size 7740158
|
toxic.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:73b4cc477172e73a10c43cc26bc3c628a71b2a2a6c145b5edf6a8ce42d4905e8
|
| 3 |
+
size 1816640
|