Spaces:
Sleeping
Sleeping
| import tensorflow as tf | |
| from tensorflow.keras.layers import TextVectorization,LSTM | |
| import gradio as gr | |
| import pandas as pd | |
| import os | |
| df = pd.read_csv('train.csv') | |
| MAX_FEATURES = 200000 | |
| vectorizer = TextVectorization(max_tokens=MAX_FEATURES, | |
| output_sequence_length=1800, | |
| output_mode='int') | |
| # Adapt the vectorizer to the training data | |
| vectorizer.adapt(df['comment_text'].values) | |
| model = tf.keras.models.load_model('toxicity.keras') | |
| def score_comment(comment): | |
| vectorized_comment = vectorizer([comment]) | |
| results = model.predict(vectorized_comment) | |
| text = '' | |
| for idx, col in enumerate(df.columns[2:]): | |
| text += '{}: {}\n'.format(col, results[0][idx]>0.5) | |
| return text | |
| interface = gr.Interface(fn=score_comment, | |
| inputs=gr.Textbox(lines=2, placeholder='Comment to score'), | |
| outputs='text') | |
| interface.launch(share=True) |