import streamlit as st import pickle import re import nltk import numpy as np from nltk.corpus import stopwords from textblob import TextBlob st.title("YouTube Comment Analysis") st.video("https://www.youtube.com/watch?v=iCvmsMzlF7o") nltk.download('stopwords') stop_words = set(stopwords.words('english')) # Load saved model and vectorizer with open('sentiment_model.pkl', 'rb') as f: model = pickle.load(f) with open('tfidf_vectorizer.pkl', 'rb') as f: vectorizer = pickle.load(f) # Text cleaning function def clean_text(text): text = text.lower() text = re.sub(r"http\S+|www\S+|https\S+", '', text) text = re.sub(r'[^a-z\s]', '', text) text = re.sub(r'\s+', ' ', text).strip() text = ' '.join([word for word in text.split() if word not in stop_words]) return text # Streamlit UI st.title("🎯 YouTube Comment Sentiment Classifier") comment_input = st.text_area("Enter your YouTube comment here:") if st.button("Predict Sentiment"): if comment_input.strip() == "": st.warning("Please enter a comment.") else: cleaned = clean_text(comment_input) features = vectorizer.transform([cleaned]) prediction = model.predict(features)[0] st.subheader("🔍 Sentiment Prediction:") if prediction == "Positive": st.success("😊 Positive Comment") elif prediction == "Negative": st.error("😠 Negative Comment") else: st.info("😐 Neutral Comment")