forked from Scottcjn/grazer-skill
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.py
More file actions
executable file
·295 lines (252 loc) · 9.79 KB
/
demo.py
File metadata and controls
executable file
·295 lines (252 loc) · 9.79 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#!/usr/bin/env python3
"""
Grazer CLI Demo - Shows content discovery in action across multiple platforms.
Run:
python demo.py # Full demo (ArXiv + YouTube + Podcasts + BoTTube)
python demo.py --offline # Offline demo with sample data (no network)
python demo.py --arxiv # ArXiv only
python demo.py --youtube # YouTube only
python demo.py --podcasts # Podcasts only
"""
import argparse
import json
import sys
import time
# ── Sample data for offline demo ────────────────────────────
SAMPLE_ARXIV = [
{
"arxiv_id": "2401.12345v1",
"title": "Constraint-Bound Selection in Non-Bijunctive Attention Mechanisms",
"authors": ["A. Researcher", "B. Collaborator", "C. Advisor"],
"summary": "We propose a novel approach to attention that uses hardware-native "
"selection operations to prune weak paths and amplify strong ones.",
"published": "2024-01-15T00:00:00Z",
"url": "https://arxiv.org/abs/2401.12345",
"pdf_url": "https://arxiv.org/pdf/2401.12345v1",
"categories": ["cs.AI", "cs.LG"],
},
{
"arxiv_id": "2401.67890v2",
"title": "Proof of Antiquity: Hardware Age as a Sybil Resistance Mechanism",
"authors": ["S. Boudreaux"],
"summary": "We introduce a blockchain consensus mechanism that rewards vintage "
"hardware, using silicon aging fingerprints as unforgeable identity.",
"published": "2024-01-10T00:00:00Z",
"url": "https://arxiv.org/abs/2401.67890",
"pdf_url": "https://arxiv.org/pdf/2401.67890v2",
"categories": ["cs.CR", "cs.DC"],
},
]
SAMPLE_YOUTUBE = [
{
"id": "dQw4w9WgXcQ",
"title": "Building AI Agents That Discover Content Autonomously",
"channel": "Elyan Labs",
"description": "A walkthrough of the Grazer skill for multi-platform discovery.",
"published": "2024-03-01T12:00:00Z",
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"views": 4200,
},
{
"id": "abc123XYZab",
"title": "POWER8 LLM Inference at 147 tokens/sec",
"channel": "Vintage Computing",
"description": "Running language models on IBM POWER8 with vec_perm collapse.",
"published": "2024-02-15T08:00:00Z",
"url": "https://www.youtube.com/watch?v=abc123XYZab",
"views": 8900,
},
]
SAMPLE_PODCASTS = [
{
"id": 99999,
"name": "The Agent Internet Podcast",
"artist": "Elyan Labs",
"genre": "Technology",
"episode_count": 24,
"url": "https://podcasts.apple.com/podcast/99999",
"feed_url": "https://feeds.example.com/agent-internet",
"artwork": "https://example.com/artwork.jpg",
},
{
"id": 88888,
"name": "Proof of Work: Crypto & Hardware",
"artist": "BlockTalk Media",
"genre": "Technology",
"episode_count": 150,
"url": "https://podcasts.apple.com/podcast/88888",
"feed_url": "https://feeds.example.com/pow",
"artwork": "https://example.com/pow-art.jpg",
},
]
def print_header(text):
"""Print a styled section header."""
width = 60
print()
print("=" * width)
print(f" {text}")
print("=" * width)
print()
def print_divider():
print("-" * 60)
def demo_arxiv(offline=False):
"""Demonstrate ArXiv paper discovery."""
print_header("ArXiv Paper Discovery")
if offline:
papers = SAMPLE_ARXIV
print(" [offline mode - using sample data]\n")
else:
from grazer.arxiv_grazer import ArxivGrazer
grazer = ArxivGrazer()
print(" Searching arXiv for recent AI papers...\n")
try:
papers = grazer.discover(query="large language models", category="ai", limit=5)
except Exception as e:
print(f" Error: {e}")
print(" Falling back to sample data...\n")
papers = SAMPLE_ARXIV
for i, p in enumerate(papers, 1):
title = p.get("title", "(untitled)")
authors = p.get("authors", [])
author_str = ", ".join(authors[:3])
if len(authors) > 3:
author_str += f" +{len(authors) - 3} more"
url = p.get("url", "")
published = p.get("published", "")[:10]
cats = ", ".join(p.get("categories", [])[:3])
summary = p.get("summary", "")
if len(summary) > 120:
summary = summary[:117] + "..."
print(f" [{i}] {title}")
print(f" Authors: {author_str}")
print(f" Date: {published} | Categories: {cats}")
if summary:
print(f" {summary}")
print(f" {url}")
print()
print(f" Found {len(papers)} papers.")
print_divider()
def demo_youtube(offline=False):
"""Demonstrate YouTube video discovery."""
print_header("YouTube Video Discovery")
if offline:
videos = SAMPLE_YOUTUBE
print(" [offline mode - using sample data]\n")
else:
from grazer.youtube_grazer import YouTubeGrazer
grazer = YouTubeGrazer()
print(" Searching YouTube for AI agent videos...\n")
try:
videos = grazer.discover(query="AI agents tutorial", limit=5)
except Exception as e:
print(f" Error: {e}")
print(" Falling back to sample data...\n")
videos = SAMPLE_YOUTUBE
for i, v in enumerate(videos, 1):
title = v.get("title", "(untitled)")
channel = v.get("channel", "unknown")
url = v.get("url", "")
views = v.get("views", "")
views_str = f" | {views:,} views" if views else ""
print(f" [{i}] {title}")
print(f" Channel: {channel}{views_str}")
print(f" {url}")
print()
print(f" Found {len(videos)} videos.")
print_divider()
def demo_podcasts(offline=False):
"""Demonstrate podcast discovery."""
print_header("Podcast Discovery (iTunes)")
if offline:
shows = SAMPLE_PODCASTS
print(" [offline mode - using sample data]\n")
else:
from grazer.podcast_grazer import PodcastGrazer
grazer = PodcastGrazer()
print(" Searching iTunes for AI/technology podcasts...\n")
try:
shows = grazer.search(query="artificial intelligence technology", limit=5)
except Exception as e:
print(f" Error: {e}")
print(" Falling back to sample data...\n")
shows = SAMPLE_PODCASTS
for i, s in enumerate(shows, 1):
name = s.get("name", "(unnamed)")
artist = s.get("artist", "unknown")
genre = s.get("genre", "")
ep_count = s.get("episode_count", 0)
url = s.get("url", "")
print(f" [{i}] {name}")
print(f" By: {artist} | Genre: {genre} | {ep_count} episodes")
print(f" {url}")
print()
print(f" Found {len(shows)} podcasts.")
print_divider()
def demo_integration(offline=False):
"""Show GrazerClient unified discovery across all platforms."""
print_header("Unified Discovery (GrazerClient)")
if offline:
print(" [offline mode - showing what discover_all() returns]\n")
result = {
"arxiv": SAMPLE_ARXIV,
"youtube": SAMPLE_YOUTUBE,
"podcasts": SAMPLE_PODCASTS,
"bottube": [{"title": "Sample BoTTube video", "agent": "sophia-elya"}],
"moltbook": [{"title": "Sample Moltbook post", "submolt": "ai"}],
}
for platform, items in result.items():
print(f" {platform}: {len(items)} items")
if items:
first = items[0]
label = first.get("title") or first.get("name") or "(item)"
print(f" First: {label}")
print()
else:
from grazer import GrazerClient
client = GrazerClient()
print(" Calling client.discover_all(limit=3)...\n")
try:
result = client.discover_all(limit=3)
errors = result.pop("_errors", {})
for platform, items in sorted(result.items()):
err = errors.get(platform)
if err:
print(f" {platform}: OFFLINE ({err[:50]})")
else:
print(f" {platform}: {len(items)} items")
print()
if errors:
print(f" ({len(errors)} platform(s) offline -- this is normal without API keys)")
except Exception as e:
print(f" Error: {e}")
print_divider()
def main():
parser = argparse.ArgumentParser(
description="Grazer Demo - Content discovery in action"
)
parser.add_argument("--offline", action="store_true", help="Use sample data (no network calls)")
parser.add_argument("--arxiv", action="store_true", help="ArXiv demo only")
parser.add_argument("--youtube", action="store_true", help="YouTube demo only")
parser.add_argument("--podcasts", action="store_true", help="Podcasts demo only")
args = parser.parse_args()
specific = args.arxiv or args.youtube or args.podcasts
print()
print(" Grazer - Multi-Platform Content Discovery for AI Agents")
print(" https://github.com/Scottcjn/grazer-skill")
print()
if not specific or args.arxiv:
demo_arxiv(offline=args.offline)
if not specific or args.youtube:
demo_youtube(offline=args.offline)
if not specific or args.podcasts:
demo_podcasts(offline=args.offline)
if not specific:
demo_integration(offline=args.offline)
print()
print(" Demo complete. Install: pip install grazer-skill")
print(" CLI usage: grazer discover -p arxiv -l 5")
print(" grazer discover -p youtube -l 5")
print(" grazer discover -p podcasts -l 5")
print()
if __name__ == "__main__":
main()