Commit
·
1f2ab71
1
Parent(s):
19346d3
updated and restructured app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,15 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
|
4 |
|
5 |
-
|
6 |
-
model = keras.models.load_model("sentimentality.h5")
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
text = tf.keras.preprocessing.sequence.pad_sequences(tokenizer.texts_to_sequences(text), maxlen=max_len)
|
16 |
-
|
17 |
-
# Make a prediction
|
18 |
-
prediction = model.predict(text)[0][0]
|
19 |
-
|
20 |
-
# Return the probabilities of each sentiment
|
21 |
-
positive_prob = round(prediction * 100, 2)
|
22 |
-
negative_prob = round((1 - prediction) * 100, 2)
|
23 |
-
neutral_prob = 100 - positive_prob - negative_prob
|
24 |
-
|
25 |
-
return f"Positive: {positive_prob}%\nNegative: {negative_prob}%\nNeutral: {neutral_prob}%"
|
26 |
-
|
27 |
-
# Define the interface of the Gradio app
|
28 |
-
iface = gr.Interface(
|
29 |
-
fn=predict_sentiment,
|
30 |
-
inputs=gr.inputs.Textbox(label="Enter text here:"),
|
31 |
-
outputs=gr.outputs.Textbox(label="Sentiment probabilities:"),
|
32 |
-
title="Sentiment Analysis",
|
33 |
-
description="Enter some text and get the probabilities of the sentiment.",
|
34 |
-
)
|
35 |
-
|
36 |
-
# Run the Gradio app
|
37 |
-
iface.launch()
|
|
|
1 |
+
from tensorflow.keras.models import load_model
|
2 |
+
import numpy as np
|
3 |
+
import cv2
|
4 |
|
5 |
+
model = load_model('sentimentality.h5')
|
|
|
6 |
|
7 |
+
def sentiment(text):
|
8 |
+
result = model(text)[0]
|
9 |
+
label = result['label']
|
10 |
+
score = round(result['score'], 3)
|
11 |
+
return f"{label} ({score})"
|
12 |
|
13 |
+
input_text = gr.inputs.Textbox(label="Enter text here to be classified:")
|
14 |
+
label = gr.outputs.Label(num_top_classes=2)
|
15 |
+
gr.Interface(fn=predict_from_img, inputs=image, outputs=label,title = 'Sentiment-Analysis').launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|