Spaces:
Running
Running
Fix some bugs.
Browse files- server/ops.py +7 -10
- server/pytorch_model_ops.py +1 -1
- server/workspace.py +3 -1
- web/src/LynxKiteFlow.svelte +1 -0
server/ops.py
CHANGED
@@ -22,7 +22,9 @@ class Parameter:
|
|
22 |
return Parameter(name, options[0], enum.Enum(f'OptionsFor{name}', options))
|
23 |
|
24 |
def __post_init__(self):
|
25 |
-
if self.
|
|
|
|
|
26 |
self.type = type(self.default)
|
27 |
def to_json(self):
|
28 |
if isinstance(self.type, type) and issubclass(self.type, enum.Enum):
|
@@ -47,11 +49,11 @@ class Op:
|
|
47 |
|
48 |
def __call__(self, *inputs, **params):
|
49 |
# Convert parameters.
|
50 |
-
for p in params
|
51 |
if p in self.params:
|
52 |
-
if p.type == int:
|
53 |
params[p] = int(params[p])
|
54 |
-
elif p.type == float:
|
55 |
params[p] = float(params[p])
|
56 |
# Convert inputs.
|
57 |
inputs = list(inputs)
|
@@ -150,12 +152,7 @@ def op(name, *, view='basic', sub_nodes=None):
|
|
150 |
params = {}
|
151 |
for n, param in sig.parameters.items():
|
152 |
if param.kind == param.KEYWORD_ONLY:
|
153 |
-
|
154 |
-
if p.default is inspect._empty:
|
155 |
-
p.default = None
|
156 |
-
if p.type is inspect._empty:
|
157 |
-
p.type = type(p.default)
|
158 |
-
params[n] = p
|
159 |
outputs = {'output': 'yes'} if view == 'basic' else {} # Maybe more fancy later.
|
160 |
op = Op(func, name, params=params, inputs=inputs, outputs=outputs, type=view)
|
161 |
if sub_nodes is not None:
|
|
|
22 |
return Parameter(name, options[0], enum.Enum(f'OptionsFor{name}', options))
|
23 |
|
24 |
def __post_init__(self):
|
25 |
+
if self.default is inspect._empty:
|
26 |
+
self.default = None
|
27 |
+
if self.type is None or self.type is inspect._empty:
|
28 |
self.type = type(self.default)
|
29 |
def to_json(self):
|
30 |
if isinstance(self.type, type) and issubclass(self.type, enum.Enum):
|
|
|
49 |
|
50 |
def __call__(self, *inputs, **params):
|
51 |
# Convert parameters.
|
52 |
+
for p in params:
|
53 |
if p in self.params:
|
54 |
+
if self.params[p].type == int:
|
55 |
params[p] = int(params[p])
|
56 |
+
elif self.params[p].type == float:
|
57 |
params[p] = float(params[p])
|
58 |
# Convert inputs.
|
59 |
inputs = list(inputs)
|
|
|
152 |
params = {}
|
153 |
for n, param in sig.parameters.items():
|
154 |
if param.kind == param.KEYWORD_ONLY:
|
155 |
+
params[n] = Parameter(n, param.default, param.annotation)
|
|
|
|
|
|
|
|
|
|
|
156 |
outputs = {'output': 'yes'} if view == 'basic' else {} # Maybe more fancy later.
|
157 |
op = Op(func, name, params=params, inputs=inputs, outputs=outputs, type=view)
|
158 |
if sub_nodes is not None:
|
server/pytorch_model_ops.py
CHANGED
@@ -23,7 +23,7 @@ def register_layer(name):
|
|
23 |
for name, param in sig.parameters.items()
|
24 |
if param.kind != param.KEYWORD_ONLY}
|
25 |
params = {
|
26 |
-
name:
|
27 |
for name, param in sig.parameters.items()
|
28 |
if param.kind == param.KEYWORD_ONLY}
|
29 |
outputs = {'x': 'tensor'}
|
|
|
23 |
for name, param in sig.parameters.items()
|
24 |
if param.kind != param.KEYWORD_ONLY}
|
25 |
params = {
|
26 |
+
name: ops.Parameter(name, param.default, param.annotation)
|
27 |
for name, param in sig.parameters.items()
|
28 |
if param.kind == param.KEYWORD_ONLY}
|
29 |
outputs = {'x': 'tensor'}
|
server/workspace.py
CHANGED
@@ -81,7 +81,9 @@ def execute(ws):
|
|
81 |
|
82 |
def save(ws: Workspace, path: str):
|
83 |
j = ws.model_dump_json(indent=2)
|
84 |
-
|
|
|
|
|
85 |
f.write(j)
|
86 |
f.close()
|
87 |
os.replace(f.name, path)
|
|
|
81 |
|
82 |
def save(ws: Workspace, path: str):
|
83 |
j = ws.model_dump_json(indent=2)
|
84 |
+
dirname, basename = os.path.split(path)
|
85 |
+
# Create temp file in the same directory to make sure it's on the same filesystem.
|
86 |
+
with tempfile.NamedTemporaryFile('w', prefix=basename, dir=dirname, delete_on_close=False) as f:
|
87 |
f.write(j)
|
88 |
f.close()
|
89 |
os.replace(f.name, path)
|
web/src/LynxKiteFlow.svelte
CHANGED
@@ -65,6 +65,7 @@
|
|
65 |
const node = {...e.detail};
|
66 |
nodes.update((n) => {
|
67 |
node.position = screenToFlowPosition({x: nodeSearchSettings.pos.x, y: nodeSearchSettings.pos.y});
|
|
|
68 |
const title = node.data.title;
|
69 |
node.data.params = Object.fromEntries(
|
70 |
node.data.params.map((p) => [p.name, p.default]));
|
|
|
65 |
const node = {...e.detail};
|
66 |
nodes.update((n) => {
|
67 |
node.position = screenToFlowPosition({x: nodeSearchSettings.pos.x, y: nodeSearchSettings.pos.y});
|
68 |
+
node.data = { ...node.data };
|
69 |
const title = node.data.title;
|
70 |
node.data.params = Object.fromEntries(
|
71 |
node.data.params.map((p) => [p.name, p.default]));
|