Download app.py from Srikanthgoud7/YoutubeCommentsAnalysis: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/Srikanthgoud7/YoutubeCommentsAnalysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/Srikanthgoud7/YoutubeCommentsAnalysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Srikanthgoud7/YoutubeCommentsAnalysis/resolve/main/app.py
1.54 kB
| 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") | |