Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,46 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pickle
|
3 |
-
import re
|
4 |
-
from sklearn.feature_extraction.text import CountVectorizer
|
5 |
-
|
6 |
-
with open('count_vectorizer.pkl','rb')as vectorizer_file:
|
7 |
-
count_vectorizer = pickle.load(vectorizer_file)
|
8 |
-
|
9 |
-
with open('nb_classifier.pkl','rb')as classifier_file:
|
10 |
-
nb_classifier = pickle.load(classifier_file)
|
11 |
-
|
12 |
-
def process_text(text):
|
13 |
-
text = text.lower()
|
14 |
-
text = re.sub(r'http\S+', '', text)
|
15 |
-
text = re.sub(r'@[a-zA-Z0-9_]+', '', text)
|
16 |
-
text = re.sub(r'#', '', text)
|
17 |
-
text = re.sub(r'[^a-zA-Z\s]', '', text)
|
18 |
-
return text
|
19 |
-
|
20 |
-
sentiment_mapping = {
|
21 |
-
"Negative" : "Negative π",
|
22 |
-
"Positive" : "Positive π",
|
23 |
-
"Neutral" : "Neutral π",
|
24 |
-
"Irrelevant" : "Irrelevant π€·ββοΈ"
|
25 |
-
}
|
26 |
-
|
27 |
-
def main():
|
28 |
-
col1 , col2 , col3 ,col4 = st.columns([1,1,3,1])
|
29 |
-
with col3:
|
30 |
-
st.image("./
|
31 |
-
st.title("Twitter Sentiment Classifier")
|
32 |
-
st.write("Enter twitter tweet below :")
|
33 |
-
input_text = st.text_area("Input Text :","")
|
34 |
-
if st.button("Predict"):
|
35 |
-
cleaned_text = process_text(input_text)
|
36 |
-
vectorizer_text = count_vectorizer.transform([cleaned_text])
|
37 |
-
sentiment_prediction = nb_classifier.predict(vectorizer_text)[0]
|
38 |
-
|
39 |
-
predicted_sentiment = sentiment_mapping.get(sentiment_prediction , "Unknown Sentiment")
|
40 |
-
|
41 |
-
st.write("Predicted Sentimen :")
|
42 |
-
st.title(predicted_sentiment)
|
43 |
-
|
44 |
-
|
45 |
-
if __name__ == "__main__":
|
46 |
main()
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
import re
|
4 |
+
from sklearn.feature_extraction.text import CountVectorizer
|
5 |
+
|
6 |
+
with open('count_vectorizer.pkl','rb')as vectorizer_file:
|
7 |
+
count_vectorizer = pickle.load(vectorizer_file)
|
8 |
+
|
9 |
+
with open('nb_classifier.pkl','rb')as classifier_file:
|
10 |
+
nb_classifier = pickle.load(classifier_file)
|
11 |
+
|
12 |
+
def process_text(text):
|
13 |
+
text = text.lower()
|
14 |
+
text = re.sub(r'http\S+', '', text)
|
15 |
+
text = re.sub(r'@[a-zA-Z0-9_]+', '', text)
|
16 |
+
text = re.sub(r'#', '', text)
|
17 |
+
text = re.sub(r'[^a-zA-Z\s]', '', text)
|
18 |
+
return text
|
19 |
+
|
20 |
+
sentiment_mapping = {
|
21 |
+
"Negative" : "Negative π",
|
22 |
+
"Positive" : "Positive π",
|
23 |
+
"Neutral" : "Neutral π",
|
24 |
+
"Irrelevant" : "Irrelevant π€·ββοΈ"
|
25 |
+
}
|
26 |
+
|
27 |
+
def main():
|
28 |
+
col1 , col2 , col3 ,col4 = st.columns([1,1,3,1])
|
29 |
+
with col3:
|
30 |
+
st.image("./pngwing.com (1).png" , width=100)
|
31 |
+
st.title("Twitter Sentiment Classifier")
|
32 |
+
st.write("Enter twitter tweet below :")
|
33 |
+
input_text = st.text_area("Input Text :","")
|
34 |
+
if st.button("Predict"):
|
35 |
+
cleaned_text = process_text(input_text)
|
36 |
+
vectorizer_text = count_vectorizer.transform([cleaned_text])
|
37 |
+
sentiment_prediction = nb_classifier.predict(vectorizer_text)[0]
|
38 |
+
|
39 |
+
predicted_sentiment = sentiment_mapping.get(sentiment_prediction , "Unknown Sentiment")
|
40 |
+
|
41 |
+
st.write("Predicted Sentimen :")
|
42 |
+
st.title(predicted_sentiment)
|
43 |
+
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
main()
|