Skip to content

Commit

Permalink
Complete
Browse files Browse the repository at this point in the history
  • Loading branch information
DhananjayPorwal committed Apr 1, 2024
0 parents commit 495027a
Show file tree
Hide file tree
Showing 13 changed files with 13,826 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[theme]

# Primary accent for interactive elements
primaryColor = '#128c7e'

# Background color for the main content area
backgroundColor = '#dcf8c6'

# Background color for sidebar and most interactive widgets
secondaryBackgroundColor = '#25d366'

# Color used for almost all text
textColor = '#00000'
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use the official Python image as a base image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the entire project directory into the container
COPY . .

# Expose the port where Streamlit will run
EXPOSE 8501

# Command to run the Streamlit app when the container starts
CMD ["streamlit", "run", "app.py"]
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
worker: python app.py
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# WhatsApp Chat Analyser 📈

## Objective 🎯

The objective of this project is to provide a tool for statistical and visual analysis of WhatsApp chat data. It allows users to gain insights into their chat history by analyzing various aspects such as message frequency, word usage, media sharing, links shared, and more.

## Installation ⚙️

To use the WhatsApp Chat Analyser, follow these steps:

1. Clone the repository to your local machine:
```bash
git clone https://github.com/DhananjayPorwal/whatsapp-chat-analyser.git
```
2. Navigate to the project directory:
```bash
cd whatsapp-chat-analyser
```
3. Install the required dependencies:
```bash
pip install -r requirements.txt
```
4. Run the Streamlit web app:
```bash
streamlit run app.py
```
5. Upload your WhatsApp chat export file and start analyzing!

## Docker Installation and Usage 🐳

Alternatively, you can run the WhatsApp Chat Analyser using Docker. Follow these steps:

1. Ensure Docker is installed on your machine.
2. Clone the repository to your local machine:

```bash
git clone https://github.com/DhananjayPorwal/whatsapp-chat-analyser.git
```

3. Navigate to the project directory:
```bash
cd whatsapp-chat-analyser
```
4. Build the Docker image:
```bash
docker build -t whatsapp-chat-analyser .
```
5. Run a container using the following command:
```bash
docker run -p 8501:8501 whatsapp-chat-analyser
```
6. Access the Streamlit web app from your browser at `http://localhost:8501`.

## WhatsApp Color Palette

<center><img src="https://i.imgur.com/m0w84VM.png" alt="alt-text" style="width:20%;">

| Hex | RGB |
| --------- | ------------- |
| `#075e54` | (7,94,84) |
| `#128c7e` | (18,140,126) |
| `#25d366` | (37,211,102) |
| `#dcf8c6` | (220,248,198) |
| `#ece5dd` | (236,229,221) |

</center>

## Learning 📚

This project demonstrates the use of Streamlit for creating interactive web applications in Python. It also involves data preprocessing, statistical analysis, and data visualization techniques using pandas, matplotlib, seaborn, and other libraries.

## Conclusion 🌟

The WhatsApp Chat Analyser provides valuable insights into chat behavior, helping users understand their communication patterns, most active periods, frequently used words and emojis, and more. It can be a useful tool for personal reflection, group analysis, or even research purposes.

## Possible Use Cases 🚀

- Personal reflection and self-analysis of communication habits.
- Team communication analysis for project management or team dynamics assessment.
- Academic research on linguistic patterns, social dynamics, or sentiment analysis.
- Business intelligence for customer support analysis or marketing insights.

## Contribution Guidelines 🤝

Contributions to the WhatsApp Chat Analyser are welcome! If you have ideas for new features, improvements, or bug fixes, please feel free to open an issue or submit a pull request.

## Issues ❗

If you encounter any issues or have suggestions for improvements, please open an issue on the GitHub repository. We appreciate your feedback and will work to address any concerns promptly.

## Reference 👥

