-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtext_summarizer.py
More file actions
64 lines (49 loc) · 1.98 KB
/
Copy pathtext_summarizer.py
File metadata and controls
64 lines (49 loc) · 1.98 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
"""
Text Summarizer: Condense articles or documents into key points.
Simple use case: you have an article or document but only need
the key points. Get a summary with controlled length.
Run:
export OPENAI_API_KEY=sk-...
python examples/usecases/text_summarizer.py
"""
from enzu import Enzu
client = Enzu()
print("=" * 60)
print("TEXT SUMMARIZER")
print("=" * 60)
# Example article
article = """
Remote work has fundamentally changed how companies operate. A recent study
of 500 companies found that 73% now offer some form of remote work, up from
just 30% in 2019. The shift has had mixed effects on productivity.
Companies report that individual contributor work has improved, with
developers and writers producing more output when working from home. However,
collaborative work has suffered. Brainstorming sessions and spontaneous
conversations are harder to replicate virtually.
The biggest challenge is onboarding. New employees take 50% longer to become
productive when starting remotely. They miss the informal learning that
happens by sitting near experienced colleagues.
Companies are experimenting with hybrid models: 2-3 days in office for
collaboration, remaining days at home for focused work. Early data suggests
this balances productivity with team cohesion.
The long-term effects on company culture remain unclear. Some predict a
return to offices as economic conditions tighten, while others believe
remote work is here to stay.
"""
print(f"\n📄 Article ({len(article.split())} words)")
print("-" * 60)
print("\n📌 Summary:\n")
result = client.run(
f"""Summarize this article in 3 bullet points. Be concise.
{article}""",
tokens=150,
return_report=True,
)
output = getattr(result, "answer", None) or getattr(result, "output_text", None)
print(output)
print("\n" + "-" * 60)
print(f" Tokens: {result.budget_usage.total_tokens}")
if result.budget_usage.cost_usd:
print(f" Cost: ${result.budget_usage.cost_usd:.4f}")
print("=" * 60)