Upload 6 files
Browse filesFiles changed (6)
- app.pyAdded+52
- requirements.txtAdded+7
- rf_flipflop_model.pklAdded+3
- rf_goboult_model.pklAdded+3
- tfidf_flipflop.pklAdded+3
- tfidf_goboult.pklAdded+3
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
import streamlit as stimport pickleimport stringfrom nltk.corpus import stopwordsfrom nltk.stem import WordNetLemmatizerfrom nltk.tokenize import word_tokenizeimport nltk
# Download NLTK datanltk.download('punkt')nltk.download('stopwords')nltk.download('wordnet')
# Load models and TF-IDFwith open('rf_goboult_model.pkl', 'rb') as f: goboult_model = pickle.load(f)with open('tfidf_goboult.pkl', 'rb') as f: goboult_tfidf = pickle.load(f)
with open('rf_flipflop_model.pkl', 'rb') as f: flipflop_model = pickle.load(f)with open('tfidf_flipflop.pkl', 'rb') as f: flipflop_tfidf = pickle.load(f)
stop_words = set(stopwords.words('english'))lemmatizer = WordNetLemmatizer()
def preprocess_text(text): text = text.lower() text = text.translate(str.maketrans('', '', string.punctuation)) tokens = word_tokenize(text) tokens = [lemmatizer.lemmatize(word) for word in tokens if word not in stop_words] return " ".join(tokens)
# Streamlit UIst.title("Sentiment Analysis for Goboult & Flipflop")dataset = st.selectbox("Select Dataset", ["Goboult", "Flipflop"])review = st.text_area("Enter your review here:")
if st.button("Predict Sentiment"): if review.strip() == "": st.warning("Please enter a review!") else: cleaned = preprocess_text(review) if dataset.lower() == "goboult": vectorized = goboult_tfidf.transform([cleaned]) pred = goboult_model.predict(vectorized)[0] else: vectorized = flipflop_tfidf.transform([cleaned]) pred = flipflop_model.predict(vectorized)[0] st.success(f"Predicted Sentiment: {pred}")1234567streamlitnltkscikit-learnpandasmatplotlibseabornwordcloud123version https://git-lfs.github.com/spec/v1oid sha256:f9d555d29a6320c18bb3847a8088e6d10b4dfe782cc82634cab9f9275842a431size 1412648123version https://git-lfs.github.com/spec/v1oid sha256:203c87252888ff9f886557a0c290c2d1f20a79deb814c7eecbd5c28329379403size 2058929123version https://git-lfs.github.com/spec/v1oid sha256:57315661dda21c7b025b2d76c2ad8c24462657fdd0178f47e193aff842f4a917size 23913123version https://git-lfs.github.com/spec/v1oid sha256:6939290d53f67d137083b776b07d458962a96acf938627ce5ae10feb3d32e758size 78455app.pyAdded+52
requirements.txtAdded+7
rf_flipflop_model.pklAdded+3
rf_goboult_model.pklAdded+3
tfidf_flipflop.pklAdded+3
tfidf_goboult.pklAdded+3