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.6 : output = f"Positive review with {result : .0%} confidence score" elif result[:] < 0.4: output = f"Negative review with {result : .0%} confidence score" else: output = "Neutral" 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)