Upload 6 files
Browse files- app.py +52 -0
- requirements.txt +7 -0
- rf_flipflop_model.pkl +3 -0
- rf_goboult_model.pkl +3 -0
- tfidf_flipflop.pkl +3 -0
- tfidf_goboult.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pickle
|
| 4 |
+
import string
|
| 5 |
+
from nltk.corpus import stopwords
|
| 6 |
+
from nltk.stem import WordNetLemmatizer
|
| 7 |
+
from nltk.tokenize import word_tokenize
|
| 8 |
+
import nltk
|
| 9 |
+
|
| 10 |
+
# Download NLTK data
|
| 11 |
+
nltk.download('punkt')
|
| 12 |
+
nltk.download('stopwords')
|
| 13 |
+
nltk.download('wordnet')
|
| 14 |
+
|
| 15 |
+
# Load models and TF-IDF
|
| 16 |
+
with open('rf_goboult_model.pkl', 'rb') as f:
|
| 17 |
+
goboult_model = pickle.load(f)
|
| 18 |
+
with open('tfidf_goboult.pkl', 'rb') as f:
|
| 19 |
+
goboult_tfidf = pickle.load(f)
|
| 20 |
+
|
| 21 |
+
with open('rf_flipflop_model.pkl', 'rb') as f:
|
| 22 |
+
flipflop_model = pickle.load(f)
|
| 23 |
+
with open('tfidf_flipflop.pkl', 'rb') as f:
|
| 24 |
+
flipflop_tfidf = pickle.load(f)
|
| 25 |
+
|
| 26 |
+
stop_words = set(stopwords.words('english'))
|
| 27 |
+
lemmatizer = WordNetLemmatizer()
|
| 28 |
+
|
| 29 |
+
def preprocess_text(text):
|
| 30 |
+
text = text.lower()
|
| 31 |
+
text = text.translate(str.maketrans('', '', string.punctuation))
|
| 32 |
+
tokens = word_tokenize(text)
|
| 33 |
+
tokens = [lemmatizer.lemmatize(word) for word in tokens if word not in stop_words]
|
| 34 |
+
return " ".join(tokens)
|
| 35 |
+
|
| 36 |
+
# Streamlit UI
|
| 37 |
+
st.title("Sentiment Analysis for Goboult & Flipflop")
|
| 38 |
+
dataset = st.selectbox("Select Dataset", ["Goboult", "Flipflop"])
|
| 39 |
+
review = st.text_area("Enter your review here:")
|
| 40 |
+
|
| 41 |
+
if st.button("Predict Sentiment"):
|
| 42 |
+
if review.strip() == "":
|
| 43 |
+
st.warning("Please enter a review!")
|
| 44 |
+
else:
|
| 45 |
+
cleaned = preprocess_text(review)
|
| 46 |
+
if dataset.lower() == "goboult":
|
| 47 |
+
vectorized = goboult_tfidf.transform([cleaned])
|
| 48 |
+
pred = goboult_model.predict(vectorized)[0]
|
| 49 |
+
else:
|
| 50 |
+
vectorized = flipflop_tfidf.transform([cleaned])
|
| 51 |
+
pred = flipflop_model.predict(vectorized)[0]
|
| 52 |
+
st.success(f"Predicted Sentiment: {pred}")
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
nltk
|
| 3 |
+
scikit-learn
|
| 4 |
+
pandas
|
| 5 |
+
matplotlib
|
| 6 |
+
seaborn
|
| 7 |
+
wordcloud
|
rf_flipflop_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f9d555d29a6320c18bb3847a8088e6d10b4dfe782cc82634cab9f9275842a431
|
| 3 |
+
size 1412648
|
rf_goboult_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:203c87252888ff9f886557a0c290c2d1f20a79deb814c7eecbd5c28329379403
|
| 3 |
+
size 2058929
|
tfidf_flipflop.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:57315661dda21c7b025b2d76c2ad8c24462657fdd0178f47e193aff842f4a917
|
| 3 |
+
size 23913
|
tfidf_goboult.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6939290d53f67d137083b776b07d458962a96acf938627ce5ae10feb3d32e758
|
| 3 |
+
size 78455
|