RichardVR commited on
Commit
367a152
·
verified ·
1 Parent(s): afcc1ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -909
app.py CHANGED
@@ -1,910 +1,66 @@
1
- import json
 
 
2
 
3
- Workflow='''{
4
- "name": "Workflow 1",
5
- "nodes": [
6
- {
7
- "parameters": {
8
- "method": "POST",
9
- "url": "https://backend.blotato.com/v2/media",
10
- "sendHeaders": true,
11
- "headerParameters": {
12
- "parameters": [
13
- {
14
- "name": "blotato-api-key",
15
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
16
- }
17
- ]
18
- },
19
- "sendBody": true,
20
- "bodyParameters": {
21
- "parameters": [
22
- {
23
- "name": "url",
24
- "value": "={{ $('Get Avatar Video').item.json.data.video_url }}"
25
- }
26
- ]
27
- },
28
- "options": {}
29
- },
30
- "type": "n8n-nodes-base.httpRequest",
31
- "typeVersion": 4.2,
32
- "position": [
33
- 2200,
34
- 960
35
- ],
36
- "id": "3fa94104-fccc-4073-b04f-484ce3a231d8",
37
- "name": "Upload to Blotato"
38
- },
39
- {
40
- "parameters": {
41
- "method": "POST",
42
- "url": "https://backend.blotato.com/v2/posts",
43
- "sendHeaders": true,
44
- "headerParameters": {
45
- "parameters": [
46
- {
47
- "name": "blotato-api-key",
48
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
49
- }
50
- ]
51
- },
52
- "sendBody": true,
53
- "specifyBody": "json",
54
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"instagram\"\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_long.toJsonString() }},\n \"platform\": \"instagram\",\n \"mediaUrls\": [\"{{ $json.url }}\"]\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.instagram_id }}\"\n }\n}",
55
- "options": {}
56
- },
57
- "type": "n8n-nodes-base.httpRequest",
58
- "typeVersion": 4.2,
59
- "position": [
60
- 2440,
61
- 160
62
- ],
63
- "id": "fcb1515a-3462-44d0-a201-9d6de3f00761",
64
- "name": "[Instagram] Publish via Blotato",
65
- "disabled": true
66
- },
67
- {
68
- "parameters": {
69
- "method": "POST",
70
- "url": "https://backend.blotato.com/v2/posts",
71
- "sendHeaders": true,
72
- "headerParameters": {
73
- "parameters": [
74
- {
75
- "name": "blotato-api-key",
76
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
77
- }
78
- ]
79
- },
80
- "sendBody": true,
81
- "specifyBody": "json",
82
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"facebook\",\n \"pageId\": \"{{ $('Prepare for Publish').item.json.facebook_page_id }}\"\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_long.toJsonString() }},\n \"platform\": \"facebook\",\n \"mediaUrls\": [\"{{ $json.url }}\"]\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.facebook_id }}\"\n }\n}",
83
- "options": {}
84
- },
85
- "type": "n8n-nodes-base.httpRequest",
86
- "typeVersion": 4.2,
87
- "position": [
88
- 2440,
89
- 500
90
- ],
91
- "id": "f00e9fb2-c520-47f8-8ef7-cf0ad90333ba",
92
- "name": "[Facebook] Publish via Blotato",
93
- "disabled": true
94
- },
95
- {
96
- "parameters": {
97
- "method": "POST",
98
- "url": "https://backend.blotato.com/v2/posts",
99
- "sendHeaders": true,
100
- "headerParameters": {
101
- "parameters": [
102
- {
103
- "name": "blotato-api-key",
104
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
105
- }
106
- ]
107
- },
108
- "sendBody": true,
109
- "specifyBody": "json",
110
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"linkedin\"\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_long.toJsonString() }},\n \"platform\": \"linkedin\",\n \"mediaUrls\": [\"{{ $json.url }}\"]\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.linkedin_id }}\"\n }\n}",
111
- "options": {}
112
- },
113
- "type": "n8n-nodes-base.httpRequest",
114
- "typeVersion": 4.2,
115
- "position": [
116
- 2440,
117
- 960
118
- ],
119
- "id": "d2afe680-6471-417e-b1bb-c2485e88a4e5",
120
- "name": "[Linkedin] Publish via Blotato",
121
- "disabled": true
122
- },
123
- {
124
- "parameters": {
125
- "method": "POST",
126
- "url": "https://backend.blotato.com/v2/posts",
127
- "sendHeaders": true,
128
- "headerParameters": {
129
- "parameters": [
130
- {
131
- "name": "blotato-api-key",
132
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
133
- }
134
- ]
135
- },
136
- "sendBody": true,
137
- "specifyBody": "json",
138
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"tiktok\",\n \"isYourBrand\": false,\n \"disabledDuet\": false,\n \"privacyLevel\": \"PUBLIC_TO_EVERYONE\",\n \"isAiGenerated\": false,\n \"disabledStitch\": false,\n \"disabledComments\": false,\n \"isBrandedContent\": false\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_long.toJsonString() }},\n \"platform\": \"tiktok\",\n \"mediaUrls\": [\"{{ $json.url }}\"]\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.tiktok_id }}\"\n }\n}\n",
139
- "options": {}
140
- },
141
- "type": "n8n-nodes-base.httpRequest",
142
- "typeVersion": 4.2,
143
- "position": [
144
- 2440,
145
- 1360
146
- ],
147
- "id": "c8699912-f113-495e-94b2-c41bc7c0e31f",
148
- "name": "[Tiktok] Publish via Blotato",
149
- "disabled": true
150
- },
151
- {
152
- "parameters": {
153
- "resource": "image",
154
- "prompt": "={{ $('Prepare for Publish').item.json.final_text_long }}",
155
- "options": {
156
- "returnImageUrls": true
157
- }
158
- },
159
- "type": "@n8n/n8n-nodes-langchain.openAi",
160
- "typeVersion": 1.8,
161
- "position": [
162
- 2440,
163
- 1760
164
- ],
165
- "id": "576b4fd2-037a-485e-b45a-6ea5e17c749b",
166
- "name": "OpenAI",
167
- "disabled": true
168
- },
169
- {
170
- "parameters": {
171
- "method": "POST",
172
- "url": "https://backend.blotato.com/v2/media",
173
- "sendHeaders": true,
174
- "headerParameters": {
175
- "parameters": [
176
- {
177
- "name": "blotato-api-key",
178
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
179
- }
180
- ]
181
- },
182
- "sendBody": true,
183
- "bodyParameters": {
184
- "parameters": [
185
- {
186
- "name": "url",
187
- "value": "={{ $json.url }}"
188
- }
189
- ]
190
- },
191
- "options": {}
192
- },
193
- "type": "n8n-nodes-base.httpRequest",
194
- "typeVersion": 4.2,
195
- "position": [
196
- 2660,
197
- 1760
198
- ],
199
- "id": "f1431dec-cdd0-4425-a2d3-603f69bd6cf5",
200
- "name": "Upload to Blotato - Image",
201
- "disabled": true
202
- },
203
- {
204
- "parameters": {
205
- "method": "POST",
206
- "url": "https://backend.blotato.com/v2/posts",
207
- "sendHeaders": true,
208
- "headerParameters": {
209
- "parameters": [
210
- {
211
- "name": "blotato-api-key",
212
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
213
- }
214
- ]
215
- },
216
- "sendBody": true,
217
- "specifyBody": "json",
218
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"pinterest\",\n \"boardId\": \"{{ $('Prepare for Publish').item.json.pinterest_board_id }}\",\n \"link\": \"https://www.tiktok.com/@sabrina_ramonov\"\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_short.toJsonString() }},,\n \"platform\": \"pinterest\",\n \"mediaUrls\": [\"{{ $json.url }}\"]\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.pinterest_id }}\"\n }\n}\n",
219
- "options": {}
220
- },
221
- "type": "n8n-nodes-base.httpRequest",
222
- "typeVersion": 4.2,
223
- "position": [
224
- 2880,
225
- 1760
226
- ],
227
- "id": "45ee656f-b145-4ea3-bda7-b5cc96a2c699",
228
- "name": "[Pinterest] Publish via Blotato",
229
- "disabled": true
230
- },
231
- {
232
- "parameters": {
233
- "method": "POST",
234
- "url": "https://backend.blotato.com/v2/posts",
235
- "sendHeaders": true,
236
- "headerParameters": {
237
- "parameters": [
238
- {
239
- "name": "blotato-api-key",
240
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
241
- }
242
- ]
243
- },
244
- "sendBody": true,
245
- "specifyBody": "json",
246
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"youtube\",\n \"title\": \"TEST VIDEO\",\n \"privacyStatus\": \"public\",\n \"shouldNotifySubscribers\": true\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_long.toJsonString() }},\n \"platform\": \"youtube\",\n \"mediaUrls\": [\"{{ $json.url }}\"]\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.youtube_id }}\"\n }\n}",
247
- "options": {}
248
- },
249
- "type": "n8n-nodes-base.httpRequest",
250
- "typeVersion": 4.2,
251
- "position": [
252
- 2800,
253
- 160
254
- ],
255
- "id": "381875de-eddd-4363-afd5-06e07eb26728",
256
- "name": "[Youtube] Publish via Blotato"
257
- },
258
- {
259
- "parameters": {
260
- "method": "POST",
261
- "url": "https://backend.blotato.com/v2/posts",
262
- "sendHeaders": true,
263
- "headerParameters": {
264
- "parameters": [
265
- {
266
- "name": "blotato-api-key",
267
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
268
- }
269
- ]
270
- },
271
- "sendBody": true,
272
- "specifyBody": "json",
273
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"threads\"\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_short.toJsonString() }},\n \"platform\": \"threads\",\n \"mediaUrls\": [\"{{ $json.url }}\"]\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.threads_id }}\"\n }\n}\n",
274
- "options": {}
275
- },
276
- "type": "n8n-nodes-base.httpRequest",
277
- "typeVersion": 4.2,
278
- "position": [
279
- 2800,
280
- 500
281
- ],
282
- "id": "68537e7b-ce14-4184-9cb9-6f6e3e52be2e",
283
- "name": "[Threads] Publish via Blotato",
284
- "disabled": true
285
- },
286
- {
287
- "parameters": {
288
- "method": "POST",
289
- "url": "https://backend.blotato.com/v2/posts",
290
- "sendHeaders": true,
291
- "headerParameters": {
292
- "parameters": [
293
- {
294
- "name": "blotato-api-key",
295
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
296
- }
297
- ]
298
- },
299
- "sendBody": true,
300
- "specifyBody": "json",
301
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"twitter\"\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_short.toJsonString() }},\n \"platform\": \"twitter\",\n \"mediaUrls\": [\"{{ $json.url }}\"]\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.twitter_id }}\"\n }\n}\n",
302
- "options": {}
303
- },
304
- "type": "n8n-nodes-base.httpRequest",
305
- "typeVersion": 4.2,
306
- "position": [
307
- 2800,
308
- 960
309
- ],
310
- "id": "80bba3a1-8fd0-4e01-8ce4-567d440d3b73",
311
- "name": "[Twitter] Publish via Blotato",
312
- "disabled": true
313
- },
314
- {
315
- "parameters": {
316
- "method": "POST",
317
- "url": "https://backend.blotato.com/v2/posts",
318
- "sendHeaders": true,
319
- "headerParameters": {
320
- "parameters": [
321
- {
322
- "name": "blotato-api-key",
323
- "value": "={{ $('Prepare for Publish').item.json.blotato_api_key }}"
324
- }
325
- ]
326
- },
327
- "sendBody": true,
328
- "specifyBody": "json",
329
- "jsonBody": "={\n \"post\": {\n \"target\": {\n \"targetType\": \"bluesky\"\n },\n \"content\": {\n \"text\": {{ $('Prepare for Publish').item.json.final_text_short.toJsonString() }},\n \"platform\": \"bluesky\",\n \"mediaUrls\": []\n },\n \"accountId\": \"{{ $('Prepare for Publish').item.json.bluesky_id }}\"\n }\n}\n",
330
- "options": {}
331
- },
332
- "type": "n8n-nodes-base.httpRequest",
333
- "typeVersion": 4.2,
334
- "position": [
335
- 2800,
336
- 1360
337
- ],
338
- "id": "a60e3e2d-3224-4ed9-b981-63aeaf754032",
339
- "name": "[Bluesky] Publish via Blotato",
340
- "disabled": true
341
- },
342
- {
343
- "parameters": {
344
- "rule": {
345
- "interval": [
346
- {
347
- "triggerAtHour": 10
348
- }
349
- ]
350
- }
351
- },
352
- "type": "n8n-nodes-base.scheduleTrigger",
353
- "typeVersion": 1.2,
354
- "position": [
355
- 40,
356
- 960
357
- ],
358
- "id": "fb46b60f-d916-4dfd-8c36-8f417856ac7f",
359
- "name": "Schedule Trigger"
360
- },
361
- {
362
- "parameters": {
363
- "promptType": "define",
364
- "text": "# INSTRUCTIONS\n\nPerform the following tasks, in order:\n\n1. Fetch the top 10 stories from Hacker News from the past 24 hours related to AI or LLMs. \n\n2. Select the top story that is most likely to go viral on social media. \n\n3. Fetch the article and Hacker News comments.\n\n4. Create a 30-second monologue script for an AI avatar video, following these guidelines:\n - The script should be approximately 30 seconds when spoken aloud.\n - Include lots of details and statistics from the article.\n - Use 6th grade reading level.\n - Balanced viewpoint.\n - Script should be in single paragraph\n\n5. Update the script's first 2 sentences to use sensational viral hooks that grab the viewer's attention and spark curiosity. The 3rd sentence should start diving into the article's details.\n\n6. Replace the last sentence with: \"Hit follow to stay ahead in AI!\"\n\n# OUTPUT FORMAT\n\nONLY output the exact video script. Do not output anything else. NEVER include intermediate thoughts, notes, or formatting.\nR",
365
- "options": {
366
- "returnIntermediateSteps": true
367
- }
368
- },
369
- "type": "@n8n/n8n-nodes-langchain.agent",
370
- "typeVersion": 1.8,
371
- "position": [
372
- 240,
373
- 960
374
- ],
375
- "id": "70a96a77-6df6-4717-8324-3d40334a8a74",
376
- "name": "AI Agent"
377
- },
378
- {
379
- "parameters": {
380
- "articleId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Article_ID', ``, 'string') }}",
381
- "additionalFields": {
382
- "includeComments": true
383
- }
384
- },
385
- "type": "n8n-nodes-base.hackerNewsTool",
386
- "typeVersion": 1,
387
- "position": [
388
- 480,
389
- 1160
390
- ],
391
- "id": "ffb17043-9f6d-4379-845f-684fd835269f",
392
- "name": "Fetch HN Article"
393
- },
394
- {
395
- "parameters": {
396
- "resource": "all",
397
- "additionalFields": {
398
- "keyword": "AI",
399
- "tags": [
400
- "front_page"
401
- ]
402
- }
403
- },
404
- "type": "n8n-nodes-base.hackerNewsTool",
405
- "typeVersion": 1,
406
- "position": [
407
- 320,
408
- 1160
409
- ],
410
- "id": "513d839e-b2f2-4410-8373-b8e774a0bf5e",
411
- "name": "Fetch HN Front Page"
412
- },
413
- {
414
- "parameters": {
415
- "amount": 8,
416
- "unit": "minutes"
417
- },
418
- "type": "n8n-nodes-base.wait",
419
- "typeVersion": 1.1,
420
- "position": [
421
- 1440,
422
- 960
423
- ],
424
- "id": "351ca8a7-e357-4114-8499-42b93fee76b6",
425
- "name": "Wait",
426
- "webhookId": "d9404622-0a06-4a65-959e-badd4fd87465",
427
- "alwaysOutputData": false
428
- },
429
- {
430
- "parameters": {
431
- "model": {
432
- "__rl": true,
433
- "value": "gpt-4o-mini",
434
- "mode": "list",
435
- "cachedResultName": "gpt-4o-mini"
436
- },
437
- "options": {}
438
- },
439
- "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
440
- "typeVersion": 1.2,
441
- "position": [
442
- 180,
443
- 1160
444
- ],
445
- "id": "2c2baeca-4885-4098-b85a-fdbe924d1f21",
446
- "name": "Write Script",
447
- "credentials": {
448
- "openAiApi": {
449
- "id": "F9KdoKWLuehFNuFM",
450
- "name": "OpenAi account (1)"
451
- }
452
- }
453
- },
454
- {
455
- "parameters": {
456
- "mode": "raw",
457
- "jsonOutput": "{\n \"heygen_api_key\": \"OTdmMGZlYjVhMGQzNDZlNjhmZGMwZWQ3MjNjZjJmNTAtMTc1MDg4NDgwNA==\",\n \"avatar_id\": \"c67f3f55c5fd49d080e19a2ea9666e77\",\n \"voice_id\": \"e515d746526f448fa533afddc97e4933\",\n \"background_video_url\": \"https://database.blotato.io/storage/v1/object/public/public_media/4ddd33eb-e811-4ab5-93e1-2cd0b7e8fb3f/videogen2-render-e6b398a2-5859-4a77-88ef-2345bcefdc98.mp4\"\n}\n",
458
- "options": {}
459
- },
460
- "type": "n8n-nodes-base.set",
461
- "typeVersion": 3.4,
462
- "position": [
463
- 1120,
464
- 960
465
- ],
466
- "id": "dd76714f-100c-4bb0-bff3-a62243c67319",
467
- "name": "Setup Heygen"
468
- },
469
- {
470
- "parameters": {
471
- "url": "https://api.heygen.com/v1/video_status.get",
472
- "sendQuery": true,
473
- "queryParameters": {
474
- "parameters": [
475
- {
476
- "name": "video_id",
477
- "value": "={{ $('Create Avatar Video').item.json.data.video_id }}"
478
- }
479
- ]
480
- },
481
- "sendHeaders": true,
482
- "headerParameters": {
483
- "parameters": [
484
- {
485
- "name": "X-Api-Key",
486
- "value": "={{ $('Setup Heygen').item.json.heygen_api_key }}"
487
- }
488
- ]
489
- },
490
- "options": {}
491
- },
492
- "type": "n8n-nodes-base.httpRequest",
493
- "typeVersion": 4.2,
494
- "position": [
495
- 1680,
496
- 960
497
- ],
498
- "id": "784c548f-6033-43b6-8e07-762561961b1c",
499
- "name": "Get Avatar Video"
500
- },
501
- {
502
- "parameters": {
503
- "content": "# Research Daily News and Write Script",
504
- "height": 2100,
505
- "width": 940,
506
- "color": 2
507
- },
508
- "type": "n8n-nodes-base.stickyNote",
509
- "typeVersion": 1,
510
- "position": [
511
- 0,
512
- 0
513
- ],
514
- "id": "aaff2eb3-2507-4748-9e76-c0531f1f5396",
515
- "name": "Sticky Note"
516
- },
517
- {
518
- "parameters": {
519
- "content": "# Create AI Avatar Video\n\n- Heygen API plan (paid) is required; the free plan is insufficient.\n- if you have a long script, you may need to increase the WAIT time.\n- you can use Elevenlabs voice by integrating Elevenlabs from within Heygen app.",
520
- "height": 2100,
521
- "width": 800,
522
- "color": 3
523
- },
524
- "type": "n8n-nodes-base.stickyNote",
525
- "typeVersion": 1,
526
- "position": [
527
- 1060,
528
- 0
529
- ],
530
- "id": "eebb5349-8ce0-404d-8f78-ccbf40773f7a",
531
- "name": "Sticky Note1"
532
- },
533
- {
534
- "parameters": {
535
- "content": "# Publish to Social Media\n\n- Sign up for Blotato: https://www.blotato.com\n- Blotato's API currently doesn't support uploading videos to Bluesky or Pinterest. \n- This feature will be released in the future, so I've deactivated the nodes for now.",
536
- "height": 2100,
537
- "width": 1120,
538
- "color": 4
539
- },
540
- "type": "n8n-nodes-base.stickyNote",
541
- "typeVersion": 1,
542
- "position": [
543
- 1980,
544
- 0
545
- ],
546
- "id": "eaf2e2d7-b8af-4030-85ac-f424f418ac29",
547
- "name": "Sticky Note2"
548
- },
549
- {
550
- "parameters": {
551
- "mode": "raw",
552
- "jsonOutput": "={\n \"blotato_api_key\": \"blt_a4X6NhON82hC1BjW6M3TnIwizVQPfHXnzxlG5HF8lws=\",\n \"instagram_id\": \"\",\n \"youtube_id\": \"5174\",\n \"tiktok_id\": \"\",\n \"facebook_id\": \"\",\n \"facebook_page_id\": \"\",\n \"threads_id\": \"\",\n \"twitter_id\": \"\",\n \"linkedin_id\": \"\",\n \"pinterest_id\": \"\",\n \"pinterest_board_id\": \"\",\n \"bluesky_id\": \"\",\n \"final_text_long\": {{ $('Write Long Caption').item.json.message.content.toJsonString() }},\n \"final_text_short\": {{ $('Write Short Caption').item.json.message.content.toJsonString() }}\n}",
553
- "options": {}
554
- },
555
- "type": "n8n-nodes-base.set",
556
- "typeVersion": 3.4,
557
- "position": [
558
- 2040,
559
- 960
560
- ],
561
- "id": "8f1894f0-825a-4bda-9165-87d4d6cc5636",
562
- "name": "Prepare for Publish"
563
- },
564
- {
565
- "parameters": {
566
- "modelId": {
567
- "__rl": true,
568
- "value": "gpt-4o",
569
- "mode": "list",
570
- "cachedResultName": "GPT-4O"
571
- },
572
- "messages": {
573
- "values": [
574
- {
575
- "content": "=# EXAMPLE\n\n<example>\nMany people have recently asked me about ask engine optimization, which is all about optimizing your website and existing content, so it can be pulled into ChatGPT and other generative AI tools. Consider that generative AI tools tend to be more conversational in nature and have a Q&A type format, so search engines will want to pull in snippets that concisely answer a user’s question.- what is ask engine optimization in the age of AI?- How does traditional SEO compare to ask engine optimization today?- top tips and tricks to get started with ask engine optimization?\n\n#ai #askengineoptimization #chatgpts #seo #aitools #digitalmarketing\n</example>\n\n# CONTEXT\n\nInfer the topic from the sources provided.\n\n# WRITING STYLE\n\nHere’s how you always write:\n\n<writing_style>\n\n- Your writing style is spartan and informative.\n- Use clear, simple language.\n- Employ short, impactful sentences.\n- Use active voice; avoid passive voice.\n- Focus on practical, actionable insights.\n- Incorporate data or statistics to support claims when possible.\n- Use \"\"\"\"\"\"\"\"you\"\"\"\"\"\"\"\" and \"\"\"\"\"\"\"\"your\"\"\"\"\"\"\"\" to directly address the reader.\n- Avoid metaphors and clichés.\n- Avoid generalizations.\n- Do not include common setup language in any sentence, including: in conclusion, in closing, etc.\n- Do not output warnings or notes—just the output requested.\n- Do not use hashtags.\n- Do not use semicolons.\n- Do not use emojis.\n- Do not use asterisks.\n- Do not use adjectives and adverbs.\n- Do NOT use these words:\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"can, may, just, that, very, really, literally, actually, certainly, probably, basically, could, maybe, delve, embark, enlightening, esteemed, shed light, craft, crafting, imagine, realm, game-changer, unlock, discover, skyrocket, abyss, you're not alone, in a world where, revolutionize, disruptive, utilize, utilizing, dive deep, tapestry, illuminate, unveil, pivotal, enrich, intricate, elucidate, hence, furthermore, realm, however, harness, exciting, groundbreaking, cutting-edge, remarkable, it. remains to be seen, glimpse into, navigating, landscape, stark, testament, in summary, in conclusion, moreover, boost, bustling, opened up, powerful, inquiries, ever-evolving\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n</writing_style>\n\n# PLANNING\n\nYour goal is to write a 50-word video caption based on the provided source.\n\n1. Analyze the provided sources thoroughly.\n2. Study the <example> post carefully. You will be asked to replicate their:\n - Overall structure.\n - Tone and voice.\n - Formatting (including line breaks and spacing).\n - Length (aim for a similarly detailed post).\n - Absence of emojis.\n - Use of hashtags.\n - Emotional resonance.\n\n# OUTPUT\nFollow the GUIDELINES below to write the post. Use your analysis from step 1 and step 2. Use the provided sources as the foundation for your post, expanding on it significantly while maintaining the style and structure of the examples provided from step 2. You MUST use information from the provided sources. Make sure you adhere to your <writing_style>.\n\n<guidelines>\nThe description should be structured as follows:\n1. Start with 1 paragraph summarizing the source\n2. Newline, followed by 3 bullet points of questions that a viewer might ask on a search engine about the source\n3. Newline, followed by these hashtags: #ai #artificialintelligence #ainews #sabrinaramonov #aiavatar\n</guidelines>\n\nTake a deep breath and take it step-by-step!\n\n# INPUT\nUse the following information sources:\n<sources>\n{{ $json.output }}\n</sources>"
576
- }
577
- ]
578
- },
579
- "options": {}
580
- },
581
- "type": "@n8n/n8n-nodes-langchain.openAi",
582
- "typeVersion": 1.8,
583
- "position": [
584
- 600,
585
- 840
586
- ],
587
- "id": "e305e9c2-3cbe-42d3-bb61-9d4ce875aa5d",
588
- "name": "Write Long Caption",
589
- "credentials": {
590
- "openAiApi": {
591
- "id": "F9KdoKWLuehFNuFM",
592
- "name": "OpenAi account (1)"
593
- }
594
- }
595
- },
596
- {
597
- "parameters": {
598
- "modelId": {
599
- "__rl": true,
600
- "value": "gpt-4o",
601
- "mode": "list",
602
- "cachedResultName": "GPT-4O"
603
- },
604
- "messages": {
605
- "values": [
606
- {
607
- "content": "=Write a spartan 2-sentence caption summarizing the video content, use 6th grade language, balanced neutral perspective, no emojis:\n\n<content>\n{{ $json.message.content }}\n</content>"
608
- }
609
- ]
610
- },
611
- "options": {}
612
- },
613
- "type": "@n8n/n8n-nodes-langchain.openAi",
614
- "typeVersion": 1.8,
615
- "position": [
616
- 600,
617
- 1080
618
- ],
619
- "id": "d58aea0c-6a2a-410e-9efb-7cf7ba63b884",
620
- "name": "Write Short Caption",
621
- "credentials": {
622
- "openAiApi": {
623
- "id": "F9KdoKWLuehFNuFM",
624
- "name": "OpenAi account (1)"
625
- }
626
- }
627
- },
628
- {
629
- "parameters": {
630
- "method": "POST",
631
- "url": "https://api.heygen.com/v2/video/generate",
632
- "sendHeaders": true,
633
- "headerParameters": {
634
- "parameters": [
635
- {
636
- "name": "X-Api-Key",
637
- "value": "={{ $json.heygen_api_key }}"
638
- }
639
- ]
640
- },
641
- "sendBody": true,
642
- "specifyBody": "json",
643
- "jsonBody": "={\n \"video_inputs\": [\n {\n \"character\": {\n \"type\": \"avatar\",\n \"avatar_id\": \"{{ $json.avatar_id }}\",\n \"avatar_style\": \"normal\",\n \"scale\": 1.0,\n \"offset\": {\n \"x\": 0.0,\n \"y\": 0.0\n },\n \"matting\": true\n },\n \"voice\": {\n \"type\": \"text\",\n \"input_text\": \"{{ $('AI Agent').item.json.output }}\",\n \"voice_id\": \"{{ $json.voice_id }}\",\n \"speed\": 1.1,\n \"pitch\": 50,\n \"emotion\": \"Excited\"\n },\n \"background\": {\n \"type\": \"video\",\n \"url\": \"{{ $json.background_video_url }}\",\n \"play_style\": \"loop\",\n \"fit\": \"cover\"\n }\n }\n ],\n \"dimension\": {\n \"width\": 720,\n \"height\": 1280\n },\n \"aspect_ratio\": \"9:16\",\n \"caption\": false,\n \"title\": \"n8n TEST AVATAR\"\n}",
644
- "options": {}
645
- },
646
- "type": "n8n-nodes-base.httpRequest",
647
- "typeVersion": 4.2,
648
- "position": [
649
- 1280,
650
- 960
651
- ],
652
- "id": "eb1af192-6893-4c6b-b9cf-619487264a15",
653
- "name": "Create Avatar Video",
654
- "retryOnFail": false,
655
- "executeOnce": false,
656
- "alwaysOutputData": false
657
- },
658
- {
659
- "parameters": {
660
- "content": "## Make sure you fill out \"Setup Heygen\"",
661
- "height": 180,
662
- "width": 150,
663
- "color": 6
664
- },
665
- "type": "n8n-nodes-base.stickyNote",
666
- "typeVersion": 1,
667
- "position": [
668
- 1100,
669
- 1140
670
- ],
671
- "id": "889115b7-bd33-4625-836e-e3c3c3c6c2c1",
672
- "name": "Sticky Note3"
673
- },
674
- {
675
- "parameters": {
676
- "content": "## Make sure you fill out \"Prepare for Publish\"",
677
- "height": 180,
678
- "width": 160,
679
- "color": 6
680
- },
681
- "type": "n8n-nodes-base.stickyNote",
682
- "typeVersion": 1,
683
- "position": [
684
- 2020,
685
- 1140
686
- ],
687
- "id": "d8cedc2c-2637-40d9-a6f6-17a00b278927",
688
- "name": "Sticky Note4"
689
- }
690
- ],
691
- "pinData": {},
692
- "connections": {
693
- "Upload to Blotato": {
694
- "main": [
695
- [
696
- {
697
- "node": "[Instagram] Publish via Blotato",
698
- "type": "main",
699
- "index": 0
700
- },
701
- {
702
- "node": "[Facebook] Publish via Blotato",
703
- "type": "main",
704
- "index": 0
705
- },
706
- {
707
- "node": "[Linkedin] Publish via Blotato",
708
- "type": "main",
709
- "index": 0
710
- },
711
- {
712
- "node": "[Tiktok] Publish via Blotato",
713
- "type": "main",
714
- "index": 0
715
- },
716
- {
717
- "node": "OpenAI",
718
- "type": "main",
719
- "index": 0
720
- },
721
- {
722
- "node": "[Youtube] Publish via Blotato",
723
- "type": "main",
724
- "index": 0
725
- },
726
- {
727
- "node": "[Threads] Publish via Blotato",
728
- "type": "main",
729
- "index": 0
730
- },
731
- {
732
- "node": "[Twitter] Publish via Blotato",
733
- "type": "main",
734
- "index": 0
735
- },
736
- {
737
- "node": "[Bluesky] Publish via Blotato",
738
- "type": "main",
739
- "index": 0
740
- }
741
- ]
742
- ]
743
- },
744
- "OpenAI": {
745
- "main": [
746
- [
747
- {
748
- "node": "Upload to Blotato - Image",
749
- "type": "main",
750
- "index": 0
751
- }
752
- ]
753
- ]
754
- },
755
- "Upload to Blotato - Image": {
756
- "main": [
757
- [
758
- {
759
- "node": "[Pinterest] Publish via Blotato",
760
- "type": "main",
761
- "index": 0
762
- }
763
- ]
764
- ]
765
- },
766
- "Schedule Trigger": {
767
- "main": [
768
- [
769
- {
770
- "node": "AI Agent",
771
- "type": "main",
772
- "index": 0
773
- }
774
- ]
775
- ]
776
- },
777
- "AI Agent": {
778
- "main": [
779
- [
780
- {
781
- "node": "Write Long Caption",
782
- "type": "main",
783
- "index": 0
784
- }
785
- ]
786
- ]
787
- },
788
- "Fetch HN Article": {
789
- "ai_tool": [
790
- [
791
- {
792
- "node": "AI Agent",
793
- "type": "ai_tool",
794
- "index": 0
795
- }
796
- ]
797
- ]
798
- },
799
- "Fetch HN Front Page": {
800
- "ai_tool": [
801
- [
802
- {
803
- "node": "AI Agent",
804
- "type": "ai_tool",
805
- "index": 0
806
- }
807
- ]
808
- ]
809
- },
810
- "Write Script": {
811
- "ai_languageModel": [
812
- [
813
- {
814
- "node": "AI Agent",
815
- "type": "ai_languageModel",
816
- "index": 0
817
- }
818
- ]
819
- ]
820
- },
821
- "Setup Heygen": {
822
- "main": [
823
- [
824
- {
825
- "node": "Create Avatar Video",
826
- "type": "main",
827
- "index": 0
828
- }
829
- ]
830
- ]
831
- },
832
- "Wait": {
833
- "main": [
834
- [
835
- {
836
- "node": "Get Avatar Video",
837
- "type": "main",
838
- "index": 0
839
- }
840
- ]
841
- ]
842
- },
843
- "Get Avatar Video": {
844
- "main": [
845
- [
846
- {
847
- "node": "Prepare for Publish",
848
- "type": "main",
849
- "index": 0
850
- }
851
- ]
852
- ]
853
- },
854
- "Prepare for Publish": {
855
- "main": [
856
- [
857
- {
858
- "node": "Upload to Blotato",
859
- "type": "main",
860
- "index": 0
861
- }
862
- ]
863
- ]
864
- },
865
- "Write Long Caption": {
866
- "main": [
867
- [
868
- {
869
- "node": "Write Short Caption",
870
- "type": "main",
871
- "index": 0
872
- }
873
- ]
874
- ]
875
- },
876
- "Write Short Caption": {
877
- "main": [
878
- [
879
- {
880
- "node": "Setup Heygen",
881
- "type": "main",
882
- "index": 0
883
- }
884
- ]
885
- ]
886
- },
887
- "Create Avatar Video": {
888
- "main": [
889
- [
890
- {
891
- "node": "Wait",
892
- "type": "main",
893
- "index": 0
894
- }
895
- ]
896
- ]
897
- }
898
- },
899
- "active": false,
900
- "settings": {
901
- "executionOrder": "v1"
902
- },
903
- "versionId": "bdf003ba-cc90-4cdb-8ae8-d946966fb050",
904
- "meta": {
905
- "instanceId": "4524b680f47c2cca4320dc7db8ea4881b7a84dc24b2f6183ec019ee71e07144b"
906
- },
907
- "id": "CHYuRjzU7QJyE564",
908
- "tags": []
909
- }'''
910
- data=json.loads(Workflow)
 
