Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,7 +26,7 @@ def sentiment_pie_chart(df):
|
|
| 26 |
|
| 27 |
# Create a pie chart
|
| 28 |
fig, ax = plt.subplots()
|
| 29 |
-
sentiment_counts.plot(kind='pie', autopct='%1.1f%%',
|
| 30 |
ax.set_title('Review Sentiment Chart')
|
| 31 |
|
| 32 |
return fig
|
|
@@ -42,6 +42,8 @@ def read_reviews_and_analyze_sentiment(file_object):
|
|
| 42 |
|
| 43 |
# Apply the get_sentiment function to each review in the DataFrame
|
| 44 |
df['Sentiment'] = df['Reviews'].apply(sentiment_analyzer)
|
|
|
|
|
|
|
| 45 |
chart_object = sentiment_pie_chart(df)
|
| 46 |
return df, chart_object
|
| 47 |
|
|
@@ -52,6 +54,6 @@ demo = gr.Interface(fn=read_reviews_and_analyze_sentiment,
|
|
| 52 |
inputs=[gr.File(file_types=["xlsx"], label="Upload your reviews file")],
|
| 53 |
outputs=[gr.Dataframe(label="Sentiments"), gr.Plot(label="Sentiment Analysis")],
|
| 54 |
title="Sentiment Analyzer",
|
| 55 |
-
description="Analyze the sentiment based on
|
| 56 |
demo.launch()
|
| 57 |
|
|
|
|
| 26 |
|
| 27 |
# Create a pie chart
|
| 28 |
fig, ax = plt.subplots()
|
| 29 |
+
sentiment_counts.plot(kind='pie', autopct='%1.1f%%', labels=None, colors=['green', 'red'])
|
| 30 |
ax.set_title('Review Sentiment Chart')
|
| 31 |
|
| 32 |
return fig
|
|
|
|
| 42 |
|
| 43 |
# Apply the get_sentiment function to each review in the DataFrame
|
| 44 |
df['Sentiment'] = df['Reviews'].apply(sentiment_analyzer)
|
| 45 |
+
df = df[['Sentiment'] + [col for col in df.columns if col != 'Sentiment']]
|
| 46 |
+
|
| 47 |
chart_object = sentiment_pie_chart(df)
|
| 48 |
return df, chart_object
|
| 49 |
|
|
|
|
| 54 |
inputs=[gr.File(file_types=["xlsx"], label="Upload your reviews file")],
|
| 55 |
outputs=[gr.Dataframe(label="Sentiments"), gr.Plot(label="Sentiment Analysis")],
|
| 56 |
title="Sentiment Analyzer",
|
| 57 |
+
description="Analyze the sentiment based on reviews (Excel file .xlsx must contain a 'Reviews' column)")
|
| 58 |
demo.launch()
|
| 59 |
|