iamisha commited on
Commit
2a982df
ยท
verified ยท
1 Parent(s): 5f26f46

uploading app files

Browse files
Sentiment_CNN_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:716cbb90365fdc3ac8c6f918d16b8c47bd33c9fbe0be34c62da16e9c3483c2af
3
+ size 283407096
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from keras.models import load_model
3
+ from keras.preprocessing.sequence import pad_sequences
4
+ from streamlit_lottie import st_lottie
5
+ import requests
6
+ import pickle
7
+
8
+ col1, col2 = st.columns([1, 1])
9
+
10
+ with col1:
11
+
12
+ # Load the saved tokenizer
13
+ with open('tokenizer.pickle', 'rb') as handle:
14
+ tokenizer = pickle.load(handle)
15
+
16
+ # Load the saved MAX_SEQUENCE_LENGTH
17
+ with open('max_sequence_length.txt', 'r') as f:
18
+ MAX_SEQUENCE_LENGTH = int(f.read())
19
+
20
+ # Load the saved model
21
+ model = load_model('Sentiment_CNN_model.h5')
22
+
23
+ # Define the tokenizer function
24
+ def tokenize_text(text):
25
+ # Tokenize text
26
+ x_test = pad_sequences(tokenizer.texts_to_sequences([text]), maxlen=MAX_SEQUENCE_LENGTH)
27
+ return x_test
28
+
29
+ # Streamlit app
30
+ st.title('Twitter Sentiment Analysis')
31
+
32
+ user_input = st.text_input("Enter a tweet for sentiment analysis")
33
+
34
+ if st.button('Submit'):
35
+ processed_input = tokenize_text(user_input)
36
+ prediction = model.predict(processed_input)
37
+ if prediction >= 0.7:
38
+ st.success(f"Positive sentiment ๐Ÿ˜Š")
39
+ st.slider('Sentiment Score', 0,10, int (prediction*10))
40
+ elif 0.3 < prediction < 0.7: # Adjusted the condition to check for values between 0.4 and 0.7
41
+ st.info(f"Neutral sentiment ๐Ÿ™‚")
42
+ st.slider('Sentiment Score', 0,10, int(prediction*10))
43
+ else:
44
+ st.warning(f"Negative sentiment ๐Ÿ˜–")
45
+ st.slider('Sentiment Score', 0,10, int(prediction*10))
46
+ with col2:
47
+ def load_lottieurl(url: str):
48
+ r = requests.get(url)
49
+ if r.status_code != 200:
50
+ return None
51
+ return r.json()
52
+ lottie_hello = load_lottieurl("https://lottie.host/22856a7c-7ef0-453d-81ea-dc5842ab763a/p0C048YfUz.json")
53
+
54
+ st_lottie(
55
+ lottie_hello,
56
+ speed=1,
57
+ reverse=False,
58
+ loop=True,
59
+ quality="high",
60
+ width=300,
61
+ height=300,
62
+ key=None,
63
+ )
64
+
max_sequence_length.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ 300
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+
2
+ Keras-Preprocessing==1.1.2
3
+ streamlit==1.31.0
4
+ streamlit-lottie==0.0.5
5
+ tensorflow==2.15.0
tokenizer.pickle ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2d65057a02c4577c625d24a893556a8cee46e78353d8e6ef09494bade586cfe
3
+ size 10438740