kajalag commited on
Commit
10aa210
·
1 Parent(s): a8c6552

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -156
app.py DELETED
@@ -1,156 +0,0 @@
1
- import streamlit as st
2
- from transformers import pipeline
3
- from transformers import AutoTokenizer
4
- from transformers import AutoModelForSequenceClassification
5
- import nltk
6
- nltk.download('all')
7
- import matplotlib.pyplot as plt
8
- import helper
9
- import preprocessor
10
- import torch
11
- import seaborn as sns
12
- st.sidebar.title("Whatsapp Chat analyzer")
13
-
14
- uploaded_file= st.sidebar.file_uploader("Choose a file")
15
-
16
- if uploaded_file is not None:
17
-
18
- bytes_data = uploaded_file.getvalue()
19
- data=bytes_data.decode("utf-8")
20
- df_new= preprocessor.preprocess(data)
21
-
22
- user_list= df_new['users'].unique().tolist()
23
- user_list.sort()
24
- user_list.insert(0,"Group analysis")
25
- selected_user=st.sidebar.selectbox("show analysis wrt",user_list)
26
- if st.sidebar.button("Show Analysis"):
27
- num_messages,words,num_links=helper.fetch_stats(selected_user,df_new)
28
- st.title("Top Statistics")
29
- col1,col2,col3=st.columns(3)
30
-
31
- with col1:
32
- st.header("Total Messages")
33
- st.title(num_messages)
34
- with col2:
35
- st.header("Total Words")
36
- st.title(words)
37
- with col3:
38
- st.header("Links Shared")
39
- st.title(num_links)
40
-
41
- st.title("Timeline")
42
- col1, col2 = st.columns(2)
43
-
44
- with col1:
45
- st.header("Monthly ")
46
- timeline = helper.monthly_timeline(selected_user, df_new)
47
- fig, ax = plt.subplots()
48
- ax.plot(timeline['time'], timeline['message'])
49
- plt.xticks(rotation='vertical')
50
- st.pyplot(fig)
51
- with col2:
52
- st.title("Daily")
53
- daily_timeline = helper.Daily_timeline(selected_user, df_new)
54
- fig, ax = plt.subplots()
55
- ax.plot(daily_timeline['Date'], daily_timeline['message'], color='black')
56
- plt.xticks(rotation='vertical')
57
- st.pyplot(fig)
58
-
59
- st.title("Activity Map")
60
- col1,col2=st.columns(2)
61
-
62
- with col1:
63
- st.header("Most busy day")
64
- busy_day=helper.week_activity_map(selected_user, df_new)
65
- fig,ax=plt.subplots()
66
- ax.bar(busy_day.index,busy_day.values,color=('pink','green','orange','black','blue','yellow','red'))
67
- plt.xticks(rotation='vertical')
68
- st.pyplot(fig)
69
- with col2:
70
- st.header("Most busy Month")
71
- busy_day = helper.month_activity_map(selected_user, df_new)
72
- fig, ax = plt.subplots()
73
- ax.bar(busy_day.index, busy_day.values,color=('violet','indigo','blue','green'))
74
- plt.xticks(rotation='vertical')
75
- st.pyplot(fig)
76
-
77
- st.title("Weekly Activity Map")
78
- Activity_heatmap=helper.activity_heatmap(selected_user,df_new)
79
- fig,ax=plt.subplots()
80
- ax=sns.heatmap(Activity_heatmap,cmap='RdBu',linewidths=1,linecolor='black')
81
- st.pyplot(fig)
82
-
83
- if selected_user == "Group analysis":
84
- st.title("Most busy user")
85
- x,new_df=helper.most_busy_users(df_new)
86
- fig,ax=plt.subplots()
87
- col1,col2=st.columns(2)
88
-
89
- with col1:
90
- ax.bar(x.index, x.values,color=('blue','red','pink','orange','green'))
91
- plt.xticks(rotation='vertical')
92
- st.pyplot(fig)
93
- with col2:
94
- st.dataframe(new_df)
95
-
96
- st.title("Chat Sentiment Analysis")
97
- col1, col2, col3 = st.columns(3)
98
-
99
- with col1:
100
- st.header("Positive")
101
- pos_words = helper.pos_words(selected_user, df_new)
102
- st.dataframe(pos_words)
103
- with col2:
104
- st.header("Negative")
105
- neg_words = helper.neg_words(selected_user, df_new)
106
- st.dataframe(neg_words)
107
- with col3:
108
- st.header("Neutral")
109
- neu_words = helper.neu_words(selected_user, df_new)
110
- st.dataframe(neu_words)
111
-
112
-
113
- st.title("Word cloud")
114
- df_wc = helper.word_cloud(selected_user, df_new)
115
- fig, ax = plt.subplots()
116
- ax.imshow(df_wc)
117
- plt.axis('off')
118
- st.pyplot(fig)
119
-
120
- st.title("Most Common Words")
121
- most_common_df=helper.most_common_words(selected_user,df_new)
122
- fig,ax=plt.subplots()
123
- ax.barh(most_common_df[0],most_common_df[1],color=(0.1, 0.1, 0.1, 0.1), edgecolor='blue')
124
- plt.ylabel(None)
125
- sns.despine(left=True)
126
- ax.grid(False)
127
- ax.tick_params(bottom=True, left=False)
128
- st.pyplot(fig)
129
- st.dataframe(most_common_df.style.set_properties(**{"background-color": "black", "color": "lawngreen"}))
130
-
131
- emoji_df=helper.emoji_helper(selected_user,df_new)
132
- st.title("Emoji Analysis")
133
- st.dataframe(emoji_df.style.set_properties(**{"background-color": "black", "color": "lawngreen"}))
134
-
135
-
136
- st.title("Sentiment Analysis")
137
- @st.cache(allow_output_mutation=True)
138
- def get_model():
139
- MODEL = f"cardiffnlp/twitter-roberta-base-sentiment"
140
- tokenizer = AutoTokenizer.from_pretrained(MODEL)
141
- model = AutoModelForSequenceClassification.from_pretrained(MODEL)
142
- return tokenizer,model
143
-
144
-
145
- tokenizer, model = get_model()
146
-
147
- user_input = st.text_area('Enter Text to Analyze')
148
- button = st.button("Analyze")
149
-
150
- sent_pipeline = pipeline("sentiment-analysis")
151
- if user_input and button:
152
- test_sample = tokenizer([user_input], padding=True, truncation=True, max_length=512, return_tensors='pt')
153
- # test_sample
154
- output = model(**test_sample)
155
- st.write("Prediction: ", sent_pipeline(user_input))
156
- showWarningOnDirectExecution = False