stanlys96 commited on
Commit
63226c9
·
verified ·
1 Parent(s): d91171b

Upload 6 files

Browse files
Files changed (2) hide show
  1. eda.py +4 -2
  2. prediction.py +17 -16
eda.py CHANGED
@@ -35,7 +35,7 @@ def app():
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')
@@ -55,6 +55,7 @@ def app():
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')
@@ -69,4 +70,5 @@ def app():
69
  # Plot stopword count distribution by sentiment
70
  sns.boxplot(data=temp_b, x='feeling', y='stopword_count')
71
  plt.title('Stopword Count by Sentiment')
72
- st.pyplot(plt)
 
 
35
  plt.xlabel('Text Length (characters)')
36
  plt.ylabel('Frequency')
37
  st.pyplot(plt)
38
+ st.write("Insight: text length distribution of our data appears to be right-skewed.")
39
  elif val == "Sentiment Distribution":
40
  sentiment_counts = df['feeling'].value_counts()
41
  st.header('Sentiment Distribution')
 
55
  st.pyplot(plt)
56
  st.write("Insight: surprise sentiment has the lowest value of around 900 data")
57
  elif val == "Word Clouds":
58
+ plt.title('Word Clouds')
59
  plot_wordcloud('joy')
60
  plot_wordcloud('sadness')
61
  plot_wordcloud('anger')
 
70
  # Plot stopword count distribution by sentiment
71
  sns.boxplot(data=temp_b, x='feeling', y='stopword_count')
72
  plt.title('Stopword Count by Sentiment')
73
+ st.pyplot(plt)
74
+ st.write("Insight: each sentiment has quite a number of stop words outliers")
prediction.py CHANGED
@@ -21,26 +21,27 @@ def get_feeling(number):
21
  def load_model():
22
  return tf.keras.models.load_model('model.keras', custom_objects={'KerasLayer': tf_hub.KerasLayer})
23
 
 
 
24
  def app():
25
  st.header('Prediction', divider='rainbow')
26
 
27
  user_input = st.text_input("Enter your text here:")
28
  if 'the_model' not in st.session_state:
29
  with st.spinner("Loading the model, please wait..."):
30
- st.session_state.the_model = load_model()
31
- if st.button('Predict', type="secondary"):
32
- data = {
33
- "text_processed": [
34
- user_input
35
- ]
36
- }
37
- df = pd.DataFrame(data)
38
- with st.spinner("Making prediction..."):
39
- # Replace with your preprocessing and prediction code
40
- predictions = st.session_state.the_model.predict(df)
41
- predicted_class = np.argmax(predictions, axis=1)
42
- the_sentiment = predicted_class[0]
43
 
44
- st.write(f"We have predicted that the sentiment of this text is {get_feeling(the_sentiment)}")
45
- else:
46
- st.write("Click the button to predict!")
 
21
  def load_model():
22
  return tf.keras.models.load_model('model.keras', custom_objects={'KerasLayer': tf_hub.KerasLayer})
23
 
24
+ st.session_state.the_model = load_model()
25
+
26
  def app():
27
  st.header('Prediction', divider='rainbow')
28
 
29
  user_input = st.text_input("Enter your text here:")
30
  if 'the_model' not in st.session_state:
31
  with st.spinner("Loading the model, please wait..."):
32
+ if st.button('Predict', type="secondary"):
33
+ data = {
34
+ "text_processed": [
35
+ user_input
36
+ ]
37
+ }
38
+ df = pd.DataFrame(data)
39
+ with st.spinner("Making prediction..."):
40
+ # Replace with your preprocessing and prediction code
41
+ predictions = st.session_state.the_model.predict(df)
42
+ predicted_class = np.argmax(predictions, axis=1)
43
+ the_sentiment = predicted_class[0]
 
44
 
45
+ st.write(f"We have predicted that the sentiment of this text is {get_feeling(the_sentiment)}")
46
+ else:
47
+ st.write("Click the button to predict!")