Commit
·
b4a2a0b
1
Parent(s):
6ed2700
fn 7
Browse files
app.py
CHANGED
|
@@ -21,29 +21,28 @@ def predict_sentiment(text):
|
|
| 21 |
proba = model.predict(text)[0]
|
| 22 |
# Normalize the probabilities
|
| 23 |
proba /= proba.sum()
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 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()
|
|
|
|
| 21 |
proba = model.predict(text)[0]
|
| 22 |
# Normalize the probabilities
|
| 23 |
proba /= proba.sum()
|
| 24 |
+
# Get the predicted sentiment label
|
| 25 |
+
sentiment_label = ['Positive', 'Negative', 'Neutral'][np.argmax(proba)]
|
| 26 |
+
# Determine the color based on the sentiment label
|
| 27 |
+
if sentiment_label == 'Positive':
|
| 28 |
+
color = '#2a9d8f'
|
| 29 |
+
elif sentiment_label == 'Negative':
|
| 30 |
+
color = '#e76f51'
|
| 31 |
+
else:
|
| 32 |
+
color = '#264653'
|
| 33 |
+
# Return the sentiment label and color
|
| 34 |
+
return {'label': sentiment_label, 'color': color}
|
| 35 |
|
| 36 |
# Define the Gradio interface
|
| 37 |
iface = gr.Interface(
|
| 38 |
fn=predict_sentiment,
|
| 39 |
inputs=gr.inputs.Textbox(label='Enter text here'),
|
| 40 |
+
outputs=gr.outputs.Label(label='Sentiment', default='Neutral',
|
| 41 |
+
font_size=30, font_family='Arial',
|
| 42 |
+
background_color='#f8f8f8',
|
| 43 |
+
color='black', value=None),
|
|
|
|
| 44 |
title='SENTIMENT ANALYSIS'
|
| 45 |
)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Launch the interface
|
| 48 |
iface.launch()
|