Spaces:
Runtime error
Runtime error
File size: 1,101 Bytes
4734e0d 03d6caa 7e18c05 4734e0d 7e18c05 4734e0d 5d67345 4734e0d 017304c 4734e0d ca7dc37 017304c 4734e0d 4a1f3f9 |
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 |
import gradio as gr
import tensorflow as tf
import pandas as pd
from tensorflow.keras.layers import TextVectorization
model = tf.keras.models.load_model('toxic-detect.h5')
df = pd.read_csv('train.csv')
X = df.comment_text
vectorizer = TextVectorization(max_tokens=200000,
output_sequence_length=1800,
output_mode='int')
vectorizer.adapt(X.values)
def evaluate_comment(Comment):
processed_Comment = vectorizer([Comment])
res = model.predict(processed_Comment)
text = ''
for i, col in enumerate(df.columns[2:]):
text += '{}: \t\t{}\n'.format(col.upper(), 'πππ'.upper() if res[0][i] > 0.5 else 'πππ'.upper())
return text
interface = gr.Interface(fn = evaluate_comment, title='ToxClass', inputs = gr.inputs.Textbox(lines = 4, label='Comment', placeholder='Comment to evaluate'),
outputs = gr.Textbox(lines=4, label='Evaluation'), description="An NLP model that classifies level of toxicity of the sentence.")
interface.launch() |