File size: 15,105 Bytes
edae06c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
{
    "name": "Antigravity Image Research Extractor",
    "nodes": [
        {
            "parameters": {
                "path": "C:/Users/Nauti/Desktop/LOGOS CURSOR/LOGOS Notes",
                "fileExtensions": "jpg,jpeg,png,pdf,heic",
                "options": {
                    "recurse": true
                }
            },
            "id": "image_scanner",
            "name": "Scan Images (Notes)",
            "type": "n8n-nodes-base.readFilesFromFolder",
            "position": [
                250,
                300
            ]
        },
        {
            "parameters": {
                "jsCode": "// ROUTER: Classify images for specialized analysis\nconst images = items.map(item => {\n  const fileName = item.json.fileName;\n  const fileSize = item.json.size || 0;\n  \n  let taskType = 'general_vision';\n  let priority = 1;\n  \n  // Route by filename patterns and size\n  if (fileName.includes('diagram') || fileName.includes('sketch')) {\n    taskType = 'diagram_analysis';\n    priority = 3;\n  } else if (fileName.includes('note') || fileName.includes('handwritten')) {\n    taskType = 'handwriting_ocr';\n    priority = 2;\n  } else if (fileName.includes('ui') || fileName.includes('interface')) {\n    taskType = 'ui_analysis';\n    priority = 3;\n  } else if (fileSize < 500000) {\n    taskType = 'handwriting_ocr'; // Smaller files likely notes\n    priority = 2;\n  } else {\n    taskType = 'diagram_analysis'; // Larger files likely detailed diagrams\n    priority = 3;\n  }\n  \n  return {\n    json: {\n      fileName,\n      taskType,\n      priority,\n      fullPath: item.json.directory + '/' + fileName,\n      fileSize\n    },\n    binary: item.binary\n  };\n});\n\nreturn images;"
            },
            "id": "router",
            "name": "Neural Router",
            "type": "n8n-nodes-base.code",
            "position": [
                450,
                300
            ]
        },
        {
            "parameters": {
                "conditions": {
                    "options": {
                        "caseSensitive": false
                    },
                    "conditions": [
                        {
                            "id": "handwriting_path",
                            "leftValue": "={{ $json.taskType }}",
                            "rightValue": "handwriting_ocr",
                            "operator": {
                                "type": "string",
                                "operation": "equals"
                            }
                        },
                        {
                            "id": "diagram_path",
                            "leftValue": "={{ $json.taskType }}",
                            "rightValue": "diagram_analysis",
                            "operator": {
                                "type": "string",
                                "operation": "equals"
                            }
                        },
                        {
                            "id": "ui_path",
                            "leftValue": "={{ $json.taskType }}",
                            "rightValue": "ui_analysis",
                            "operator": {
                                "type": "string",
                                "operation": "equals"
                            }
                        }
                    ]
                },
                "options": {}
            },
            "id": "switch",
            "name": "Task Switch",
            "type": "n8n-nodes-base.switch",
            "position": [
                650,
                300
            ]
        },
        {
            "parameters": {
                "method": "POST",
                "url": "https://api-inference.huggingface.co/models/microsoft/trocr-base-handwritten",
                "authentication": "genericCredentialType",
                "genericAuthType": "httpHeaderAuth",
                "sendHeaders": true,
                "headerParameters": {
                    "parameters": [
                        {
                            "name": "Content-Type",
                            "value": "application/json"
                        }
                    ]
                },
                "sendBody": true,
                "specifyBody": "json",
                "jsonBody": "={\n  \"inputs\": \"{{ $binary.data.toString('base64') }}\"\n}",
                "options": {}
            },
            "id": "ocr_analyst",
            "name": "OCR Handwriting (TrOCR)",
            "type": "n8n-nodes-base.httpRequest",
            "position": [
                850,
                200
            ]
        },
        {
            "parameters": {
                "method": "POST",
                "url": "http://localhost:1234/v1/chat/completions",
                "authentication": "none",
                "sendHeaders": true,
                "headerParameters": {
                    "parameters": [
                        {
                            "name": "Content-Type",
                            "value": "application/json"
                        }
                    ]
                },
                "sendBody": true,
                "specifyBody": "json",
                "jsonBody": "={\n  \"model\": \"llava-v1.6-mistral-7b\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are a technical diagram analyst specializing in geometry, polyforms, and compression systems. Identify: 1) Mathematical concepts shown, 2) Geometric shapes/polyhedra types, 3) Compression techniques mentioned, 4) UI/workflow elements. Output structured JSON.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"Analyze this diagram from {{ $json.fileName }}. Focus on polyform development, compression methods, and UI design.\"\n        },\n        {\n          \"type\": \"image_url\",\n          \"image_url\": {\n            \"url\": \"data:image/jpeg;base64,{{ $binary.data.toString('base64') }}\"\n          }\n        }\n      ]\n    }\n  ],\n  \"temperature\": 0.2,\n  \"max_tokens\": 1500\n}",
                "options": {}
            },
            "id": "diagram_analyst",
            "name": "Diagram Analyst (LLaVA)",
            "type": "n8n-nodes-base.httpRequest",
            "position": [
                850,
                300
            ]
        },
        {
            "parameters": {
                "method": "POST",
                "url": "http://localhost:1234/v1/chat/completions",
                "authentication": "none",
                "sendHeaders": true,
                "headerParameters": {
                    "parameters": [
                        {
                            "name": "Content-Type",
                            "value": "application/json"
                        }
                    ]
                },
                "sendBody": true,
                "specifyBody": "json",
                "jsonBody": "={\n  \"model\": \"llava-v1.6-mistral-7b\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are a UI/UX analyst. Extract: 1) Interface components shown, 2) Interaction patterns, 3) Data visualization methods, 4) Success indicators mentioned, 5) User workflow steps. Output structured JSON.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"Analyze UI design from {{ $json.fileName }}. Identify successful patterns for polyform visualization and user interaction.\"\n        },\n        {\n          \"type\": \"image_url\",\n          \"image_url\": {\n            \"url\": \"data:image/jpeg;base64,{{ $binary.data.toString('base64') }}\"\n          }\n        }\n      ]\n    }\n  ],\n  \"temperature\": 0.3,\n  \"max_tokens\": 1200\n}",
                "options": {}
            },
            "id": "ui_analyst",
            "name": "UI Analyst (LLaVA)",
            "type": "n8n-nodes-base.httpRequest",
            "position": [
                850,
                400
            ]
        },
        {
            "parameters": {
                "mode": "mergeByPosition",
                "options": {}
            },
            "id": "merge",
            "name": "Merge Analysis",
            "type": "n8n-nodes-base.merge",
            "position": [
                1050,
                300
            ]
        },
        {
            "parameters": {
                "jsCode": "// SYNTHESIS: Parse vision model responses and structure results\nconst results = items.map(item => {\n  let analysis = {};\n  \n  try {\n    // Handle TrOCR response (array format)\n    if (Array.isArray(item.json)) {\n      analysis = {\n        extracted_text: item.json[0]?.generated_text || item.json.toString(),\n        confidence: item.json[0]?.score || 0.8\n      };\n    }\n    // Handle LLaVA response (OpenAI format)\n    else if (item.json.choices) {\n      const content = item.json.choices[0]?.message?.content || '{}';\n      analysis = JSON.parse(content);\n    }\n    // Handle direct JSON response\n    else if (typeof item.json === 'object') {\n      analysis = item.json;\n    }\n    else {\n      analysis = { raw_response: JSON.stringify(item.json) };\n    }\n  } catch (e) {\n    analysis = {\n      raw_response: JSON.stringify(item.json),\n      parse_error: true,\n      error_detail: e.message\n    };\n  }\n  \n  return {\n    json: {\n      file: item.json.fileName || 'unknown',\n      taskType: item.json.taskType,\n      analysis,\n      timestamp: new Date().toISOString()\n    }\n  };\n});\n\nreturn results;"
            },
            "id": "synthesizer",
            "name": "Synthesizer",
            "type": "n8n-nodes-base.code",
            "position": [
                1250,
                300
            ]
        },
        {
            "parameters": {
                "method": "POST",
                "url": "http://localhost:1234/v1/chat/completions",
                "authentication": "none",
                "sendHeaders": true,
                "headerParameters": {
                    "parameters": [
                        {
                            "name": "Content-Type",
                            "value": "application/json"
                        }
                    ]
                },
                "sendBody": true,
                "specifyBody": "json",
                "jsonBody": "={\n  \"model\": \"nvidia/nemotron-3-nano\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are the RESEARCH SYNTHESIZER for a polyform compression project. Analyze handwritten notes and diagrams to extract: 1) POLYFORM TYPES (Platonic, Archimedean, Johnson, near-miss solids, geodesics), 2) COMPRESSION METHODS (vertex encoding, edge compression, spheroid nets), 3) SUCCESSFUL UI PATTERNS from iterations, 4) MATHEMATICAL INSIGHTS (topology, manifolds, optimization), 5) CRITICAL GAPS to address. Output: Executive Summary, Key Findings by Category, Priority Next Steps, Integration Opportunities.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Synthesize these image analyses from research notes:\\n\\n{{ JSON.stringify($json) }}\\n\\nFocus on actionable insights for building the polyform generator and compression library.\"\n    }\n  ],\n  \"temperature\": 0.3,\n  \"max_tokens\": 3000\n}",
                "options": {}
            },
            "id": "jury",
            "name": "Jury Consensus (Nemotron)",
            "type": "n8n-nodes-base.httpRequest",
            "position": [
                1450,
                300
            ]
        },
        {
            "parameters": {
                "operation": "write",
                "fileName": "=/tmp/polyform_research_{{ DateTime.now().toFormat('yyyyMMdd_HHmmss') }}.json",
                "options": {}
            },
            "id": "save_results",
            "name": "Save Research Synthesis",
            "type": "n8n-nodes-base.writeFile",
            "position": [
                1650,
                300
            ]
        }
    ],
    "connections": {
        "image_scanner": {
            "main": [
                [
                    {
                        "node": "router",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "router": {
            "main": [
                [
                    {
                        "node": "switch",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "switch": {
            "main": [
                [
                    {
                        "node": "ocr_analyst",
                        "type": "main",
                        "index": 0
                    }
                ],
                [
                    {
                        "node": "diagram_analyst",
                        "type": "main",
                        "index": 0
                    }
                ],
                [
                    {
                        "node": "ui_analyst",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "ocr_analyst": {
            "main": [
                [
                    {
                        "node": "merge",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "diagram_analyst": {
            "main": [
                [
                    {
                        "node": "merge",
                        "type": "main",
                        "index": 1
                    }
                ]
            ]
        },
        "ui_analyst": {
            "main": [
                [
                    {
                        "node": "merge",
                        "type": "main",
                        "index": 2
                    }
                ]
            ]
        },
        "merge": {
            "main": [
                [
                    {
                        "node": "synthesizer",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "synthesizer": {
            "main": [
                [
                    {
                        "node": "jury",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "jury": {
            "main": [
                [
                    {
                        "node": "save_results",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    },
    "settings": {
        "executionOrder": "v1"
    }
}