Spaces:
Sleeping
Sleeping
| from transformers import pipeline | |
| import streamlit as st | |
| 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 | |