1
+ import gradio as gr
2
+ import os
3
+ from workflow_logic import run_daily_ai_video_workflow
4
 
5
+ def run_workflow_and_display_results():
6
+ """
7
+ Function to run the workflow and return results for Gradio.
8
+ """
9
+ output_messages = []
10
+ output_messages.append("Initiating workflow... This may take several minutes (due to Heygen video processing and a hardcoded 8-minute wait).")
11
+
12
+ try:
13
+ workflow_output = run_daily_ai_video_workflow()
14
+
15
+ if workflow_output['status'] == "success":
16
+ output_messages.append("🎉 Workflow Completed Successfully!")
17
+ output_messages.append("Summary of Results:")
18
+ output_messages.append(f"```json\n{json.dumps(workflow_output['results'], indent=2)}\n```") # Format JSON nicely
19
+ if workflow_output['results'].get('heygen_video_url'):
20
+ output_messages.append(f"Heygen Video URL: {workflow_output['results']['heygen_video_url']}")
21
+ # Gradio needs the URL directly for gr.Video
22
+ return "\n".join(output_messages), workflow_output['results'].get('heygen_video_url')
23
+ else:
24
+ output_messages.append(f"Workflow Failed: {workflow_output['message']}")
25
+ if workflow_output.get('results'):
26
+ output_messages.append("Partial Results:")
27
+ output_messages.append(f"```json\n{json.dumps(workflow_output['results'], indent=2)}\n```")
28
+ return "\n".join(output_messages), None
29
+ except Exception as e:
30
+ output_messages.append(f"An unexpected error occurred during workflow execution: {str(e)}")
31
+ return "\n".join(output_messages), None
32
+
33
+
34
+ # Gradio Interface
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown(
37
+ """
38
+ # Automated AI Video & Social Media Publisher
39
+ This app runs a workflow to generate AI avatar videos based on trending AI news from Hacker News and publishes them to social media platforms via Blotato.
40
+ """
41
+ )
42
+
43
+ gr.Markdown(
44
+ """
45
+ **Before running:**
46
+ Please ensure you have set the following API keys as **Space Secrets** in your Hugging Face Space settings:
47
+ * `OPENAI_API_KEY`
48
+ * `HEYGEN_API_KEY`
49
+ * `BLOTATO_API_KEY`
50
+
51
+ You can also set various `HEYGEN_` and `BLOTATO_` specific IDs as environment variables if needed.
52
+ """
53
+ )
54
+
55
+ run_button = gr.Button("🚀 Run Workflow Now")
56
+ output_text = gr.Textbox(label="Workflow Output", lines=20, interactive=False)
57
+ video_output = gr.Video(label="Generated Video Preview", interactive=False)
58
+
59
+ run_button.click(
60
+ fn=run_workflow_and_display_results,
61
+ inputs=[],
62
+ outputs=[output_text, video_output]
63
+ )
64
+
65
+ # Launch the Gradio app
66
+ demo.launch()