File size: 1,681 Bytes
9f56dae
94555c5
 
d11c05f
 
5886659
 
94555c5
d11c05f
94555c5
d11c05f
 
94555c5
d11c05f
 
 
6b08e4f
44a0b8b
d2be599
44a0b8b
d2be599
d11c05f
3a21a09
d11c05f
ba1b8bc
 
f3d1c24
 
 
d11c05f
f3d1c24
8e4cbbb
d11c05f
f3d1c24
4b84559
8e4cbbb
2753ced
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
32
33
34
35
36
37
38
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
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

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)[0][0]
  if result >= 0.6 :
    return "Positive review"
  elif result <= 0.4:
    return "Negative review"
  else:
    return "Neutral review"
  

  
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."
article = "<div style='text-align: center;'><a href='https://huggingface.co/DrishtiSharma' target='_blank'>Space by Drishti Sharma</a><br><a href='https://keras.io/examples/nlp/bidirectional_lstm_imdb/' target='_blank'>Keras example by François Chollet</a></div>"

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