File size: 7,103 Bytes
dfe57e4 7db0cc0 ff6c428 dfe57e4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | import streamlit as st
import matplotlib.pyplot as plt
import numpy as np
import preprocessor
import helper
st.sidebar.title("Whatsapp Chat Analyzer")
uploaded_file = st.sidebar.file_uploader("Choose a file")
if uploaded_file is not None:
bytes_data = uploaded_file.getvalue()
data = bytes_data.decode("utf-8")
df = preprocessor.preprocess(data)
# Show Analysis wrt
user_list = df['user'].unique().tolist()
user_list.sort()
user_list.insert(0, "Overall")
selected_users = st.sidebar.selectbox("Show Analysis wrt", user_list)
if st.sidebar.button("Show Analysis"):
#stats Area
num_messages, words, num_media_messages, num_links = helper.fetch_stats(selected_users, df)
st.markdown(f'<h1 style="color: red; text-align: center; font-size: 70px;text-decoration: underline;">TOP STATISTICS</h1>', unsafe_allow_html=True)
col1, col2, col3 = st.columns(3)
with col1:
st.markdown(f'<h1 style="color: skyblue; font-size: 40px;">Total Messages</h1>', unsafe_allow_html=True)
st.markdown(f'<h1 style="color: purple; font-size: 38px;">{num_messages}</h1>', unsafe_allow_html=True)
with col2:
st.markdown(f'<h1 style="color: skyblue; font-size: 40px;">Total Words</h1>', unsafe_allow_html=True)
st.markdown(f'<h1 style="color: purple; font-size: 38px;">{words}</h1>', unsafe_allow_html=True)
with col3:
st.markdown(f'<h1 style="color: skyblue; font-size: 40px;">Total links Shared</h1>', unsafe_allow_html=True)
st.markdown(f'<h1 style="color: purple; font-size: 38px;">{num_links}</h1>', unsafe_allow_html=True)
col1, col2 = st.columns(2)
with col1:
st.markdown(f'<h1 style="color: skyblue; font-size: 35px;">Total Media Shared</h1>', unsafe_allow_html=True)
st.markdown(f'<h1 style="color: purple; font-size: 38px;">{num_media_messages}</h1>', unsafe_allow_html=True)
with col2:
avg_messages_per_day = helper.avg_messages_per_day(selected_users,df)
st.markdown(f'<h1 style="color: skyblue; font-size: 35px;">Avg No of Messages Per day</h1>', unsafe_allow_html=True)
st.markdown(f'<h1 style="color: purple; font-size: 38px;">{avg_messages_per_day}</h1>', unsafe_allow_html=True)
if selected_users == 'Overall':
col1, col2, col3 = st.columns(3)
with col1:
first_last_msg = helper.first_last_msg(df)
st.markdown(f'<h1 style="color: skyblue; font-size: 35px;">First Message Sent</h1>', unsafe_allow_html=True)
st.dataframe(first_last_msg.head(1))
with col2:
first_last_msg = helper.first_last_msg(df)
st.markdown(f'<h1 style="color: skyblue; font-size: 35px;">Last Message Sent</h1>', unsafe_allow_html=True)
st.dataframe(first_last_msg.tail(1))
with col3:
connected_days = helper.connected_days(df)
st.markdown(f'<h1 style="color: skyblue; font-size: 35px;">Total Connected Days</h1>', unsafe_allow_html=True)
st.markdown(f'<h1 style="color: purple; font-size: 38px;">{connected_days}</h1>', unsafe_allow_html=True)
with col1:
max_active_day = helper.max_active_day(df)
st.markdown(f'<h1 style="color: skyblue; font-size: 35px;">Most Active Day</h1>', unsafe_allow_html=True)
st.dataframe(max_active_day.head(1))
with col2:
max_active_month = helper.max_active_month(selected_users,df)
st.markdown(f'<h1 style="color: skyblue; font-size: 35px;">Most Active Month</h1>', unsafe_allow_html=True)
st.dataframe(max_active_month.head(1))
# month wise
st.markdown(f'<h1 style="color: red; text-align: center; font-size: 50px;text-decoration: underline;">MONTH WISE</h1>', unsafe_allow_html=True)
col1, col2 = st.columns(2)
with col1:
st.markdown(f'<h1 style="color: skyblue; text-align: center; font-size: 40px;">GRAPH</h1>', unsafe_allow_html=True)
timeline = helper.monthly_timeline(selected_users, df)
fig, ax = plt.subplots()
ax.plot(timeline['time'], timeline['message'], color='green')
plt.xticks(rotation='vertical')
st.pyplot(fig)
with col2:
timeline = helper.monthly_timeline_msg(selected_users, df)
st.markdown(f'<h1 style="color: skyblue; font-size: 40px;">Message Counts</h1>', unsafe_allow_html=True)
st.dataframe(timeline)
# finding the busiest people in the group(Group Level)
if selected_users == 'Overall':
st.markdown(f'<h1 style="color: red; text-align: center; font-size: 50px;text-decoration: underline;">MOST BUSY USERS</h1>', unsafe_allow_html=True)
x, new_df = helper.most_busy_users(df)
fig, ax = plt.subplots()
col1, col2 = st.columns(2)
with col1:
st.markdown(f'<h1 style="color: skyblue; text-align: center; font-size: 40px;">GRAPH</h1>', unsafe_allow_html=True)
num_bars = len(x)
colors = plt.cm.rainbow(np.linspace(0, 1, num_bars))
ax.bar(x.index, x.values, color=colors,alpha=0.5)
plt.xticks(rotation='vertical')
st.pyplot(fig)
with col2:
st.markdown(f'<h1 style="color: skyblue; font-size: 35px;">CONTRIBUTIONS</h1>', unsafe_allow_html=True)
st.dataframe(new_df)
# WordCloud
st.markdown(f'<h1 style="color: red; text-align: center; font-size: 50px;text-decoration: underline;">WORD WISE ANALYSIS</h1>', unsafe_allow_html=True)
st.markdown(f'<h1 style="color: skyblue;text-align: center; font-size: 40px;">WordCloud</h1>', unsafe_allow_html=True)
df_wc = helper.create_wordcloud(selected_users, df)
fig, ax = plt.subplots()
ax.imshow(df_wc)
st.pyplot(fig)
# # Emoji analysis
# st.markdown(f'<h1 style="color: red; text-align: center; font-size: 50px;text-decoration: underline;">EMOJI ANALYSIS</h1>', unsafe_allow_html=True)
# col1,col2 = st.columns(2)
# with col1:
# st.markdown(f'<h1 style="color: skyblue; font-size: 40px;">Top 5 Emojis Used</h1>', unsafe_allow_html=True)
# emoji_df = helper.emoji_helper(selected_users, df)
# st.dataframe(emoji_df.head(5))
# with col2:
# st.markdown(f'<h1 style="color: skyblue; font-size: 40px;">Pie Chart</h1>', unsafe_allow_html=True)
# fig, ax = plt.subplots()
# ax.pie(emoji_df['Count '], labels=emoji_df['Emoji '], autopct='%1.2f%%', startangle=90)
# ax.axis('equal')
# st.pyplot(fig)
st.markdown(f'<h1 style="color: red; text-align: center; font-size: 40px;text-decoration: underline;">More features will be added soon</h1>', unsafe_allow_html=True)
|