Spaces:
Sleeping
Sleeping
File size: 3,036 Bytes
89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b 137c7fb 89bed1b |
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 |
import streamlit as st
import helper
import matplotlib.pyplot as plt
st.sidebar.title('Whatsapp Chat Analyzer')
st.sidebar.write('Upload your whatsapp chat file to analyze the chat')
st.sidebar.write('The chat file should be a .txt file exported from whatsapp')
uploaded_file = st.sidebar.file_uploader('Choose a file')
if uploaded_file is not None:
chat_data = uploaded_file.getvalue().decode('utf-8')
df = helper.preprocess_data(chat_data)
# st.write(df)
#unique users dropdown menu to select user
unique_users = df['user'].unique()
unique_users = list(unique_users)
unique_users.sort()
unique_users.insert(0, 'All')
selected_user = st.sidebar.selectbox('Select a user', unique_users)
st.sidebar.write(selected_user)
#fetch stats
user_df, total_messages, media_messages, links, emojis, total_words = helper.fetch_stats(selected_user, df)
st.title(f'User: {selected_user}')
# st.write(user_df)
#display below data side by side
col1, col2, col3 = st.columns(3)
with col1:
st.write('Total messages:', total_messages)
st.write('Media messages:', media_messages)
with col2:
st.write('Links shared:', links)
st.write('Emojis shared:', emojis)
with col3:
st.write('Total words:', total_words)
#busiest users (users with most messages)
with st.expander('Busiest users'):
if selected_user == 'All':
busiest_users, plot = helper.busiest_users(df)
st.write('Busiest users:')
st.write(busiest_users)
st.pyplot(plot)
with st.expander('View word cloud and most common words'):
st.pyplot(helper.word_cloud(df, selected_user))
st.write('Most common words')
temp_df, plot = helper.most_common_words(selected_user, df)
st.write(temp_df)
st.pyplot(plot)
st.write("Most common emojis")
temp_df = helper.most_common_emojis(selected_user, df)
st.write(temp_df)
with st.expander("Activity over time"):
col1, col2 = st.columns(2)
with col1: #left
_, plot = helper.daily_timeline(selected_user, df)
st.pyplot(plot)
_, plot = helper.weekday_activity_map(selected_user, df)
st.pyplot(plot)
with col2: #right
_, plot = helper.monthly_timeline(selected_user, df)
st.pyplot(plot)
_, plot = helper.month_activity_map(selected_user, df)
st.pyplot(plot)
st.write("Messages sent by hour")
_, plot = helper.hour_activity_map(selected_user, df)
st.pyplot(plot)
st.write("weekly heatmap")
plot = helper.activity_heatmap(selected_user, df)
st.pyplot(plot)
with st.expander("Links shared"):
temp_df = helper.extract_links(df)
st.write(temp_df)
common_domains, plot = helper.plot_common_domains(df)
st.pyplot(plot)
st.write("Most common domains")
st.write(common_domains)
|