Spaces:
Running
Running
Update model.py
Browse files
model.py
CHANGED
@@ -15,15 +15,13 @@ import numpy as np
|
|
15 |
# === Load Hugging Face Pipelines ===
|
16 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
17 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
18 |
-
emotion_pipeline = pipeline("text-classification", model="
|
19 |
|
20 |
# === Summarization Functions ===
|
21 |
def summarize_review(text, max_len=60, min_len=10):
|
22 |
-
"""Transformer-based summarization (brief)"""
|
23 |
return summarizer(text, max_length=max_len, min_length=min_len, do_sample=False)[0]["summary_text"]
|
24 |
|
25 |
def smart_summarize(text, n_clusters=1):
|
26 |
-
"""TF-IDF Clustering based summarization"""
|
27 |
sentences = sent_tokenize(text)
|
28 |
if len(sentences) <= 1:
|
29 |
return text
|
@@ -54,7 +52,7 @@ def detect_emotion(text):
|
|
54 |
result = emotion_pipeline(text)[0]
|
55 |
return result["label"]
|
56 |
except Exception:
|
57 |
-
return "
|
58 |
|
59 |
# === Follow-up Q&A (single or multi) ===
|
60 |
def answer_followup(text, question, verbosity="brief"):
|
|
|
15 |
# === Load Hugging Face Pipelines ===
|
16 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
17 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
18 |
+
emotion_pipeline = pipeline("text-classification", model="bhadresh-savani/distilbert-base-uncased-emotion", top_k=1)
|
19 |
|
20 |
# === Summarization Functions ===
|
21 |
def summarize_review(text, max_len=60, min_len=10):
|
|
|
22 |
return summarizer(text, max_length=max_len, min_length=min_len, do_sample=False)[0]["summary_text"]
|
23 |
|
24 |
def smart_summarize(text, n_clusters=1):
|
|
|
25 |
sentences = sent_tokenize(text)
|
26 |
if len(sentences) <= 1:
|
27 |
return text
|
|
|
52 |
result = emotion_pipeline(text)[0]
|
53 |
return result["label"]
|
54 |
except Exception:
|
55 |
+
return "neutral"
|
56 |
|
57 |
# === Follow-up Q&A (single or multi) ===
|
58 |
def answer_followup(text, question, verbosity="brief"):
|