RohithMidigudla commited on
Commit
318ce2e
·
1 Parent(s): efef10c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import gradio as gr
4
+
5
+ import tensorflow as tf
6
+ from tensorflow.keras.layers import TextVectorization
7
+
8
+ df = pd.read_csv('/content/CommentToxicity/jigsaw-toxic-comment-classification-challenge/train.csv/train.csv')
9
+ df.shape
10
+
11
+ X = df['comment_text']
12
+ y = df[df.columns[2:]].values
13
+
14
+ max_features = 2000000
15
+
16
+ vecterizor = TextVectorization(max_tokens=max_features,output_sequence_length=1800,output_mode='int')
17
+
18
+ vecterizor.adapt(X.values)
19
+
20
+ model_path = 'commenttoxicity (1).h5'
21
+
22
+ model = tf.keras.models.load_model(model_path)
23
+
24
+
25
+ def score_comment(comment):
26
+ vectorized_comment = vecterizor([comment])
27
+ results = model.predict(vectorized_comment)
28
+
29
+ text = ''
30
+ for idx, col in enumerate(df.columns[2:]):
31
+ text += '{}: {}\n'.format(col, results[0][idx]>0.5)
32
+
33
+ return text
34
+
35
+ interface = gr.Interface(fn=score_comment,
36
+ inputs=gr.Textbox(lines=2, placeholder='Comment to score'),
37
+ outputs='text')
38
+
39
+ interface.launch(share=True)