Delete app.py
Browse files
app.py
DELETED
|
@@ -1,52 +0,0 @@
|
|
| 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}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|