Commit
·
6ed2700
1
Parent(s):
9a811e6
fn 6
Browse files
app.py
CHANGED
@@ -22,20 +22,28 @@ def predict_sentiment(text):
|
|
22 |
# Normalize the probabilities
|
23 |
proba /= proba.sum()
|
24 |
# Return the probability distribution
|
25 |
-
return {
|
26 |
|
27 |
-
#
|
|
|
|
|
|
|
28 |
iface = gr.Interface(
|
29 |
-
fn=predict_sentiment,
|
30 |
-
inputs=gr.inputs.Textbox(label=
|
31 |
-
outputs=gr.outputs.
|
|
|
|
|
|
|
|
|
|
|
32 |
)
|
33 |
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
iface.outputs[0].
|
39 |
|
40 |
# Launch the interface
|
41 |
iface.launch()
|
|
|
22 |
# Normalize the probabilities
|
23 |
proba /= proba.sum()
|
24 |
# Return the probability distribution
|
25 |
+
return {'Positive': float(proba[0]), 'Negative': float(proba[1]), 'Neutral': float(proba[2])}
|
26 |
|
27 |
+
# Define the possible classes
|
28 |
+
classes = ['Positive', 'Negative', 'Neutral']
|
29 |
+
|
30 |
+
# Define the Gradio interface
|
31 |
iface = gr.Interface(
|
32 |
+
fn=predict_sentiment,
|
33 |
+
inputs=gr.inputs.Textbox(label='Enter text here'),
|
34 |
+
outputs=gr.outputs.Bar(label='Sentiment Distribution',
|
35 |
+
colors=['#2a9d8f', '#e76f51', '#264653'],
|
36 |
+
value=[0.3, 0.3, 0.3],
|
37 |
+
min=0,
|
38 |
+
max=1),
|
39 |
+
title='SENTIMENT ANALYSIS'
|
40 |
)
|
41 |
|
42 |
+
# Set the class labels for the output
|
43 |
+
iface.outputs[0].type = 'bar'
|
44 |
+
iface.outputs[0].label = 'Sentiment Distribution'
|
45 |
+
iface.outputs[0].determine_labels_from_data = False
|
46 |
+
iface.outputs[0].labels = classes
|
47 |
|
48 |
# Launch the interface
|
49 |
iface.launch()
|