Team Ai
Apppublic

meghost/Profanity_Filter

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py35 linesDownload Raw Back to root
1import gradio as gr2from keras.layers import TextVectorization3import tensorflow as tf4import pandas as pd5 6df = pd.read_csv('train.csv')7 8X = df['comment_text']9y = df[df.columns[2:]].values10 11MAX_FEATURES = 20000012vectorizer = TextVectorization(max_tokens=MAX_FEATURES,13                               output_sequence_length=1800,14                               output_mode='int')15vectorizer.adapt(X.values)16 17model = tf.keras.models.load_model('pfilter.h5')18 19 20def 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 text29 30 31interface = gr.Interface(fn=score_comment,32                         inputs=gr.components.Textbox33                         (lines=2, placeholder='Comment to Score'), outputs='text')34interface.launch(inline=False)35