Harsh032/whatsapp_chat_analyzer
0
1import matplotlib.pyplot as plt2import streamlit as st3import preprocessor,helper4 5 6st.set_page_config(layout='wide',page_title='Whatsapp chat analyzer',initial_sidebar_state="auto")7 8 9st.sidebar.title("Whats App Chat Analyzer")10 11 12uploaded_file = st.sidebar.file_uploader("Choose a file")13if uploaded_file is not None:14 # To read file as bytes:15 bytes_data = uploaded_file.getvalue()16 data = bytes_data.decode('utf-8')17 df = preprocessor.preprocess(data)18 19 st.dataframe(df)20 21 user_list = df["sender"].unique().tolist()22 user_list.sort()23 user_list.insert(0 ,"Overall")24 25 selected_user = st.sidebar.selectbox("Show Analysis wrt",user_list)26 27 if st.sidebar.button("Show Analysis"):28 29 num_messages,words,num_media_messages,nums_links = helper.fecth_stats(selected_user,df)30 31 col1, col2 ,col3 ,col4 =st.columns(4)32 33 #Number of messsages34 with col1:35 st.header("Total messages")36 st.title(num_messages)37 38 # Total number of words sended by user39 with col2:40 st.header("Total words")41 st.title(words)42 43 # Number of media sended by user like photos and videos etc.44 with col3:45 st.header("Total Media")46 st.title(num_media_messages)47 48 # number of links and ulrs49 with col4:50 st.header("Number of Links")51 st.title(nums_links)52 53 if selected_user == "Overall":54 st.title("Most Busiest User")55 56 x , new_df = helper.most_busy_user(df)57 fig, ax = plt.subplots()58 59 col1, col2 = st.columns(2)60 with col1:61 ax.bar(x.index,x.values)62 st.pyplot(fig)63 64 with col2:65 st.dataframe(new_df)66 67 st.title("Word Cloud")68 df_wc = helper.create_word_cloud(selected_user,df)69 fig , ax = plt.subplots()70 ax.imshow(df_wc)71 st.pyplot(fig)72 73 74 75 76 77 