DrishtiSharma commited on
Commit
94555c5
1 Parent(s): aacd30a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -2
app.py CHANGED
@@ -1,4 +1,37 @@
1
- import transformers
 
2
  import gradio as gr
3
- from transformers import pipeline
 
 
 
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Import required libraries
2
+ import pickle
3
  import gradio as gr
4
+ import gradio.inputs
5
+ import pandas as pd
6
+ import numpy as np
7
+ import tensorflow as tf
8
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
9
 
10
+
11
+ #Loading the tokenizer
12
+ with open('tokenizer.pickle', 'rb') as f:
13
+ tokenizer = pickle.load(f)
14
+
15
+
16
+
17
+ def predict_sentiment(text):
18
+ sentiment = ['Do you really dislike the movie so much?','Hmm...your thoughts are neutral about the movie.','Wow! Your a big fan.']
19
+ sequence_test = tokenizer.texts_to_sequences([text])
20
+ padded_test = pad_sequences(sequence_test, maxlen= 52)
21
+ text=padded_test
22
+ model = tf.keras.models.load_model("huggingface/keras-io/bidirectional-lstm-imdb")
23
+ X = [text for _ in range(len(model.input))]
24
+ a=model.predict(X, verbose=0)
25
+ return sentiment[np.around(a, decimals=0).argmax(axis=1)[0]]
26
+ description = "Give a review of a movie that you like(or hate, sarcasm intended XD) and the model will let you know just how much your review truely reflects your emotions. "
27
+
28
+
29
+ #Gradio app
30
+ iface = gr.Interface(predict_sentiment,
31
+ inputs= gradio.inputs.Textbox( lines=1, placeholder=None, default="", label=None),
32
+ outputs='text',
33
+ title="Sentiment analysis of movie reviews",
34
+ description=description,
35
+ theme="grass")
36
+ iface.launch(enable_queue = True, inline=False, share = True)
37
+