vibha-mah commited on
Commit
c1ba88a
·
1 Parent(s): a3a96ae

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import matplotlib.pyplot as plt
3
+ from wordcloud import WordCloud
4
+ import seaborn as sns
5
+ import gradio as gr
6
+
7
+ def generate_wordcloud(text, title):
8
+ wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text)
9
+ plt.figure(figsize=(10, 5))
10
+ plt.imshow(wordcloud, interpolation='bilinear')
11
+ plt.axis('off')
12
+ plt.title(title)
13
+ plt.show()
14
+
15
+ def generate_bar_plot(data, x, y, title):
16
+ plt.figure(figsize=(10, 5))
17
+ sns.barplot(x=x, y=y, data=data)
18
+ plt.title(title)
19
+ plt.show()
20
+
21
+ def generate_line_plot(data, x, y, title):
22
+ plt.figure(figsize=(10, 5))
23
+ sns.lineplot(x=x, y=y, data=data)
24
+ plt.title(title)
25
+ plt.show()
26
+
27
+ def sentiment_analysis(csv_file):
28
+ # Load CSV file
29
+ df = pd.read_csv(csv_file)
30
+
31
+ # Assuming you have a 'Sentiment' column in your CSV indicating positive or negative sentiment
32
+
33
+ # Positive Sentiment
34
+ positive_df = df[df['Sentiment'] == 'positive']
35
+ positive_text = ' '.join(positive_df['Content'])
36
+ generate_wordcloud(positive_text, 'Positive Sentiment Word Cloud')
37
+ generate_bar_plot(positive_df, 'Label', 'Count', 'Positive Sentiment Distribution')
38
+ generate_line_plot(positive_df, 'Created At', 'SentimentScore', 'Positive Sentiment over Time')
39
+
40
+ # Negative Sentiment
41
+ negative_df = df[df['Sentiment'] == 'negative']
42
+ negative_text = ' '.join(negative_df['Content'])
43
+ generate_wordcloud(negative_text, 'Negative Sentiment Word Cloud')
44
+ generate_bar_plot(negative_df, 'Label', 'Count', 'Negative Sentiment Distribution')
45
+ generate_line_plot(negative_df, 'Created At', 'SentimentScore', 'Negative Sentiment over Time')
46
+
47
+ # Gradio Interface
48
+ csv_file_input = gr.inputs.File(label="Select CSV file")
49
+ interface = gr.Interface(fn=sentiment_analysis, inputs=csv_file_input, outputs=None, title="Sentiment Analysis", description="Generates word clouds, bar plots, and line plots based on sentiment of text data from CSV files")
50
+ interface.launch()