DrishtiSharma's picture
Upload app.py
479d51b
raw
history blame
No virus
1.55 kB
import gradio as gr
import gradio.inputs
import pandas as pd
import numpy as np # linear algebra
import os #interacting with input and output directories
import tensorflow as tf #framework for creating the neural network
from tensorflow.keras.preprocessing.sequence import pad_sequences
import pickle
with open('tokenizer.pickle', 'rb') as handle:
tokenizer = pickle.load(handle)
# loading
def fn(X_test):
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([X_test])
padded_test = pad_sequences(sequence_test, maxlen= 52)
Xtest=padded_test
model = tf.keras.models.load_model(os.path.join(os.getcwd(), 'deepverse.h5'))
X = [Xtest 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. "
here = gr.Interface(fn,
inputs= gradio.inputs.Textbox( lines=1, placeholder=None, default="", label=None),
outputs='text',
title="Sentiment analysis of movie reviews",
description=description,
theme="peach",
allow_flagging="auto",
flagging_dir='flagging records')
here.launch(inline=False, share = True)