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 = "
Space by Drishti Sharma
Keras example by François Chollet
" 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)