Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import nltk
|
| 3 |
-
import
|
| 4 |
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
| 5 |
|
| 6 |
nltk.download("vader_lexicon")
|
|
@@ -14,14 +14,27 @@ def sentiment_analysis(text):
|
|
| 14 |
values = list(scores.values())
|
| 15 |
colors = ['red' if label == 'neg' else 'green' if label == 'pos' else 'white' for label in labels]
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return gr.Image('sentiment_chart.png')
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import nltk
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
| 5 |
|
| 6 |
nltk.download("vader_lexicon")
|
|
|
|
| 14 |
values = list(scores.values())
|
| 15 |
colors = ['red' if label == 'neg' else 'green' if label == 'pos' else 'white' for label in labels]
|
| 16 |
|
| 17 |
+
fig = go.Figure(go.Bar(
|
| 18 |
+
x=values,
|
| 19 |
+
y=labels,
|
| 20 |
+
orientation='h',
|
| 21 |
+
marker=dict(color=colors)
|
| 22 |
+
))
|
| 23 |
|
| 24 |
+
fig.update_layout(
|
| 25 |
+
title="Sentiment Analysis",
|
| 26 |
+
xaxis_title="Score",
|
| 27 |
+
yaxis_title="Sentiment",
|
| 28 |
+
xaxis=dict(range=[0, 1]),
|
| 29 |
+
yaxis=dict(showgrid=True),
|
| 30 |
+
plot_bgcolor='rgba(0,0,0,0)',
|
| 31 |
+
paper_bgcolor='rgba(0,0,0,0)'
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
fig.update_xaxes(showgrid=True)
|
| 35 |
+
fig.update_yaxes(showgrid=True)
|
| 36 |
+
|
| 37 |
+
fig.write_image('sentiment_chart.png')
|
| 38 |
return gr.Image('sentiment_chart.png')
|
| 39 |
|
| 40 |
demo = gr.Interface(
|