RohithMidigudla commited on
Commit
3069cd6
·
verified ·
1 Parent(s): 5110a60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -1,9 +1,9 @@
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('https://raw.githubusercontent.com/whitehatjr1001/comment-toxicity-detecttion-/main/jigsaw-toxic-comment-classification-challenge/train.csv/train.csv')
9
 
@@ -12,14 +12,13 @@ y = df[df.columns[2:]].values
12
 
13
  max_features = 2000000
14
 
15
- vecterizor = TextVectorization(max_tokens=max_features,output_sequence_length=1800,output_mode='int')
16
-
17
  vecterizor.adapt(X.values)
18
 
19
  model_path = 'commenttoxicity (1).h5'
20
 
21
- model = tf.keras.models.load_model(model_path)
22
-
23
 
24
  def score_comment(comment):
25
  vectorized_comment = vecterizor([comment])
@@ -33,6 +32,6 @@ def score_comment(comment):
33
 
34
  interface = gr.Interface(fn=score_comment,
35
  inputs=gr.Textbox(lines=2, placeholder='Comment to score'),
36
- outputs='text')
37
 
38
  interface.launch(share=True)
 
1
  import pandas as pd
2
  import numpy as np
3
  import gradio as gr
 
4
  import tensorflow as tf
5
+ from tensorflow.keras.layers import TextVectorization, LSTM
6
+ from tensorflow.keras.models import load_model
7
 
8
  df = pd.read_csv('https://raw.githubusercontent.com/whitehatjr1001/comment-toxicity-detecttion-/main/jigsaw-toxic-comment-classification-challenge/train.csv/train.csv')
9
 
 
12
 
13
  max_features = 2000000
14
 
15
+ vecterizor = TextVectorization(max_tokens=max_features, output_sequence_length=1800, output_mode='int')
 
16
  vecterizor.adapt(X.values)
17
 
18
  model_path = 'commenttoxicity (1).h5'
19
 
20
+ # Load the model with custom_objects
21
+ model = load_model(model_path, custom_objects={'LSTM': LSTM})
22
 
23
  def score_comment(comment):
24
  vectorized_comment = vecterizor([comment])
 
32
 
33
  interface = gr.Interface(fn=score_comment,
34
  inputs=gr.Textbox(lines=2, placeholder='Comment to score'),
35
+ outputs='text')
36
 
37
  interface.launch(share=True)