Kurkur99 commited on
Commit
49ab3c7
1 Parent(s): 9272d64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -16
app.py CHANGED
@@ -1,22 +1,66 @@
1
  import streamlit as st
2
  import pandas as pd
3
- from eda import display_eda
4
- from prediction import predict_and_strategy
 
 
 
 
5
 
6
- # Load the data
7
- data = pd.read_csv('threads_reviews.csv')
 
 
8
 
9
- st.title("Sentiment Analysis and Business Strategy")
 
 
 
 
 
 
10
 
11
- # EDA Section
12
- st.header("Exploratory Data Analysis")
13
- if st.checkbox("Show EDA", False): # Checkbox to toggle EDA display
14
- display_eda(data)
15
 
16
- # Prediction Section
17
- st.header("Prediction")
18
- user_input = st.text_area("Enter text for sentiment analysis:", "")
19
- if st.button("Analyze"):
20
- sentiment, strategy = predict_and_strategy(user_input)
21
- st.write(f"Sentiment: {sentiment}")
22
- st.write(f"Strategy: {strategy}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ from wordcloud import WordCloud
6
+ from sentiment_labeling import add_sentiment_column
7
+ from keras.models import load_model
8
+ import pickle
9
 
10
+ # Load the model and tokenizer
11
+ model = load_model('model.h5')
12
+ with open('tokenizer.pkl', 'rb') as f:
13
+ tokenizer = pickle.load(f)
14
 
15
+ def predict_sentiment(text):
16
+ # Tokenize and pad the input text
17
+ seq = tokenizer.texts_to_sequences([text])
18
+ padded_seq = pad_sequences(seq, maxlen=MAX_LENGTH)
19
+ # Predict using the model
20
+ prediction = model.predict(padded_seq)
21
+ return np.argmax(prediction)
22
 
23
+ # Streamlit app
24
+ st.title("Thread Review Sentiment Analysis")
 
 
25
 
26
+ # Upload CSV file
27
+ uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
28
+ if uploaded_file:
29
+ data = pd.read_csv(uploaded_file)
30
+ st.write("Data Loaded Successfully!")
31
+
32
+ # Display raw data
33
+ if st.checkbox("Show raw data"):
34
+ st.write(data)
35
+
36
+ # Add sentiment column
37
+ data = add_sentiment_column(data)
38
+
39
+ # Distribution of sentiments
40
+ st.subheader("Distribution of Sentiments")
41
+ sentiment_counts = data['sentiment'].value_counts()
42
+ fig, ax = plt.subplots()
43
+ sentiment_counts.plot(kind='bar', ax=ax)
44
+ ax.set_title('Distribution of Sentiments')
45
+ ax.set_xlabel('Sentiment')
46
+ ax.set_ylabel('Count')
47
+ st.pyplot(fig)
48
+
49
+ # Word cloud for each sentiment
50
+ st.subheader("Word Clouds for Sentiments")
51
+ sentiments = ['positive', 'neutral', 'negative']
52
+ for sentiment in sentiments:
53
+ st.write(f"Word Cloud for {sentiment}")
54
+ subset = data[data['sentiment'] == sentiment]
55
+ text = " ".join(review for review in subset['review'])
56
+ wordcloud = WordCloud(max_words=100, background_color="white").generate(text)
57
+ plt.figure()
58
+ plt.imshow(wordcloud, interpolation="bilinear")
59
+ plt.axis("off")
60
+ st.pyplot()
61
+
62
+ # Individual review prediction
63
+ user_input = st.text_area("Type a review here to predict its sentiment:")
64
+ if user_input:
65
+ sentiment_pred = predict_sentiment(user_input)
66
+ st.write(f"The predicted sentiment is: {sentiment_pred}")