File size: 867 Bytes
2f9f9d9 625452f b976ff0 4386646 b976ff0 4386646 1a2c81f 4386646 1a2c81f 4386646 1a2c81f 4386646 1a2c81f 4386646 60ae5e6 1a2c81f 4386646 60ae5e6 4386646 |
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 29 30 31 32 33 |
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() |