Commit
·
078e4df
1
Parent(s):
4386646
software engineer draft
Browse files
app.py
CHANGED
@@ -5,29 +5,17 @@ import tensorflow as tf
|
|
5 |
model = tf.keras.models.load_model("sentimentality.h5")
|
6 |
|
7 |
def predict_sentiment(text):
|
8 |
-
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
-
|
15 |
-
str: The predicted sentiment of the input text (either "positive" or "negative")
|
16 |
-
"""
|
17 |
-
# Preprocess the input text
|
18 |
-
text = preprocess_text(text)
|
19 |
-
|
20 |
-
# Make the prediction using the loaded model
|
21 |
-
prediction = model.predict([text])[0][0]
|
22 |
-
|
23 |
-
# Return the predicted sentiment
|
24 |
-
if prediction > 0.5:
|
25 |
-
return "positive"
|
26 |
-
else:
|
27 |
-
return "negative"
|
28 |
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
# Run the interface
|
33 |
iface.launch()
|
|
|
5 |
model = tf.keras.models.load_model("sentimentality.h5")
|
6 |
|
7 |
def predict_sentiment(text):
|
8 |
+
# preprocess input text
|
9 |
+
processed_text = preprocess(text)
|
10 |
|
11 |
+
# predict sentiment
|
12 |
+
prediction = model.predict([processed_text])[0][0]
|
13 |
+
sentiment = 'positive' if prediction >= 0.5 else 'negative'
|
14 |
|
15 |
+
return sentiment
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
iface = gr.Interface(fn=predict_sentiment,
|
18 |
+
inputs=gr.inputs.Textbox(label='Input Text'),
|
19 |
+
outputs=gr.outputs.Label(label='Sentiment Prediction'))
|
20 |
|
|
|
21 |
iface.launch()
|