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 | |
| #Loading the tokenizer | |
| with open('tokenizer.pickle', 'rb') as f: | |
| tokenizer = pickle.load(f) | |
| def predict_sentiment(text): | |
| sentiment = ['Do you really dislike the movie so much?','Hmm...your thoughts are neutral about the movie.','Wow! Your a big fan.'] | |
| sequence_test = tokenizer.texts_to_sequences([text]) | |
| padded_test = pad_sequences(sequence_test, maxlen= 52) | |
| text=padded_test | |
| model = tf.keras.models.load_model("huggingface/keras-io/bidirectional-lstm-imdb") | |
| X = [text for _ in range(len(model.input))] | |
| a=model.predict(X, verbose=0) | |
| return sentiment[np.around(a, decimals=0).argmax(axis=1)[0]] | |
| description = "Give a review of a movie that you like(or hate, sarcasm intended XD) and the model will let you know just how much your review truely reflects your emotions. " | |
| #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) | |