File size: 811 Bytes
9724286 2e71df7 52fe9f8 2e71df7 73e1dac 2e71df7 73e1dac 2e71df7 |
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 gr
import tensorflow as tf
import numpy as np
# Load the pre-trained model
model = tf.keras.models.load_model('sentimentality.h5')
# Define a function to preprocess the text input
def preprocess(text):
tokenizer = tf.keras.preprocessing.text.Tokenizer()
tokenizer.fit_on_texts([text])
text = tokenizer.texts_to_sequences([text])
text = tf.keras.preprocessing.sequence.pad_sequences(text, maxlen=500, padding='post', truncating='post')
return text
def sentiment_analysis(text):
scores = model.predict(text)
return scores
iface = gr.Interface(
fn=sentiment_analysis,
inputs=gr.Textbox(placeholder="Enter a positive or negative sentence here..."),
outputs="label",
interpretation="default",
examples=[["This is wonderful!"]])
iface.launch()
|