Sambhavnoobcoder's picture
codex codes
4386646
raw
history blame
867 Bytes
import gradio as gr
import tensorflow as tf
# Load the saved model
model = tf.keras.models.load_model("sentimentality.h5")
def predict_sentiment(text):
"""
This function takes a text input and returns the predicted sentiment using a saved model.
Parameters:
text (str): The input text to be analyzed
Returns:
str: The predicted sentiment of the input text (either "positive" or "negative")
"""
# Preprocess the input text
text = preprocess_text(text)
# Make the prediction using the loaded model
prediction = model.predict([text])[0][0]
# Return the predicted sentiment
if prediction > 0.5:
return "positive"
else:
return "negative"
# Create the Gradio interface
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text")
# Run the interface
iface.launch()