Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
-
import tensorflow as tf
|
2 |
-
from tensorflow.keras.layers import TextVectorization,LSTM
|
3 |
-
import gradio as gr
|
4 |
-
import pandas as pd
|
5 |
-
import os
|
6 |
-
|
7 |
-
df = pd.read_csv(
|
8 |
-
|
9 |
-
MAX_FEATURES = 200000
|
10 |
-
|
11 |
-
vectorizer = TextVectorization(max_tokens=MAX_FEATURES,
|
12 |
-
output_sequence_length=1800,
|
13 |
-
output_mode='int')
|
14 |
-
|
15 |
-
# Adapt the vectorizer to the training data
|
16 |
-
vectorizer.adapt(df['comment_text'].values)
|
17 |
-
|
18 |
-
model = tf.keras.models.load_model('toxicity.keras')
|
19 |
-
|
20 |
-
def score_comment(comment):
|
21 |
-
vectorized_comment = vectorizer([comment])
|
22 |
-
results = model.predict(vectorized_comment)
|
23 |
-
|
24 |
-
text = ''
|
25 |
-
for idx, col in enumerate(df.columns[2:]):
|
26 |
-
text += '{}: {}\n'.format(col, results[0][idx]>0.5)
|
27 |
-
|
28 |
-
return text
|
29 |
-
|
30 |
-
interface = gr.Interface(fn=score_comment,
|
31 |
-
inputs=gr.Textbox(lines=2, placeholder='Comment to score'),
|
32 |
-
outputs='text')
|
33 |
-
|
34 |
interface.launch(share=True)
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
from tensorflow.keras.layers import TextVectorization,LSTM
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
import os
|
6 |
+
|
7 |
+
df = pd.read_csv('train.csv')
|
8 |
+
|
9 |
+
MAX_FEATURES = 200000
|
10 |
+
|
11 |
+
vectorizer = TextVectorization(max_tokens=MAX_FEATURES,
|
12 |
+
output_sequence_length=1800,
|
13 |
+
output_mode='int')
|
14 |
+
|
15 |
+
# Adapt the vectorizer to the training data
|
16 |
+
vectorizer.adapt(df['comment_text'].values)
|
17 |
+
|
18 |
+
model = tf.keras.models.load_model('toxicity.keras')
|
19 |
+
|
20 |
+
def score_comment(comment):
|
21 |
+
vectorized_comment = vectorizer([comment])
|
22 |
+
results = model.predict(vectorized_comment)
|
23 |
+
|
24 |
+
text = ''
|
25 |
+
for idx, col in enumerate(df.columns[2:]):
|
26 |
+
text += '{}: {}\n'.format(col, results[0][idx]>0.5)
|
27 |
+
|
28 |
+
return text
|
29 |
+
|
30 |
+
interface = gr.Interface(fn=score_comment,
|
31 |
+
inputs=gr.Textbox(lines=2, placeholder='Comment to score'),
|
32 |
+
outputs='text')
|
33 |
+
|
34 |
interface.launch(share=True)
|