File size: 1,543 Bytes
0ec5b98 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 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")
|