Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,13 +14,24 @@ def sentiment_analyzer(review):
|
|
| 14 |
sentiment = analyzer(review)
|
| 15 |
return sentiment[0]['label']
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def Read_Analyze(file_object):
|
| 18 |
df = pd.read_csv(file_object, encoding='latin1')
|
| 19 |
|
| 20 |
if 'Review' not in df.columns:
|
| 21 |
raise ValueError("Review column not found")
|
| 22 |
-
|
| 23 |
-
|
|
|
|
| 24 |
|
| 25 |
# result = sentiment_analyzer("C:/Users/ankitdwivedi/OneDrive - Adobe/Desktop/NLP Projects/Video to Text Summarization/Files/all-data.csv")
|
| 26 |
# print (result)
|
|
@@ -29,7 +40,8 @@ gr.close_all()
|
|
| 29 |
|
| 30 |
demo = gr.Interface(fn=Read_Analyze,
|
| 31 |
inputs=[gr.File(file_types = ["csv"],
|
| 32 |
-
label="Upload your review file")],
|
|
|
|
| 33 |
title="Project 3: Sentiment Analyzer",
|
| 34 |
description="""This is a Sentiment Analysis Model.""")
|
| 35 |
demo.launch()
|
|
|
|
| 14 |
sentiment = analyzer(review)
|
| 15 |
return sentiment[0]['label']
|
| 16 |
|
| 17 |
+
def sentiment_bar_chart(df):
|
| 18 |
+
sentiment_counts = df['Sentiment'].value_counts()
|
| 19 |
+
#create a bar chart
|
| 20 |
+
fig, ax = plt.subplots()
|
| 21 |
+
sentiment_counts.plot(kind='pie', ax=ax, autopct='%1.1f%%', color=['green', 'red'])
|
| 22 |
+
ax.set_title('Sentiment Counts')
|
| 23 |
+
# ax.set_xlabel('Sentiment')
|
| 24 |
+
# ax.set_ylabel('Count')
|
| 25 |
+
return fig
|
| 26 |
+
|
| 27 |
def Read_Analyze(file_object):
|
| 28 |
df = pd.read_csv(file_object, encoding='latin1')
|
| 29 |
|
| 30 |
if 'Review' not in df.columns:
|
| 31 |
raise ValueError("Review column not found")
|
| 32 |
+
df['Sentiment'] = df['Review'].apply(sentiment_analyzer)
|
| 33 |
+
chart_object = sentiment_bar_chart(df)
|
| 34 |
+
return df, chart_object
|
| 35 |
|
| 36 |
# result = sentiment_analyzer("C:/Users/ankitdwivedi/OneDrive - Adobe/Desktop/NLP Projects/Video to Text Summarization/Files/all-data.csv")
|
| 37 |
# print (result)
|
|
|
|
| 40 |
|
| 41 |
demo = gr.Interface(fn=Read_Analyze,
|
| 42 |
inputs=[gr.File(file_types = ["csv"],
|
| 43 |
+
label="Upload your review file")],
|
| 44 |
+
outputs=[gr.Dataframe(label="Reviews"), gr.Plot(label="Sentiment Analysis")],
|
| 45 |
title="Project 3: Sentiment Analyzer",
|
| 46 |
description="""This is a Sentiment Analysis Model.""")
|
| 47 |
demo.launch()
|