-
Notifications
You must be signed in to change notification settings - Fork 155
/
google_news_example.py
56 lines (42 loc) · 1.54 KB
/
google_news_example.py
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
from obsei.analyzer.classification_analyzer import (
ClassificationAnalyzerConfig,
ZeroShotClassificationAnalyzer,
)
from obsei.source.google_news_source import GoogleNewsConfig, GoogleNewsSource
# Only fetch title and highlight
source_config_without_full_text = GoogleNewsConfig(
query="bitcoin",
max_results=5,
lookup_period="1d",
)
# Fetch full news article
source_config_with_full_text = GoogleNewsConfig(
query="bitcoin",
max_results=5,
fetch_article=True,
lookup_period="1d",
)
source = GoogleNewsSource()
analyzer_config = ClassificationAnalyzerConfig(
labels=["buy", "sell", "going up", "going down"],
)
text_analyzer = ZeroShotClassificationAnalyzer(
model_name_or_path="typeform/mobilebert-uncased-mnli", device="auto"
)
news_articles_without_full_text = source.lookup(source_config_without_full_text)
news_articles_with_full_text = source.lookup(source_config_with_full_text)
analyzer_responses_without_full_text = text_analyzer.analyze_input(
source_response_list=news_articles_without_full_text,
analyzer_config=analyzer_config,
)
analyzer_responses_with_full_text = text_analyzer.analyze_input(
source_response_list=news_articles_with_full_text, analyzer_config=analyzer_config
)
for article in news_articles_without_full_text:
print(article.__dict__)
for response in analyzer_responses_without_full_text:
print(response.__dict__)
for article in news_articles_with_full_text:
print(article.__dict__)
for response in analyzer_responses_with_full_text:
print(response.__dict__)