Skip to content

Image Pipeline Playground

feat(frontend/header): add Example button for blur-canny pipeline

Mohammad Rajaeic33d6e2e450b
diff --git a/frontend/public/examples/blur_canny.json b/frontend/public/examples/blur_canny.json
new file mode 100644
index 0000000..94d9842
--- /dev/null
+++ b/frontend/public/examples/blur_canny.json
@@ -0,0 +1,45 @@
+{
+ "version": 1,
+ "name": "blur-and-canny",
+ "description": "Load Lena, blur it, then extract Canny edges.",
+ "seed": 0,
+ "sampleCount": 1,
+ "graph": {
+ "nodes": [
+ {
+ "id": "load-1",
+ "type": "load_image",
+ "params": { "path": "examples/lena.png" },
+ "position": { "x": 0, "y": 0 }
+ },
+ {
+ "id": "blur-1",
+ "type": "gaussian_blur",
+ "params": { "ksize": 5, "sigma": 0 },
+ "position": { "x": 220, "y": 0 }
+ },
+ {
+ "id": "canny-1",
+ "type": "canny",
+ "params": { "threshold1": 80, "threshold2": 160 },
+ "position": { "x": 440, "y": 0 }
+ }
+ ],
+ "edges": [
+ {
+ "id": "e1",
+ "source": "load-1",
+ "source_port": "image",
+ "target": "blur-1",
+ "target_port": "image"
+ },
+ {
+ "id": "e2",
+ "source": "blur-1",
+ "source_port": "image",
+ "target": "canny-1",
+ "target_port": "image"
+ }
+ ]
+ }
+}
diff --git a/frontend/src/app/App.tsx b/frontend/src/app/App.tsx
index 24fc06a..aa2d492 100644
--- a/frontend/src/app/App.tsx
+++ b/frontend/src/app/App.tsx
@@ -37,6 +37,16 @@ export default function App() {
}
}
+ const applyLoadedWorkflow = (text: string, successMessage: string) => {
+ const doc = parseWorkflowJson(text)
+ const { skippedTypes } = loadWorkflow(doc)
+ if (skippedTypes.length > 0) {
+ notifyInfo(`${successMessage} (skipped unknown nodes: ${skippedTypes.join(', ')})`)
+ } else {
+ notifySuccess(successMessage)
+ }
+ }
+
const onLoadWorkflowClick = () => {
if (nodeCatalog.length === 0) {
notifyError('Node catalog is still loading — try again in a moment')
@@ -50,13 +60,7 @@ export default function App() {
if (!file) return
try {
const text = await file.text()
- const doc = parseWorkflowJson(text)
- const { skippedTypes } = loadWorkflow(doc)
- if (skippedTypes.length > 0) {
- notifyInfo(`Workflow loaded (skipped unknown nodes: ${skippedTypes.join(', ')})`)
- } else {
- notifySuccess('Workflow loaded')
- }
+ applyLoadedWorkflow(text, 'Workflow loaded')
} catch (error) {
notifyError(error instanceof Error ? error.message : 'Load failed')
} finally {
@@ -64,6 +68,23 @@ export default function App() {
}
}
+ const onLoadExample = async () => {
+ if (nodeCatalog.length === 0) {
+ notifyError('Node catalog is still loading — try again in a moment')
+ return
+ }
+ try {
+ const response = await fetch('/examples/blur_canny.json')
+ if (!response.ok) {
+ throw new Error(`Could not fetch example (${response.status})`)
+ }
+ const text = await response.text()
+ applyLoadedWorkflow(text, 'Example workflow loaded')
+ } catch (error) {
+ notifyError(error instanceof Error ? error.message : 'Example load failed')
+ }
+ }
+
return (
<Box sx={{ display: 'flex', flexDirection: 'column', height: '100vh', bgcolor: '#0f0f0f' }}>
<input
@@ -79,6 +100,7 @@ export default function App() {
onExportPython={() => void onExportPython()}
onExportWorkflow={onExportWorkflow}
onLoadWorkflow={onLoadWorkflowClick}
+ onLoadExample={() => void onLoadExample()}
/>
<Box
diff --git a/frontend/src/app/AppHeader.tsx b/frontend/src/app/AppHeader.tsx
index 0327327..7260006 100644
--- a/frontend/src/app/AppHeader.tsx
+++ b/frontend/src/app/AppHeader.tsx
@@ -128,6 +128,7 @@ interface AppHeaderProps {
onExportPython: () => void
onExportWorkflow: () => void
onLoadWorkflow: () => void
+ onLoadExample: () => void
}
const outlineBtnSx = {
@@ -154,6 +155,7 @@ export function AppHeader({
onExportPython,
onExportWorkflow,
onLoadWorkflow,
+ onLoadExample,
}: AppHeaderProps) {
const seed = useGraphStore((s) => s.seed)
const sampleCount = useGraphStore((s) => s.sampleCount)
@@ -366,6 +368,15 @@ export function AppHeader({
</Box>
</Button>
+ <Button
+ variant="outlined"
+ disabled={isExecuting}
+ onClick={onLoadExample}
+ sx={outlineBtnSx}
+ >
+ Example
+ </Button>
+
<Button
variant="outlined"
disabled={isExecuting}