mnurbani commited on
Commit
02794f7
·
verified ·
1 Parent(s): 5b368ac

Upload 12 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model_gru_2/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import eda
3
+ import prediction
4
+
5
+ page = st.sidebar.selectbox('Pilih Halaman : ', ('Dashboard', 'Prediction'))
6
+
7
+ if page == 'Dashboard' :
8
+ eda.run()
9
+ else:
10
+ prediction.run()
eda.py ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ import plotly.express as px
6
+ from PIL import Image
7
+
8
+ def run():
9
+ #Membuat title
10
+ st.title('Text-Based Twitter Sentiment Analysis')
11
+
12
+ #Tambahkan gambar
13
+ image = Image.open('twittersentiment.jpg')
14
+ st.image(image, caption = 'Twitter Sentiment')
15
+
16
+ #Membuat garis
17
+ st.markdown('----')
18
+
19
+ #Masukkan pandas dataframe
20
+
21
+ #Show dataframe
22
+ df = pd.read_csv('tweets-update.csv')
23
+ st.dataframe(df)
24
+ st.write('Source : https://www.kaggle.com/datasets/yasserh/twitter-tweets-sentiment-dataset')
25
+
26
+ st.markdown('----')
27
+ st.title('Exploratory Data Analysis')
28
+ #Bar Plot
29
+ st.write('#### Distribution of Sentiments')
30
+ fig_sentiments = plt.figure(figsize=(10, 6))
31
+ sns.countplot(x='sentiment', data=df)
32
+ plt.xlabel('Sentiment Label')
33
+ plt.ylabel('Count')
34
+ plt.title('Distribution of Sentiments')
35
+ st.pyplot(fig_sentiments)
36
+
37
+ # Positive Sentiment Tweets Bar
38
+ st.write('#### Distribution of Text Length for Positive Sentiment Tweets')
39
+ fig_length_positive = plt.figure(figsize=(14, 7))
40
+
41
+ # Handle NaN values in 'text_processed'
42
+ df['length'] = df['text_processed'].apply(lambda x: len(str(x).split()) if pd.notna(x) else 0)
43
+
44
+ ax1 = fig_length_positive.add_subplot(122)
45
+ sns.histplot(df[df['sentiment']=='positive']['length'], ax=ax1, color='green')
46
+ describe_positive = df.length[df.sentiment=='positive'].describe().to_frame().round(2)
47
+
48
+ ax2 = fig_length_positive.add_subplot(121)
49
+ ax2.axis('off')
50
+ font_size = 14
51
+ bbox = [0, 0, 1, 1]
52
+ table_positive = ax2.table(cellText=describe_positive.values, rowLabels=describe_positive.index, bbox=bbox, colLabels=describe_positive.columns)
53
+ table_positive.set_fontsize(font_size)
54
+ fig_length_positive.suptitle('Distribution of text length for positive sentiment tweets.', fontsize=16)
55
+
56
+ st.pyplot(fig_length_positive)
57
+
58
+ # negative Sentiment Tweets Bar
59
+ st.write('#### Distribution of Text Length for negative Sentiment Tweets')
60
+ fig_length_negative = plt.figure(figsize=(14, 7))
61
+
62
+ # Handle NaN values in 'text_processed'
63
+ df['length'] = df['text_processed'].apply(lambda x: len(str(x).split()) if pd.notna(x) else 0)
64
+
65
+ ax1 = fig_length_negative.add_subplot(122)
66
+ sns.histplot(df[df['sentiment']=='negative']['length'], ax=ax1, color='red')
67
+ describe_negative = df.length[df.sentiment=='negative'].describe().to_frame().round(2)
68
+
69
+ ax2 = fig_length_negative.add_subplot(121)
70
+ ax2.axis('off')
71
+ font_size = 14
72
+ bbox = [0, 0, 1, 1]
73
+ table_negative = ax2.table(cellText=describe_negative.values, rowLabels=describe_negative.index, bbox=bbox, colLabels=describe_negative.columns)
74
+ table_negative.set_fontsize(font_size)
75
+ fig_length_negative.suptitle('Distribution of text length for negative sentiment tweets.', fontsize=16)
76
+
77
+ st.pyplot(fig_length_negative)
78
+
79
+ # neutral Sentiment Tweets Bar
80
+ st.write('#### Distribution of Text Length for neutral Sentiment Tweets')
81
+ fig_length_neutral = plt.figure(figsize=(14, 7))
82
+
83
+ # Handle NaN values in 'text_processed'
84
+ df['length'] = df['text_processed'].apply(lambda x: len(str(x).split()) if pd.notna(x) else 0)
85
+
86
+ ax1 = fig_length_neutral.add_subplot(122)
87
+ sns.histplot(df[df['sentiment']=='neutral']['length'], ax=ax1, color='blue')
88
+ describe_neutral = df.length[df.sentiment=='neutral'].describe().to_frame().round(2)
89
+
90
+ ax2 = fig_length_neutral.add_subplot(121)
91
+ ax2.axis('off')
92
+ font_size = 14
93
+ bbox = [0, 0, 1, 1]
94
+ table_neutral = ax2.table(cellText=describe_neutral.values, rowLabels=describe_neutral.index, bbox=bbox, colLabels=describe_neutral.columns)
95
+ table_neutral.set_fontsize(font_size)
96
+ fig_length_neutral.suptitle('Distribution of text length for neutral sentiment tweets.', fontsize=16)
97
+
98
+ st.pyplot(fig_length_neutral)
99
+
100
+ # Membuat pie chart
101
+ st.write('#### Pie Chart - Sentiment Distribution')
102
+ labels = ['Neutral', 'Positive', 'Negative']
103
+ size = df['sentiment'].value_counts()
104
+ colors = ['lightgreen', 'lightskyblue', 'lightcoral']
105
+ explode = [0.01, 0.01, 0.1]
106
+
107
+ fig, axes = plt.subplots(figsize=(6, 5))
108
+ plt.pie(size, colors=colors, explode=explode,
109
+ labels=labels, shadow=True, startangle=90, autopct='%.2f%%')
110
+ plt.title('Sentiment Distribution', fontsize=20)
111
+ plt.legend()
112
+
113
+ st.pyplot(fig)
114
+ # #Membuat histogram
115
+ # st.write('#### Histogram of Age')
116
+ # fig = plt.figure(figsize=(15,5))
117
+ # sns.histplot(df['Overall'], bins = 30, kde = True)
118
+ # st.pyplot(fig)
119
+
120
+ # #membuat histogram berdasarkan inputan user
121
+ # st.write('#### Histogram berdasarkan input user')
122
+ # #kalo mau pake radio button, ganti selectbox jadi radio
123
+ # option = st.selectbox('Pilih Column : ', ('Age', 'Weight', 'Height', 'ShootingTotal'))
124
+ # fig = plt.figure(figsize= (15,5))
125
+ # sns.histplot(df[option], bins = 30, kde = True)
126
+ # st.pyplot(fig)
127
+
128
+ # #Membuat Plotly plot
129
+
130
+ # st.write('#### Plotly Plot - ValueEUR vs Overall')
131
+ # fig = px.scatter(df, x = 'ValueEUR', y = 'Overall', hover_data = ['Name', 'Age'])
132
+ # st.plotly_chart(fig)
133
+
134
+ if __name__ == '__main__':
135
+ run()
model_gru_2/assets/tokens.txt ADDED
The diff for this file is too large to render. See raw diff
 
