File size: 1,142 Bytes
318ce2e
 
 
 
3069cd6
 
318ce2e
8727785
318ce2e
 
 
 
 
 
3069cd6
318ce2e
 
 
 
3069cd6
0c1de34
318ce2e
 
 
 
 
 
 
 
 
 
 
 
 
3069cd6
318ce2e
 
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
37
38
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)