|
import gradio as gr |
|
import tensorflow as tf |
|
|
|
|
|
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") |
|
""" |
|
|
|
text = preprocess_text(text) |
|
|
|
|
|
prediction = model.predict([text])[0][0] |
|
|
|
|
|
if prediction > 0.5: |
|
return "positive" |
|
else: |
|
return "negative" |
|
|
|
|
|
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text") |
|
|
|
|
|
iface.launch() |