Spaces:
Build error
Build error
File size: 1,007 Bytes
32012bf | 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 | import gradio as gd
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
import pickle
model = load_model("sentiment_analysis_LSTM.h5")
with open('tokenizer.pickle', 'rb') as handle:
tokenizer = pickle.load(handle)
def preprocess(text):
sequences = tokenizer.texts_to_sequences([text])
padded_sequences = pad_sequences(sequences, maxlen = 250)
return padded_sequences
def predict(text):
processed_text = preprocess(text)
prediction = model.predict(processed_text)
return "Positive" if prediction[0][0] > 0.5 else "Negative"
gradio = gd.Interface(
fn = predict,
inputs = gd.Textbox(lines = 2, placeholder = 'Enter a sentence here...'),
outputs = 'text',
title = "Sentiment Analysis",
description = "Enter a sentence to predict its sentiment. The model will predict it as Positive or Negative ")
gradio.launch(share = True) |