Spaces:
Runtime error
Runtime error
| #Import required libraries | |
| import pickle | |
| import gradio as gr | |
| import gradio.inputs | |
| import pandas as pd | |
| import numpy as np | |
| import tensorflow as tf | |
| from tensorflow.keras.preprocessing.sequence import pad_sequences | |
| from huggingface_hub.keras_mixin import from_pretrained_keras | |
| #Loading the tokenizer | |
| with open('tokenizer.pickle', 'rb') as f: | |
| tokenizer = pickle.load(f) | |
| def predict_sentiment(text): | |
| sentiment = ["I guess, I liked the movie, but I'm not sure it's my favorite."] | |
| sequence_test = tokenizer.texts_to_sequences([text]) | |
| padded_test = pad_sequences(sequence_test, maxlen= 64) | |
| text=padded_test | |
| model = from_pretrained_keras("keras-io/bidirectional-lstm-imdb") | |
| X = [text for _ in range(len(model.input))] | |
| a=model.predict(X) | |
| return sentiment[np.around(a, decimals=0).argmax(axis=1)[0]] | |
| description = "Provide an opinion regarding a movie as input and this app will suggest what the underlying sentiment is. " | |
| #Gradio app | |
| iface = gr.Interface(predict_sentiment, | |
| inputs= gradio.inputs.Textbox( lines=1, placeholder=None, default="", label=None), | |
| outputs='text', | |
| title="Sentiment Analysis of Movie Reviews", | |
| description=description, | |
| theme="grass") | |
| iface.launch(enable_queue = True, inline=False, share = True) | |