Pro-Coder commited on
Commit
dc5b022
·
verified ·
1 Parent(s): 5cc3a89

Create pipeline.py

Browse files
Files changed (1) hide show
  1. pipeline.py +24 -0
pipeline.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ from utils import clean_text, generate_wordcloud
3
+
4
+ # Load Hugging Face models
5
+ sentiment_model = pipeline("sentiment-analysis")
6
+ summarizer = pipeline("summarization")
7
+
8
+ def process_comment(text):
9
+ # Clean text
10
+ cleaned = clean_text(text)
11
+
12
+ # Sentiment
13
+ sentiment = sentiment_model(cleaned)[0]
14
+
15
+ # Summary
16
+ try:
17
+ summary = summarizer(cleaned, max_length=60, min_length=10, do_sample=False)[0]["summary_text"]
18
+ except:
19
+ summary = "Summary not available (text too short)."
20
+
21
+ # Word cloud
22
+ wc_img = generate_wordcloud(cleaned)
23
+
24
+ return sentiment, summary, wc_img