Spaces:
Sleeping
Sleeping
File size: 1,167 Bytes
2a73b7d 455004e 2a73b7d 94ae888 0b61c26 455004e 94ae888 455004e 2a73b7d 6c1b6bd 2a73b7d | 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 | from transformers import pipeline
import streamlit as st
@st.cache_resource
def get_llm_pipelines():
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli", truncation=True)
sentiment_pipe = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english", truncation=True)
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-6-6", truncation=True)
return classifier, sentiment_pipe, summarizer
def analyze_post(text, classifier, sentiment_pipe, summarizer):
if not text or not text.strip():
return {"category": "N/A", "sentiment": "N/A", "summary": "Empty"}
result = {}
labels = ["Bug Report", "Feature Request", "Competitor Mention", "Positive Feedback"]
hypothesis = "This text is about a {}."
result["category"] = classifier(text, labels, hypothesis_template=hypothesis)["labels"][0]
result["sentiment"] = sentiment_pipe(text)[0]['label']
if len(text.split()) > 40:
result["summary"] = summarizer(text, max_length=60, min_length=20, do_sample=False)[0]['summary_text']
else:
result["summary"] = text
return result
|