import os
os.system('pip install tensorflow')
import tensorflow as tf
from tensorflow import keras
import numpy as np
import gradio as gr
tokenizer = tf.keras.preprocessing.text.Tokenizer()
#Reads Text Inputs Here
f=open('Inputs.txt','r')
inputs = f.read().split('\n')
f.close()
corpus = inputs
tokenizer.fit_on_texts(corpus)
sequences = tokenizer.texts_to_sequences(corpus)
max_length = max([len(s) for s in sequences])
# Load your saved model
model = tf.keras.models.load_model('sentiment_mini-test')
model.summary()
def use(input_text):
# Preprocess the input text
sequences = tokenizer.texts_to_sequences([input_text])
sequences = tf.keras.preprocessing.sequence.pad_sequences(sequences, padding='post', maxlen=max_length)
# Make a prediction on the input text
prediction = model.predict(sequences)[0]
# Print the prediction
if prediction[0]<0.5:
return "That's Negative! (" + str(round(round(1-prediction[0],2)*100,1)) + "% confidence)"
if prediction[0]>0.5:
return "That's Positive! (" + str(round(round(prediction[0],2)*100,1)) + "% confidence)"
iface = gr.Interface(fn=use,
inputs=gr.Textbox(lines=3, placeholder="Type Something Awesome..."),
outputs=gr.Textbox(lines=3, placeholder="Waiting For Magic..."),
title="Use RSA (Review Sentiment Analysis) v0.1.2",
description="This is an NLP model that accepts a text string as input and simply outputs if the string is mean or nice with about 96.5% accuracy. It also provides you with a score of how positive or negative it is.",
article="\nRSA v0.1.2: @2.29M Params w/ 96.5% acc. & 388MB dataset + 1.59MB output dataset. Trained on this Kaggle dataset",
examples=[
["I went there today! The cut was terrible! I have an awful experience. They lady that cut my hair was nice but she wanted to leave early so she made a disaster in my head!"],
["Yes! Awesome soy cap, scone, and atmosphere. Nice place to hang out & read, and free WiFi with no login procedure."],
["Overpriced, salty and overrated!!! Why this place is so popular I will never understand."],
["This Valentines Day I ordered a pizza for my boyfriend and asked that they make a heart on it out of green peppers. The pizza was great, the heart was perfect, and he loved it!"]
])
iface.launch()