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