- [Streamlit footer - 🎈 Using Streamlit - Streamlit](https://discuss.streamlit.io/t/streamlit-footer/12181)
- [st.set_page_config - Streamlit Docs](https://docs.streamlit.io/library/api-reference/utilities/st.set_page_config)
- [HTML Link Colors (w3schools.com)](https://www.w3schools.com/html/html_links_colors.asp)
- [How do i change the app title and favicon? - 🎈 Using Streamlit - Streamlit](https://discuss.streamlit.io/t/how-do-i-change-the-app-title-and-favicon/1654/4)
- [Be able to change the title and favicon of a Streamlit app · Issue #1006 · streamlit/streamlit (github.com)](https://github.com/streamlit/streamlit/issues/1006)
- [WhatsApp Color Palette (color-hex.com)](https://www.color-hex.com/color-palette/110833)
- [WhatsApp Colors - Hex, RGB, CMYK, Pantone | Color Codes - U.S. Brand Colors (usbrandcolors.com)](https://usbrandcolors.com/whatsapp-colors/)
- [Hindi and Hinglish stop-words · Issue #2087 · nltk/nltk (github.com)](https://github.com/nltk/nltk/issues/2087)
- [HinglishNLP/data/assets/stop_hinglish at master · TrigonaMinima/HinglishNLP (github.com)](https://github.com/TrigonaMinima/HinglishNLP/blob/master/data/assets/stop_hinglish)
- [python - Find there is an emoji in a string in python3 - Stack Overflow](https://stackoverflow.com/questions/36216665/find-there-is-an-emoji-in-a-string-in-python3)
- [emoji · PyPI](https://pypi.org/project/emoji/)
- [Emoji: Extract, Analyze, and Get Insights — Python (advertools.readthedocs.io)](https://advertools.readthedocs.io/en/master/advertools.emoji.html)
- [Support (first font of) TTC files. by anntzer · Pull Request #9787 · matplotlib/matplotlib (github.com)](https://github.com/matplotlib/matplotlib/pull/9787)
Binary file added __pycache__/helper.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/preprocessing.cpython-310.pyc
Binary file not shown.
202 changes: 202 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import streamlit as st
import preprocessing as pp
import helper as hl
import matplotlib.pyplot as plt
import seaborn as sns

# Streamlit Page Configuration

st.set_page_config(
page_title="WhatsApp Chat Analyser",
page_icon="📈",
initial_sidebar_state="expanded",
menu_items={
'Get Help': 'mailto:[email protected]',
'Report a bug': "https://www.github.com/DhananjayPorwal/whatsapp-chat-analyser/issues",
'About': "### Created by [Dhananjay Porwal](https://www.linkedin.com/in/dhananjayporwal/)"
}
)

# Main Page
st.sidebar.title("WhatsApp Chat Analyser")

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 = pp.preprocess(data)
original_df = df

user_list = df['user'].unique().tolist()
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"):
st.title("Top Statistics")

# Stats
num_messages, words, num_media, num_links = hl.fetch_stats(selected_user, df)

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)
with col4:
st.header("Links Shared")
st.title(num_links)

# Timeline
st.title("Timeline")
timeline = hl.time_activity(selected_user, df)
fig, ax = plt.subplots()
ax = sns.heatmap(timeline, cmap='Greens')
st.pyplot(fig)

# Daily Timeline
st.title("Daily Timeline")
daily_timeline = hl.daily_timeline(selected_user, df)
fig, ax = plt.subplots()
plt.plot(daily_timeline['only_date'], daily_timeline['message'], color = '#25D366')
ax.set_facecolor('#dcf8c6')
plt.xticks(rotation='vertical')
st.pyplot(fig)

# Monthly Timeline
st.title("Monthly Timeline")
monthly_timeline_df = hl.monthly_timeline(selected_user, df)
fig, ax = plt.subplots()
plt.plot(monthly_timeline_df['time'], monthly_timeline_df['message'], color = '#25D366')
ax.set_facecolor('#dcf8c6')
plt.xticks(rotation='vertical')
st.pyplot(fig)

# Activity Map
st.title("Activity Map")

col1,col2 = st.columns(2)

with col1:
st.header("Most Active Day")
active_day = hl.week_activity(selected_user, df)
fig,ax = plt.subplots()
ax.bar(active_day.index, active_day.values, color = '#25D366')
ax.set_facecolor('#dcf8c6')
plt.xticks(rotation='vertical')
st.pyplot(fig)

with col2:
st.header("Most Month Day")
active_month = hl.month_activity(selected_user, df)
fig,ax = plt.subplots()
ax.bar(active_month.index, active_month.values, color = '#25D366')
ax.set_facecolor('#dcf8c6')
plt.xticks(rotation='vertical')
st.pyplot(fig)

# Most Active Users
if selected_user == 'Overall':
st.title('Most Active User')
active_user, new_df = hl.most_active_user(df)

col1, col2 = st.columns(2)

fig, ax = plt.subplots()

with col1:
ax.bar(active_user.index, active_user.values, color = '#25D366')
ax.set_facecolor('#dcf8c6')
plt.xticks(rotation= 'vertical')
st.pyplot(fig)
with col2:
st.dataframe(new_df)


# Word Cloud
st.title("Word Cloud")
df_wc = hl.create_wordcloud(selected_user, df)
fig, ax = plt.subplots()
plt.imshow(df_wc)
st.pyplot(fig)



# Most Common Words
st.title("Most Common Words")

col1, col2 = st.columns(2)

most_common_words_df = hl.most_common_words(selected_user, df)

with col1:
fig, ax = plt.subplots()
ax.barh(most_common_words_df[0], most_common_words_df[1], color = '#25D366')
ax.set_facecolor('#dcf8c6')
plt.xticks(rotation= 'vertical')
st.pyplot(fig)


with col2:
st.dataframe(most_common_words_df)

# Emoji Analysis

st.title("Most Used Emojis")

col1, col2 = st.columns(2)

with col1:
emoji_df = hl.most_common_emoji(selected_user, df)
st.dataframe(emoji_df)

with col2:
fig, ax = plt.subplots()
ax.pie(emoji_df['Count'].head(), labels = emoji_df['Emoji'].head(), autopct="%0.2f")
# ax.set_facecolor('#dcf8c6')

st.pyplot(fig)


# Original Data Frame

st.header("Your WhatsApp Chat")
st.dataframe(original_df)


# Footer Section

footer="""<style>
a:link , a:visited{
color: #075e54;
background-color: transparent;
text-decoration: underline;
}
a:hover, a:active {
color: red;
background-color: transparent;
text-decoration: underline;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: #dcf8c6;
color: #128c7e;
text-align: center;
}
</style>
<div class="footer">
<p>Developed with 💖 by <a href="https://www.linkedin.com/in/dhananjayporwal/">Dhananjay Porwal</a></p>
</div>
"""
st.markdown(footer,unsafe_allow_html=True)
Loading

0 comments on commit 495027a

Please sign in to comment.