Haseeb005 commited on
Commit
f723d9f
·
verified ·
1 Parent(s): 26bb2f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -20
app.py CHANGED
@@ -1,10 +1,7 @@
1
- pip install pandas matplotlib seaborn
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
4
  import seaborn as sns
5
-
6
- # Load the CSV file
7
- df = pd.read_csv('Daraz-Reviews.csv')
8
 
9
  # Function to classify reviews
10
  def classify_review(review):
@@ -15,23 +12,31 @@ def classify_review(review):
15
  else:
16
  return "neutral"
17
 
18
- # Apply the classification
19
- df['Sentiment'] = df['Reviews'].apply(classify_review)
 
 
 
 
 
 
 
 
20
 
21
- # Count the number of positive and negative comments
22
- sentiment_counts = df['Sentiment'].value_counts()
 
 
 
 
 
 
23
 
24
- # Create a bar chart
25
- plt.figure(figsize=(8, 5))
26
- sns.barplot(x=sentiment_counts.index, y=sentiment_counts.values, palette='viridis')
27
- plt.title('Sentiment Analysis of Daraz Reviews')
28
- plt.xlabel('Sentiment')
29
- plt.ylabel('Number of Comments')
30
- plt.xticks(rotation=45)
31
- plt.tight_layout()
32
 
33
- # Save the bar chart
34
- plt.savefig('sentiment_analysis_bar_chart.png')
35
 
36
- # Show the bar chart
37
- plt.show()
 
 
 
1
  import pandas as pd
2
  import matplotlib.pyplot as plt
3
  import seaborn as sns
4
+ import gradio as gr
 
 
5
 
6
  # Function to classify reviews
7
  def classify_review(review):
 
12
  else:
13
  return "neutral"
14
 
15
+ # Function to plot sentiment chart
16
+ def plot_sentiment_chart():
17
+ # Load the CSV file
18
+ df = pd.read_csv('Daraz-Reviews.csv')
19
+
20
+ # Apply the classification
21
+ df['Sentiment'] = df['Reviews'].apply(classify_review)
22
+
23
+ # Count the number of positive and negative comments
24
+ sentiment_counts = df['Sentiment'].value_counts()
25
 
26
+ # Create a bar chart
27
+ plt.figure(figsize=(8, 5))
28
+ sns.barplot(x=sentiment_counts.index, y=sentiment_counts.values, palette='viridis')
29
+ plt.title('Sentiment Analysis of Daraz Reviews')
30
+ plt.xlabel('Sentiment')
31
+ plt.ylabel('Number of Comments')
32
+ plt.xticks(rotation=45)
33
+ plt.tight_layout()
34
 
35
+ # Save the bar chart
36
+ plt.savefig('sentiment_analysis_bar_chart.png')
 
 
 
 
 
 
37
 
38
+ return 'sentiment_analysis_bar_chart.png'
 
39
 
40
+ # Gradio interface
41
+ iface = gr.Interface(fn=plot_sentiment_chart, inputs=[], outputs="image")
42
+ iface.launch()