Spaces:
Runtime error
Runtime error
File size: 1,372 Bytes
94555c5 9f56dae 94555c5 6b35d8e 94555c5 d3bb9d5 94555c5 6b35d8e 94555c5 de57948 94555c5 93b4a68 94555c5 |
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 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= 52)
text=padded_test
model = from_pretrained_keras("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 = "Provide an opinion regarding a movie 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)
|