ShuklaShreyansh
commited on
theme
Browse files
app.py
CHANGED
@@ -1,39 +1,41 @@
|
|
1 |
-
import tensorflow as tf
|
2 |
-
import pickle
|
3 |
-
import gradio as gr
|
4 |
-
import numpy as np
|
5 |
-
import json
|
6 |
-
|
7 |
-
|
8 |
-
with open('tokenizer.json') as file:
|
9 |
-
tokenizer_data = file.read()
|
10 |
-
tokenizer = tf.keras.preprocessing.text.tokenizer_from_json(tokenizer_data)
|
11 |
-
|
12 |
-
|
13 |
-
def Infernce_Pipe(text,max_length = 100):
|
14 |
-
model = tf.keras.models.load_model("LSTM_senti.h5")
|
15 |
-
|
16 |
-
sequences = tokenizer.texts_to_sequences([text])
|
17 |
-
|
18 |
-
padded = tf.keras.preprocessing.sequence.pad_sequences(sequences, maxlen=max_length, padding='post', truncating='post')
|
19 |
-
|
20 |
-
pred = model.predict(padded)
|
21 |
-
predicted_index = np.argmax(pred)
|
22 |
-
# Define the label mapping
|
23 |
-
labels = ['Negative', 'Neutral', 'Positive']
|
24 |
-
|
25 |
-
# Map index to label
|
26 |
-
predicted_label = labels[predicted_index]
|
27 |
-
|
28 |
-
return predicted_label
|
29 |
-
|
30 |
-
interface = gr.Interface(
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import pickle
|
3 |
+
import gradio as gr
|
4 |
+
import numpy as np
|
5 |
+
import json
|
6 |
+
|
7 |
+
|
8 |
+
with open('tokenizer.json') as file:
|
9 |
+
tokenizer_data = file.read()
|
10 |
+
tokenizer = tf.keras.preprocessing.text.tokenizer_from_json(tokenizer_data)
|
11 |
+
|
12 |
+
|
13 |
+
def Infernce_Pipe(text,max_length = 100):
|
14 |
+
model = tf.keras.models.load_model("LSTM_senti.h5")
|
15 |
+
|
16 |
+
sequences = tokenizer.texts_to_sequences([text])
|
17 |
+
|
18 |
+
padded = tf.keras.preprocessing.sequence.pad_sequences(sequences, maxlen=max_length, padding='post', truncating='post')
|
19 |
+
|
20 |
+
pred = model.predict(padded)
|
21 |
+
predicted_index = np.argmax(pred)
|
22 |
+
# Define the label mapping
|
23 |
+
labels = ['Negative', 'Neutral', 'Positive']
|
24 |
+
|
25 |
+
# Map index to label
|
26 |
+
predicted_label = labels[predicted_index]
|
27 |
+
|
28 |
+
return predicted_label
|
29 |
+
|
30 |
+
interface = gr.Interface(
|
31 |
+
fn=Infernce_Pipe,
|
32 |
+
inputs=gr.Textbox(placeholder="Enter text here..."),
|
33 |
+
outputs=gr.Text(label="Prediction"),
|
34 |
+
title="Sentiment Analysis on Customer Review",
|
35 |
+
description="Enter a review to get its sentiment classification (Negative, Neutral, Positive). \n\n **If you find this model helpful, please like it using the button above in the navigation bar!**",
|
36 |
+
theme="huggingface"
|
37 |
+
)
|
38 |
+
|
39 |
+
interface.launch(share=True)
|
40 |
+
|
41 |
+
|