Spaces:
Runtime error
Runtime error
| import pandas as pd | |
| import numpy as np | |
| import gradio as gr | |
| import tensorflow as tf | |
| from tensorflow.keras.layers import TextVectorization, LSTM | |
| from tensorflow.keras.models import load_model | |
| df = pd.read_csv('https://raw.githubusercontent.com/whitehatjr1001/comment-toxicity-detecttion-/main/jigsaw-toxic-comment-classification-challenge/train.csv/train.csv') | |
| X = df['comment_text'] | |
| y = df[df.columns[2:]].values | |
| max_features = 2000000 | |
| vecterizor = TextVectorization(max_tokens=max_features, output_sequence_length=1800, output_mode='int') | |
| vecterizor.adapt(X.values) | |
| model_path = 'commenttoxicity (1).h5' | |
| # Load the model with custom_objects | |
| model = load_model(model_path) | |
| def score_comment(comment): | |
| vectorized_comment = vecterizor([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) | |