Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
from transformers import pipeline
|
|
|
|
|
2 |
|
3 |
# Load once at startup
|
4 |
classifier = pipeline(
|
5 |
"zero-shot-classification",
|
6 |
model="valhalla/distilbart-mnli-12-3"
|
7 |
)
|
8 |
-
|
9 |
|
10 |
def analyze_article(text, title, link):
|
11 |
t0 = time.time()
|
@@ -14,8 +16,10 @@ def analyze_article(text, title, link):
|
|
14 |
candidate_labels=["analytics", "data science", "business insight"],
|
15 |
multi_label=True
|
16 |
)
|
17 |
-
print(f"[DEBUG] Model inference time: {time.time() - t0:.2f}s")
|
18 |
-
|
|
|
|
|
19 |
return {
|
20 |
"title": title,
|
21 |
"link": link,
|
|
|
1 |
from transformers import pipeline
|
2 |
+
import time
|
3 |
+
|
4 |
|
5 |
# Load once at startup
|
6 |
classifier = pipeline(
|
7 |
"zero-shot-classification",
|
8 |
model="valhalla/distilbart-mnli-12-3"
|
9 |
)
|
10 |
+
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
11 |
|
12 |
def analyze_article(text, title, link):
|
13 |
t0 = time.time()
|
|
|
16 |
candidate_labels=["analytics", "data science", "business insight"],
|
17 |
multi_label=True
|
18 |
)
|
19 |
+
print(f"[DEBUG] Classifier Model inference time: {time.time() - t0:.2f}s")
|
20 |
+
# Summarize article text
|
21 |
+
summary = summarizer(text[:1024], max_length=150, min_length=40, do_sample=False)[0]['summary_text']
|
22 |
+
print(f"[DEBUG] Summarizer Model inference time: {time.time() - t0:.2f}s")
|
23 |
return {
|
24 |
"title": title,
|
25 |
"link": link,
|