File size: 1,242 Bytes
9f56dae
94555c5
 
d11c05f
 
94555c5
d11c05f
94555c5
d11c05f
 
94555c5
d11c05f
 
 
 
 
 
 
 
 
 
 
 
 
 
bf1ed1a
d11c05f
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
import tensorflow as tf 
from tensorflow.keras.preprocessing.sequence import pad_sequences
import pickle
from huggingface_hub import from_pretrained_keras

model = from_pretrained_keras("keras-io/bidirectional-lstm-imdb")

with open('tokenizer.pickle', 'rb') as file:
    tokenizer = pickle.load(file)
    
def decide(text):
  tokenized_text = tokenizer.texts_to_sequences([text])
  padded_tokens = pad_sequences(tokenized_text, maxlen= 200)
  result = model.predict(padded_tokens, verbose=0)
  if result[:] < 0.5 :
    output = "negative"
  else:
    output = "positive"
  return output
  
example_sentence_1 = "I hate the movie, they made no effort in making the movie. Waste of time!"
example_sentence_2 = "Awesome movie! Loved the way in which the hero acted."
examples = [[example_sentence_1], [example_sentence_2]]
  
description = "Write out a movie review to know the underlying sentiment."

gr.Interface(decide, inputs= gr.inputs.Textbox( lines=1, placeholder=None, default="", label=None), outputs='text', examples=examples,
             title="Sentiment analysis of movie reviews",description=description, allow_flagging="auto", 
             flagging_dir='flagging records').launch(inline=False, share = True)