Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files
app.py
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import eda
|
| 3 |
+
import prediction
|
| 4 |
+
import home
|
| 5 |
+
|
| 6 |
+
PAGES = {
|
| 7 |
+
"Home": home,
|
| 8 |
+
"Exploratory Data Analysis": eda,
|
| 9 |
+
"Prediction": prediction
|
| 10 |
+
}
|
| 11 |
+
st.sidebar.title('Navigation')
|
| 12 |
+
|
| 13 |
+
selection = st.sidebar.selectbox("Go to", list(PAGES.keys()))
|
| 14 |
+
page = PAGES[selection]
|
| 15 |
+
page.app()
|
eda.py
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
import nltk
|
| 6 |
+
nltk.download('stopwords')
|
| 7 |
+
from nltk.corpus import stopwords
|
| 8 |
+
from wordcloud import WordCloud
|
| 9 |
+
|
| 10 |
+
def app():
|
| 11 |
+
df_original = pd.read_csv("data.csv", delimiter=";")
|
| 12 |
+
df = df_original.copy()
|
| 13 |
+
df.drop_duplicates(inplace=True)
|
| 14 |
+
|
| 15 |
+
temp_a = df.copy()
|
| 16 |
+
temp_a['text_length'] = temp_a['text'].apply(len)
|
| 17 |
+
st.header('Exploratory Data Analysis', divider='rainbow')
|
| 18 |
+
eda_list = ["Text Length Distribution", "Sentiment Distribution", "Word Clouds", "Boxplot Distributions"]
|
| 19 |
+
val = st.sidebar.radio("Choose plot to show", eda_list)
|
| 20 |
+
stop_words = set(stopwords.words('english'))
|
| 21 |
+
def plot_wordcloud(sentiment):
|
| 22 |
+
text = ' '.join(df[df['feeling'] == sentiment]['text'])
|
| 23 |
+
wordcloud = WordCloud(stopwords=stop_words, background_color='white').generate(text)
|
| 24 |
+
plt.figure(figsize=(10, 6))
|
| 25 |
+
plt.imshow(wordcloud, interpolation='bilinear')
|
| 26 |
+
plt.axis('off')
|
| 27 |
+
plt.title(f"Word Cloud for {sentiment} Sentiment")
|
| 28 |
+
st.pyplot(plt)
|
| 29 |
+
if val == "Text Length Distribution":
|
| 30 |
+
# Plot distribution
|
| 31 |
+
st.header('Text Length Distribution')
|
| 32 |
+
plt.figure(figsize=(10, 6))
|
| 33 |
+
plt.hist(temp_a['text_length'], bins=30, color='skyblue')
|
| 34 |
+
plt.title('Text Length Distribution')
|
| 35 |
+
plt.xlabel('Text Length (characters)')
|
| 36 |
+
plt.ylabel('Frequency')
|
| 37 |
+
st.pyplot(plt)
|
| 38 |
+
st.write("Insight: the numerical values in our data are all normal distributions.")
|
| 39 |
+
elif val == "Sentiment Distribution":
|
| 40 |
+
sentiment_counts = df['feeling'].value_counts()
|
| 41 |
+
st.header('Sentiment Distribution')
|
| 42 |
+
# Plot pie chart
|
| 43 |
+
plt.figure(figsize=(8, 6))
|
| 44 |
+
plt.pie(sentiment_counts, labels=sentiment_counts.index, autopct='%1.1f%%', startangle=140, colors=sns.color_palette('viridis', len(sentiment_counts)))
|
| 45 |
+
plt.title('Sentiment Distribution')
|
| 46 |
+
plt.axis('equal')
|
| 47 |
+
st.pyplot(plt)
|
| 48 |
+
st.write("Insight: joy and sadness dominate the sentiment dataset, with joy taking the first place in 33.8%")
|
| 49 |
+
|
| 50 |
+
plt.figure(figsize=(8, 6))
|
| 51 |
+
sns.countplot(data=df, x='feeling', palette='viridis')
|
| 52 |
+
plt.title('Sentiment Distribution')
|
| 53 |
+
plt.xlabel('Sentiment')
|
| 54 |
+
plt.ylabel('Count')
|
| 55 |
+
st.pyplot(plt)
|
| 56 |
+
st.write("Insight: surprise sentiment has the lowest value of around 900 data")
|
| 57 |
+
elif val == "Word Clouds":
|
| 58 |
+
plot_wordcloud('joy')
|
| 59 |
+
plot_wordcloud('sadness')
|
| 60 |
+
plot_wordcloud('anger')
|
| 61 |
+
plot_wordcloud('love')
|
| 62 |
+
plot_wordcloud('surprise')
|
| 63 |
+
plot_wordcloud('fear')
|
home.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
def app():
|
| 4 |
+
st.header('Sentiment Analysis Project', divider='rainbow')
|
| 5 |
+
st.write("""
|
| 6 |
+
This deep learning project is designed to predict the feeling of a user's text. This can be helpful for
|
| 7 |
+
companies, C-level executives and social media influencers to really understand what their users actually feel about
|
| 8 |
+
their products, posts, services, etc.
|
| 9 |
+
|
| 10 |
+
In addition, research shows that 70% of customer purchase decisions are based on emotional
|
| 11 |
+
factors and only 30% on rational factors. By analyzing likes, comments, shares and mentions, brands can gain valuable insights into
|
| 12 |
+
the emotional drivers that influence purchase decisions as well as brand loyalty.
|
| 13 |
+
|
| 14 |
+
This means, that this technology can help companies and businesses make better and more strategical decisions.
|
| 15 |
+
""")
|
requirements.txt
CHANGED
|
@@ -2,3 +2,5 @@ pandas==2.2.2
|
|
| 2 |
numpy==1.26.4
|
| 3 |
tensorflow==2.15.1
|
| 4 |
tensorflow_hub==0.16.1
|
|
|
|
|
|
|
|
|
| 2 |
numpy==1.26.4
|
| 3 |
tensorflow==2.15.1
|
| 4 |
tensorflow_hub==0.16.1
|
| 5 |
+
nltk==3.8.1
|
| 6 |
+
WordCloud
|