model_gru_2/fingerprint.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:389fc4a0ba65798fd60fae3ddb562d50ee7ff0de8c3640a8afecc76f1a69bd39
3
+ size 55
model_gru_2/keras_metadata.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5c87c818d04c895d135b4cce0cfc2f03ad071938411898c7986fbcf95e1c591
3
+ size 26812
model_gru_2/saved_model.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:edddd288d1bba93e83dd2b36b46b39f7a48f9713ffbc8b8a8c8b511240ecf4fc
3
+ size 3542856
model_gru_2/variables/variables.data-00000-of-00001 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e27d92803de5105255153e03a804dd7aafbc1573ae96f938a8ac59161c12f5a
3
+ size 498765088
model_gru_2/variables/variables.index ADDED
Binary file (3.07 kB). View file
 
prediction.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from keras.models import load_model
4
+ from PIL import Image
5
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
6
+
7
+ # Load the GRU model
8
+ model = load_model('model_gru_2')
9
+
10
+ def run():
11
+
12
+ image = Image.open('twittersentiment.jpg')
13
+ st.image(image, caption = 'Twitter Sentiment')
14
+
15
+ with st.form('sentiment_prediction'):
16
+ # Field Input Text
17
+ input_text = st.text_area('Input Text', '', help='Enter the text for sentiment prediction')
18
+
19
+ # Create a submit button
20
+ submitted = st.form_submit_button('Predict')
21
+
22
+ # Inference
23
+ if submitted:
24
+ # Make a prediction using the model
25
+ # Convert the input text to lowercase (optional)
26
+ input_text = input_text.lower()
27
+
28
+ # Make a prediction using the model
29
+ predictions = model.predict(np.array([input_text]))
30
+
31
+ # Map predicted class to labels
32
+ predicted_class = np.argmax(predictions[0])
33
+ class_labels = {0: 'Negative', 1: 'Positive', 2: 'Neutral'}
34
+ predicted_label = class_labels[predicted_class]
35
+
36
+ # Display the results
37
+ st.write('## Sentiment Prediction:')
38
+ st.write('Input Text:', input_text)
39
+ st.write('Predicted Class:', predicted_class)
40
+ st.write('Predicted Label:', predicted_label)
41
+ st.write('Prediction Probabilities:', predictions[0])
42
+
43
+ if __name__ == '__main__':
44
+ run()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ seaborn
4
+ matplotlib
5
+ numpy
6
+ plotly
7
+ pillow
8
+ scikit-learn==1.3.2
tweets-update.csv ADDED
The diff for this file is too large to render. See raw diff
 
twittersentiment.jpg ADDED