Spaces:
Running
Running
Another node type that marks an area.
Browse files- server/ops.py +6 -0
- server/pytorch_model_ops.py +10 -4
- web/src/LynxKiteFlow.svelte +2 -0
- web/src/LynxKiteNode.svelte +1 -1
- web/src/NodeParameter.svelte +41 -0
- web/src/NodeWithArea.svelte +67 -0
- web/src/NodeWithParams.svelte +7 -33
- web/src/NodeWithParamsVertical.svelte +11 -10
- web/src/NodeWithSubFlow.svelte +0 -1
server/ops.py
CHANGED
@@ -171,3 +171,9 @@ def register_passive_op(name, inputs={'input': Bundle}, outputs={'output': Bundl
|
|
171 |
'''A passive operation has no associated code.'''
|
172 |
op = Op(no_op, name, params={p.name: p for p in params}, inputs=inputs, outputs=outputs, type='basic')
|
173 |
ALL_OPS[name] = op
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
'''A passive operation has no associated code.'''
|
172 |
op = Op(no_op, name, params={p.name: p for p in params}, inputs=inputs, outputs=outputs, type='basic')
|
173 |
ALL_OPS[name] = op
|
174 |
+
return op
|
175 |
+
|
176 |
+
def register_area(name, params=[]):
|
177 |
+
'''A node that represents an area. It can contain other nodes, but does not restrict movement in any way.'''
|
178 |
+
op = register_passive_op(name, params=params, inputs={}, outputs={})
|
179 |
+
op.type = 'area'
|
server/pytorch_model_ops.py
CHANGED
@@ -32,11 +32,11 @@ def register_layer(name):
|
|
32 |
return decorator
|
33 |
|
34 |
@register_layer('LayerNorm')
|
35 |
-
def layernorm():
|
36 |
return 'LayerNorm'
|
37 |
|
38 |
@register_layer('Dropout')
|
39 |
-
def dropout(*, p=0.5):
|
40 |
return f'Dropout ({p})'
|
41 |
|
42 |
@register_layer('Linear')
|
@@ -50,7 +50,7 @@ class GraphConv(Enum):
|
|
50 |
SAGEConv = 'SAGEConv'
|
51 |
|
52 |
@register_layer('Graph Convolution')
|
53 |
-
def graph_convolution(*, type: GraphConv):
|
54 |
return 'GraphConv'
|
55 |
|
56 |
class Nonlinearity(Enum):
|
@@ -59,6 +59,12 @@ class Nonlinearity(Enum):
|
|
59 |
Tanh = 'Tanh'
|
60 |
|
61 |
@register_layer('Nonlinearity')
|
62 |
-
def nonlinearity(*, type: Nonlinearity):
|
63 |
return 'ReLU'
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
return decorator
|
33 |
|
34 |
@register_layer('LayerNorm')
|
35 |
+
def layernorm(x):
|
36 |
return 'LayerNorm'
|
37 |
|
38 |
@register_layer('Dropout')
|
39 |
+
def dropout(x, *, p=0.5):
|
40 |
return f'Dropout ({p})'
|
41 |
|
42 |
@register_layer('Linear')
|
|
|
50 |
SAGEConv = 'SAGEConv'
|
51 |
|
52 |
@register_layer('Graph Convolution')
|
53 |
+
def graph_convolution(x, edges, *, type: GraphConv):
|
54 |
return 'GraphConv'
|
55 |
|
56 |
class Nonlinearity(Enum):
|
|
|
59 |
Tanh = 'Tanh'
|
60 |
|
61 |
@register_layer('Nonlinearity')
|
62 |
+
def nonlinearity(x, *, type: Nonlinearity):
|
63 |
return 'ReLU'
|
64 |
|
65 |
+
def register_area(name, params=[]):
|
66 |
+
'''A node that represents an area. It can contain other nodes, but does not restrict movement in any way.'''
|
67 |
+
op = ops.Op(ops.no_op, name, params={p.name: p for p in params}, inputs={}, outputs={}, type='area')
|
68 |
+
LAYERS[name] = op
|
69 |
+
|
70 |
+
register_area('Repeat', params=[ops.Parameter('times', 1, int)])
|
web/src/LynxKiteFlow.svelte
CHANGED
@@ -19,6 +19,7 @@
|
|
19 |
import NodeWithGraphView from './NodeWithGraphView.svelte';
|
20 |
import NodeWithTableView from './NodeWithTableView.svelte';
|
21 |
import NodeWithSubFlow from './NodeWithSubFlow.svelte';
|
|
|
22 |
import NodeSearch from './NodeSearch.svelte';
|
23 |
import '@xyflow/svelte/dist/style.css';
|
24 |
|
@@ -30,6 +31,7 @@
|
|
30 |
graph_view: NodeWithGraphView,
|
31 |
table_view: NodeWithTableView,
|
32 |
sub_flow: NodeWithSubFlow,
|
|
|
33 |
};
|
34 |
|
35 |
export let path = '';
|
|
|
19 |
import NodeWithGraphView from './NodeWithGraphView.svelte';
|
20 |
import NodeWithTableView from './NodeWithTableView.svelte';
|
21 |
import NodeWithSubFlow from './NodeWithSubFlow.svelte';
|
22 |
+
import NodeWithArea from './NodeWithArea.svelte';
|
23 |
import NodeSearch from './NodeSearch.svelte';
|
24 |
import '@xyflow/svelte/dist/style.css';
|
25 |
|
|
|
31 |
graph_view: NodeWithGraphView,
|
32 |
table_view: NodeWithTableView,
|
33 |
sub_flow: NodeWithSubFlow,
|
34 |
+
area: NodeWithArea,
|
35 |
};
|
36 |
|
37 |
export let path = '';
|
web/src/LynxKiteNode.svelte
CHANGED
@@ -26,7 +26,7 @@
|
|
26 |
expanded = !expanded;
|
27 |
onToggle({ expanded });
|
28 |
}
|
29 |
-
function asPx(n: number) {
|
30 |
return n ? n + 'px' : undefined;
|
31 |
}
|
32 |
$: inputs = Object.entries(data.inputs || {});
|
|
|
26 |
expanded = !expanded;
|
27 |
onToggle({ expanded });
|
28 |
}
|
29 |
+
function asPx(n: number | undefined) {
|
30 |
return n ? n + 'px' : undefined;
|
31 |
}
|
32 |
$: inputs = Object.entries(data.inputs || {});
|
web/src/NodeParameter.svelte
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script lang="ts">
|
2 |
+
export let name: string;
|
3 |
+
export let value;
|
4 |
+
export let meta;
|
5 |
+
export let onChange;
|
6 |
+
</script>
|
7 |
+
|
8 |
+
<div class="param">
|
9 |
+
<label>
|
10 |
+
{name}<br>
|
11 |
+
{#if meta?.type?.enum}
|
12 |
+
<select
|
13 |
+
value={value}
|
14 |
+
on:change={(evt) => onChange(evt.currentTarget.value)}
|
15 |
+
>
|
16 |
+
{#each meta.type.enum as option}
|
17 |
+
<option value={option}>{option}</option>
|
18 |
+
{/each}
|
19 |
+
</select>
|
20 |
+
{:else}
|
21 |
+
<input
|
22 |
+
value={value}
|
23 |
+
on:input={(evt) => onChange(evt.currentTarget.value)}
|
24 |
+
/>
|
25 |
+
{/if}
|
26 |
+
</label>
|
27 |
+
</div>
|
28 |
+
|
29 |
+
<style>
|
30 |
+
.param {
|
31 |
+
padding: 8px;
|
32 |
+
}
|
33 |
+
.param label {
|
34 |
+
font-size: 12px;
|
35 |
+
display: block;
|
36 |
+
}
|
37 |
+
.param input,
|
38 |
+
.param select {
|
39 |
+
width: calc(100% - 8px);
|
40 |
+
}
|
41 |
+
</style>
|
web/src/NodeWithArea.svelte
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script lang="ts">
|
2 |
+
import { getContext } from 'svelte';
|
3 |
+
import { type NodeProps, useSvelteFlow } from '@xyflow/svelte';
|
4 |
+
import NodeParameter from './NodeParameter.svelte';
|
5 |
+
|
6 |
+
type $$Props = NodeProps;
|
7 |
+
|
8 |
+
export let nodeStyle = '';
|
9 |
+
export let containerStyle = '';
|
10 |
+
export let id: $$Props['id']; id;
|
11 |
+
export let data: $$Props['data'];
|
12 |
+
export let dragHandle: $$Props['dragHandle'] = undefined; dragHandle;
|
13 |
+
export let type: $$Props['type'] = undefined; type;
|
14 |
+
export let selected: $$Props['selected'] = undefined; selected;
|
15 |
+
export let isConnectable: $$Props['isConnectable'] = undefined; isConnectable;
|
16 |
+
export let zIndex: $$Props['zIndex'] = undefined; zIndex;
|
17 |
+
export let width: $$Props['width'] = undefined; width;
|
18 |
+
export let height: $$Props['height'] = undefined; height;
|
19 |
+
export let dragging: $$Props['dragging']; dragging;
|
20 |
+
export let targetPosition: $$Props['targetPosition'] = undefined; targetPosition;
|
21 |
+
export let sourcePosition: $$Props['sourcePosition'] = undefined; sourcePosition;
|
22 |
+
export let positionAbsoluteX: $$Props['positionAbsoluteX'] = undefined; positionAbsoluteX;
|
23 |
+
export let positionAbsoluteY: $$Props['positionAbsoluteY'] = undefined; positionAbsoluteY;
|
24 |
+
|
25 |
+
function asPx(n: number | undefined) {
|
26 |
+
return n ? n + 'px' : undefined;
|
27 |
+
}
|
28 |
+
const { updateNodeData } = useSvelteFlow();
|
29 |
+
$: meta = getContext('LynxKiteFlow').getMeta(data.title);
|
30 |
+
$: metaParams = meta && Object.fromEntries(meta.data.params.map((p) => [p.name, p]));
|
31 |
+
</script>
|
32 |
+
|
33 |
+
<div class="area" style:width={asPx(width)} style:height={asPx(height)} style={containerStyle}>
|
34 |
+
<div class="title">
|
35 |
+
{data.title}
|
36 |
+
</div>
|
37 |
+
{#each Object.entries(data.params) as [name, value]}
|
38 |
+
<NodeParameter
|
39 |
+
{name}
|
40 |
+
{value}
|
41 |
+
meta={metaParams?.[name]}
|
42 |
+
onChange={(newValue) => updateNodeData(id, { params: { ...data.params, [name]: newValue } })}
|
43 |
+
/>
|
44 |
+
{/each}
|
45 |
+
</div>
|
46 |
+
|
47 |
+
<style>
|
48 |
+
.area {
|
49 |
+
border-radius: 10px;
|
50 |
+
border: 3px dashed #f80;
|
51 |
+
min-width: 400px;
|
52 |
+
min-height: 400px;
|
53 |
+
max-width: 800px;
|
54 |
+
max-height: 800px;
|
55 |
+
z-index: 0 !important;
|
56 |
+
}
|
57 |
+
.title {
|
58 |
+
color: #f80;
|
59 |
+
width: 100%;
|
60 |
+
text-align: center;
|
61 |
+
top: -1.5em;
|
62 |
+
position: absolute;
|
63 |
+
-webkit-text-stroke: 5px white;
|
64 |
+
paint-order: stroke fill;
|
65 |
+
font-weight: bold;
|
66 |
+
}
|
67 |
+
</style>
|
web/src/NodeWithParams.svelte
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
import { getContext } from 'svelte';
|
3 |
import { type NodeProps, useSvelteFlow } from '@xyflow/svelte';
|
4 |
import LynxKiteNode from './LynxKiteNode.svelte';
|
|
|
5 |
type $$Props = NodeProps;
|
6 |
export let id: $$Props['id'];
|
7 |
export let data: $$Props['data'];
|
@@ -12,38 +13,11 @@
|
|
12 |
|
13 |
<LynxKiteNode {...$$props}>
|
14 |
{#each Object.entries(data.params) as [name, value]}
|
15 |
-
<
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
on:change={(evt) => updateNodeData(id, { params: { ...data.params, [name]: evt.currentTarget.value } })}
|
22 |
-
>
|
23 |
-
{#each metaParams[name].type.enum as option}
|
24 |
-
<option value={option}>{option}</option>
|
25 |
-
{/each}
|
26 |
-
</select>
|
27 |
-
{:else}
|
28 |
-
<input
|
29 |
-
value={value}
|
30 |
-
on:input={(evt) => updateNodeData(id, { params: { ...data.params, [name]: evt.currentTarget.value } })}
|
31 |
-
/>
|
32 |
-
{/if}
|
33 |
-
</label>
|
34 |
-
</div>
|
35 |
{/each}
|
36 |
</LynxKiteNode>
|
37 |
-
<style>
|
38 |
-
.param {
|
39 |
-
padding: 8px;
|
40 |
-
}
|
41 |
-
.param label {
|
42 |
-
font-size: 12px;
|
43 |
-
display: block;
|
44 |
-
}
|
45 |
-
.param input,
|
46 |
-
.param select {
|
47 |
-
width: calc(100% - 8px);
|
48 |
-
}
|
49 |
-
</style>
|
|
|
2 |
import { getContext } from 'svelte';
|
3 |
import { type NodeProps, useSvelteFlow } from '@xyflow/svelte';
|
4 |
import LynxKiteNode from './LynxKiteNode.svelte';
|
5 |
+
import NodeParameter from './NodeParameter.svelte';
|
6 |
type $$Props = NodeProps;
|
7 |
export let id: $$Props['id'];
|
8 |
export let data: $$Props['data'];
|
|
|
13 |
|
14 |
<LynxKiteNode {...$$props}>
|
15 |
{#each Object.entries(data.params) as [name, value]}
|
16 |
+
<NodeParameter
|
17 |
+
{name}
|
18 |
+
{value}
|
19 |
+
meta={metaParams?.[name]}
|
20 |
+
onChange={(newValue) => updateNodeData(id, { params: { ...data.params, [name]: newValue } })}
|
21 |
+
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
{/each}
|
23 |
</LynxKiteNode>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/NodeWithParamsVertical.svelte
CHANGED
@@ -1,23 +1,24 @@
|
|
1 |
<script lang="ts">
|
|
|
2 |
import { type NodeProps, useSvelteFlow } from '@xyflow/svelte';
|
3 |
import LynxKiteNode from './LynxKiteNode.svelte';
|
|
|
4 |
type $$Props = NodeProps;
|
5 |
export let id: $$Props['id'];
|
6 |
export let data: $$Props['data'];
|
7 |
const { updateNodeData } = useSvelteFlow();
|
|
|
|
|
8 |
</script>
|
9 |
|
10 |
-
<LynxKiteNode {...$$props} sourcePosition="
|
11 |
{#each Object.entries(data.params) as [name, value]}
|
12 |
-
<
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
/>
|
19 |
-
</label>
|
20 |
-
</div>
|
21 |
{/each}
|
22 |
</LynxKiteNode>
|
23 |
<style>
|
|
|
1 |
<script lang="ts">
|
2 |
+
import { getContext } from 'svelte';
|
3 |
import { type NodeProps, useSvelteFlow } from '@xyflow/svelte';
|
4 |
import LynxKiteNode from './LynxKiteNode.svelte';
|
5 |
+
import NodeParameter from './NodeParameter.svelte';
|
6 |
type $$Props = NodeProps;
|
7 |
export let id: $$Props['id'];
|
8 |
export let data: $$Props['data'];
|
9 |
const { updateNodeData } = useSvelteFlow();
|
10 |
+
$: meta = getContext('LynxKiteFlow').getMeta(data.title);
|
11 |
+
$: metaParams = meta && Object.fromEntries(meta.data.params.map((p) => [p.name, p]));
|
12 |
</script>
|
13 |
|
14 |
+
<LynxKiteNode {...$$props} sourcePosition="top" targetPosition="bottom">
|
15 |
{#each Object.entries(data.params) as [name, value]}
|
16 |
+
<NodeParameter
|
17 |
+
{name}
|
18 |
+
{value}
|
19 |
+
meta={metaParams?.[name]}
|
20 |
+
onChange={(newValue) => updateNodeData(id, { params: { ...data.params, [name]: newValue } })}
|
21 |
+
/>
|
|
|
|
|
|
|
22 |
{/each}
|
23 |
</LynxKiteNode>
|
24 |
<style>
|
web/src/NodeWithSubFlow.svelte
CHANGED
@@ -8,7 +8,6 @@
|
|
8 |
let isExpanded = true;
|
9 |
function onToggle({ expanded }) {
|
10 |
isExpanded = expanded;
|
11 |
-
console.log('onToggle', expanded, height);
|
12 |
nodes.update((n) =>
|
13 |
n.map((node) =>
|
14 |
node.parentNode === id
|
|
|
8 |
let isExpanded = true;
|
9 |
function onToggle({ expanded }) {
|
10 |
isExpanded = expanded;
|
|
|
11 |
nodes.update((n) =>
|
12 |
n.map((node) =>
|
13 |
node.parentNode === id
|