ShuklaShreyansh
commited on
Upload 3 files
Browse files- LSTM_senti.h5 +3 -0
- app.py +39 -0
- tokenizer.json +0 -0
LSTM_senti.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4bb6f3953f90b859667035fcc4ff3686809c5fc8db2f1ca00a70411581deb87c
|
3 |
+
size 9402280
|
app.py
ADDED
@@ -0,0 +1,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)."
|
36 |
+
)
|
37 |
+
|
38 |
+
interface.launch(share=True)
|
39 |
+
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|