Sentiment_Analysis / pipeline.py
Pro-Coder's picture
Update pipeline.py
346bce9 verified
Raw
History Blame
730 Bytes
from transformers import pipeline
from utils import clean_text, generate_wordcloud
# Load Hugging Face models
sentiment_model = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
def process_comment(text):
# Clean text
cleaned = clean_text(text)
# Sentiment
sentiment = sentiment_model(cleaned)[0]
# Summary
try:
summary = summarizer(cleaned, max_length=60, min_length=10, do_sample=False)[0]["summary_text"]
except:
summary = "Summary not available (text too short)."
# Word cloud
wc_img = generate_wordcloud(cleaned)
return sentiment, summary, wc_img