Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import gradio as gr
|
3 |
+
import pandas as pd
|
4 |
+
import os
|
5 |
+
from tensorflow.keras.layers import TextVectorization
|
6 |
+
|
7 |
+
df = pd.read_csv('train.csv')
|
8 |
+
|
9 |
+
X = df['comment_text']
|
10 |
+
y = df[df.columns[2:]].values
|
11 |
+
|
12 |
+
MAX_FEATURES = 200000 # number of words in the vocab
|
13 |
+
|
14 |
+
vectorizer = TextVectorization(max_tokens=MAX_FEATURES,
|
15 |
+
output_sequence_length=1800,
|
16 |
+
output_mode='int')
|
17 |
+
|
18 |
+
vectorizer.adapt(X.values)
|
19 |
+
|
20 |
+
model = tf.keras.models.load_model('hate_speech.h5')
|
21 |
+
|
22 |
+
def score_comment(comment):
|
23 |
+
vectorized_comment = vectorizer([comment])
|
24 |
+
results = model.predict(vectorized_comment)
|
25 |
+
|
26 |
+
for idx, col in enumerate(df.columns[2:]):
|
27 |
+
if results[0][idx]>0.5:
|
28 |
+
return 'Hate Speech detected'
|
29 |
+
|
30 |
+
return 'No hate speech detected'
|
31 |
+
|
32 |
+
interface = gr.Interface(fn=score_comment,
|
33 |
+
inputs=gr.Textbox(lines=2, placeholder='Comment to score'),
|
34 |
+
outputs='text')
|
35 |
+
|
36 |
+
interface.launch(share=True)
|