import streamlit as st import matplotlib.pyplot as plt import plotly.express as px import preprocessor import helper color_2 = 'rgb(237, 59, 59)' f = open('number_of_files_upload.txt', 'r+') num_file_upload = int(f.read()) st.set_page_config(page_title="Whatsapp Chat Data Analysis App", initial_sidebar_state='expanded', page_icon="๐Ÿ“Š", menu_items={ 'Get Help': 'https://www.linkedin.com/in/imdebamritapaul/', 'Report a bug': "mailto:imdebamrita@1gmail.com", 'About': "Introducing the WhatsApp Chat Analysis App! Analyze your chat history, uncover trends, and gain insights into your messaging habits. < ___Made by : Debamrita Paul___ > Connect in LinkedIn: https://www.linkedin.com/in/imdebamritapaul/ssssss ๐Ÿ“ฒ๐Ÿš€ #WhatsAppChatAnalysis #DataInsights" }) st.sidebar.title("Whatsapp Chat Analyzer") uploaded_file = st.sidebar.file_uploader("Choose a file", type=['txt']) if uploaded_file is not None: bytes_data = uploaded_file.getvalue() data = bytes_data.decode("utf-8") check = preprocessor.checker(data) if check: num_file_upload += 1 f.seek(0) f.write(str(num_file_upload)) df = preprocessor.preprocess(data) # Get unique users user_list = df['user'].unique().tolist() if 'group_notification' in user_list: user_list.remove('group_notification') user_list.sort() user_list.insert(0, 'Overall') selected_user = st.sidebar.selectbox("Show analysis wrt", user_list) if st.sidebar.button("Show Analysis"): # States Area num_messages, words, num_media_messages, num_links = helper.fetch_states( selected_user, df) st.title("Top Statistics") col1, col2, col3, col4 = st.columns(4) with col1: st.header("Total Messages") st.title(num_messages) with col2: st.header("Total Words") st.title(words) with col3: st.header("Media Shared") st.title(num_media_messages) with col4: st.header("Links Shared") st.title(num_links) # Timeline Data st.title("Timeline") col1, col2 = st.columns(2) # Monthly Timeline with col1: monthly_timeline = helper.monthly_timeline(selected_user, df) fig = px.line(monthly_timeline, x='Timeline', y='Message', title='Monthly Timeline') st.plotly_chart(fig, use_container_width=True) # Daily Timeline with col2: daily_timeline = helper.daily_timeline(selected_user, df) fig = px.line(daily_timeline, x='Date', y='Message', title='Daily Timeline') fig.update_traces(line_color=color_2) st.plotly_chart(fig, use_container_width=True) # Activity Map st.title("Activity Map") col1, col2 = st.columns(2) # Weekly Activity with col1: week_activity = helper.week_activity_map(selected_user, df) fig = px.bar(week_activity, x='Day', y='Message', title='Weekly Activity') fig.update_traces(marker_color=color_2) st.plotly_chart(fig, use_container_width=True) # Monthly Activity with col2: month_activity = helper.month_activity_map(selected_user, df) fig = px.bar(month_activity, x='Month', y='Message', title='Monthly Activity') st.plotly_chart(fig, use_container_width=True) # Heat Map user_heatmap = helper.activity_heatmap(selected_user, df) fig = px.imshow(user_heatmap, title='Activity Heatmap') st.plotly_chart(fig) # Finding the most active user in the Group if selected_user == 'Overall': st.title("Most Active Users") x, per = helper.most_active_user(df) col1, col2 = st.columns(2) with col1: fig = px.bar(x, x='User', y='Count') fig.update_traces(marker_color=color_2) st.plotly_chart(fig, use_container_width=True) # st.bar_chart(x) with col2: st.dataframe(per) # WordCloud st.title("Word Cloud") df_wc = helper.create_wordcloud(selected_user, df) fig, ax = plt.subplots() ax.imshow(df_wc) ax.set_axis_off() st.pyplot(fig) # Most common words most_common_df = helper.most_common_words(selected_user, df) st.title("Most Common Words") fig = px.bar(most_common_df, x='Count', y='Message', orientation='h') st.write(fig) # Emoji Analysis emoji_df = helper.emoji_data(selected_user, df) st.title("Emoji Analysis") col1, col2 = st.columns(2) if emoji_df.empty: with col1: st.dataframe(emoji_df) else: with col1: st.dataframe(emoji_df) with col2: fig = px.pie(emoji_df.head(10), values='Count', names='Emoji', title='Top 10 Emojis') st.plotly_chart(fig, use_container_width=True) # Data Time Freame st.title("Data Timeframe") timeframe = helper.data_timeframe(df) st.write(timeframe) else: st.write("In sidebar click on ___Show Analysis___ button...") else: st.write("Uploaded file doesn't match with the default format") st.write("!!! Upload the correct file.") else: st.text("Go to Sidebar and Upload the file") st.text("How to export Whatsapp chat:") st.write("- Open the indivitual or group chat.") st.write("- At the top-right Info (โ‹ฎ) -> More -> Export chat (Without Media).") st.write("- Save that .txt file and upload it.") st.sidebar.text("Made by Debamrita Paul") st.sidebar.write("[Connect โคด](https://www.linkedin.com/in/imdebamritapaul/)") st.sidebar.text("Number of Analysis Done: " + str(num_file_upload)) hide_default_format = """ """ st.markdown(hide_default_format, unsafe_allow_html=True) custom_footer_style = """ """ def custom_footer(): st.markdown('', unsafe_allow_html=True) st.markdown(custom_footer_style, unsafe_allow_html=True) custom_footer()