Create ui_flowstudio.py
Browse files- app_02/ui_flowstudio.py +56 -16
app_02/ui_flowstudio.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
from engine_03.flow.graph_models import table_to_flowgraph
|
| 4 |
from engine_03.flow.mermaid_renderer import build_mermaid
|
| 5 |
from engine_03.flow.simulator import simulate_flowgraph
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
def build_flowstudio_tab():
|
|
@@ -10,34 +11,35 @@ def build_flowstudio_tab():
|
|
| 10 |
"""
|
| 11 |
## 🧩 MindsEye Flow Studio
|
| 12 |
|
| 13 |
-
- Define **nodes** (id, label, type).
|
| 14 |
-
- Define **edges** (source, target, label).
|
| 15 |
- Click **Update Diagram** to generate a Mermaid-style graph.
|
| 16 |
-
- Click **Simulate Flow** to walk the graph and see an execution log.
|
|
|
|
| 17 |
"""
|
| 18 |
)
|
| 19 |
|
| 20 |
sample_nodes = [
|
| 21 |
-
["event_in", "Incoming Event", "event"],
|
| 22 |
-
["handler", "Handle Event / Transform", "function"],
|
| 23 |
-
["log", "Log to Ledger (conceptual)", "function"],
|
| 24 |
-
["out", "Emit Output", "output"],
|
| 25 |
]
|
| 26 |
sample_edges = [
|
| 27 |
-
["event_in", "handler", ""],
|
| 28 |
-
["handler", "log", ""],
|
| 29 |
-
["log", "out", ""],
|
| 30 |
]
|
| 31 |
|
| 32 |
with gr.Row():
|
| 33 |
with gr.Column(scale=2):
|
| 34 |
gr.Markdown("### Nodes")
|
| 35 |
nodes_df = gr.Dataframe(
|
| 36 |
-
headers=["id", "label", "type"],
|
| 37 |
-
datatype=["str", "str", "str"],
|
| 38 |
value=sample_nodes,
|
| 39 |
row_count=(4, "dynamic"),
|
| 40 |
-
col_count=
|
| 41 |
interactive=True,
|
| 42 |
label="Nodes Table",
|
| 43 |
)
|
|
@@ -45,11 +47,11 @@ def build_flowstudio_tab():
|
|
| 45 |
with gr.Column(scale=2):
|
| 46 |
gr.Markdown("### Edges")
|
| 47 |
edges_df = gr.Dataframe(
|
| 48 |
-
headers=["source", "target", "label"],
|
| 49 |
-
datatype=["str", "str", "str"],
|
| 50 |
value=sample_edges,
|
| 51 |
row_count=(3, "dynamic"),
|
| 52 |
-
col_count=
|
| 53 |
interactive=True,
|
| 54 |
label="Edges Table",
|
| 55 |
)
|
|
@@ -67,6 +69,31 @@ def build_flowstudio_tab():
|
|
| 67 |
label="Execution Log",
|
| 68 |
)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
def update_diagram(nodes, edges):
|
| 71 |
flow = table_to_flowgraph(nodes, edges)
|
| 72 |
return build_mermaid(flow)
|
|
@@ -75,5 +102,18 @@ def build_flowstudio_tab():
|
|
| 75 |
flow = table_to_flowgraph(nodes, edges)
|
| 76 |
return simulate_flowgraph(flow)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
update_btn.click(update_diagram, [nodes_df, edges_df], [diagram_md])
|
| 79 |
simulate_btn.click(simulate, [nodes_df, edges_df], [sim_log])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from engine_03.flow.graph_models import table_to_flowgraph
|
| 4 |
from engine_03.flow.mermaid_renderer import build_mermaid
|
| 5 |
from engine_03.flow.simulator import simulate_flowgraph
|
| 6 |
+
from engine_03.flow.sql_adapter import apply_command
|
| 7 |
|
| 8 |
|
| 9 |
def build_flowstudio_tab():
|
|
|
|
| 11 |
"""
|
| 12 |
## 🧩 MindsEye Flow Studio
|
| 13 |
|
| 14 |
+
- Define **nodes** (id, label, type, style).
|
| 15 |
+
- Define **edges** (source, target, label, style).
|
| 16 |
- Click **Update Diagram** to generate a Mermaid-style graph.
|
| 17 |
+
- Click **Simulate Flow** to walk the graph and see an execution log.
|
| 18 |
+
- Use the **Flow Command** box to modify the graph with a tiny SQL-like syntax.
|
| 19 |
"""
|
| 20 |
)
|
| 21 |
|
| 22 |
sample_nodes = [
|
| 23 |
+
["event_in", "Incoming Event", "event", ""],
|
| 24 |
+
["handler", "Handle Event / Transform", "function", ""],
|
| 25 |
+
["log", "Log to Ledger (conceptual)", "function", ""],
|
| 26 |
+
["out", "Emit Output", "output", ""],
|
| 27 |
]
|
| 28 |
sample_edges = [
|
| 29 |
+
["event_in", "handler", "", ""],
|
| 30 |
+
["handler", "log", "", ""],
|
| 31 |
+
["log", "out", "", ""],
|
| 32 |
]
|
| 33 |
|
| 34 |
with gr.Row():
|
| 35 |
with gr.Column(scale=2):
|
| 36 |
gr.Markdown("### Nodes")
|
| 37 |
nodes_df = gr.Dataframe(
|
| 38 |
+
headers=["id", "label", "type", "style"],
|
| 39 |
+
datatype=["str", "str", "str", "str"],
|
| 40 |
value=sample_nodes,
|
| 41 |
row_count=(4, "dynamic"),
|
| 42 |
+
col_count=4,
|
| 43 |
interactive=True,
|
| 44 |
label="Nodes Table",
|
| 45 |
)
|
|
|
|
| 47 |
with gr.Column(scale=2):
|
| 48 |
gr.Markdown("### Edges")
|
| 49 |
edges_df = gr.Dataframe(
|
| 50 |
+
headers=["source", "target", "label", "style"],
|
| 51 |
+
datatype=["str", "str", "str", "str"],
|
| 52 |
value=sample_edges,
|
| 53 |
row_count=(3, "dynamic"),
|
| 54 |
+
col_count=4,
|
| 55 |
interactive=True,
|
| 56 |
label="Edges Table",
|
| 57 |
)
|
|
|
|
| 69 |
label="Execution Log",
|
| 70 |
)
|
| 71 |
|
| 72 |
+
gr.Markdown("### Flow Command (SQL-ish)")
|
| 73 |
+
|
| 74 |
+
command_box = gr.Textbox(
|
| 75 |
+
label="Command",
|
| 76 |
+
placeholder=(
|
| 77 |
+
'Examples:\n'
|
| 78 |
+
' ADD NODE id=event_in label="Incoming Event" type=event\n'
|
| 79 |
+
' ADD EDGE source=event_in target=handler label="to handler"\n'
|
| 80 |
+
' DELETE NODE id=log\n'
|
| 81 |
+
' DELETE EDGE source=handler target=log\n'
|
| 82 |
+
' STYLE NODE id=handler style="fill:#0ea5e9,stroke:#0369a1"\n'
|
| 83 |
+
' STYLE EDGE source=handler target=log style="stroke:#f97316,stroke-width:2px"'
|
| 84 |
+
),
|
| 85 |
+
lines=4,
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
run_cmd_btn = gr.Button("⚙️ Run Command")
|
| 89 |
+
|
| 90 |
+
command_output = gr.Markdown(
|
| 91 |
+
value="Command output will appear here.",
|
| 92 |
+
label="Command Output",
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
# Core functions
|
| 96 |
+
|
| 97 |
def update_diagram(nodes, edges):
|
| 98 |
flow = table_to_flowgraph(nodes, edges)
|
| 99 |
return build_mermaid(flow)
|
|
|
|
| 102 |
flow = table_to_flowgraph(nodes, edges)
|
| 103 |
return simulate_flowgraph(flow)
|
| 104 |
|
| 105 |
+
def run_command(cmd, nodes, edges):
|
| 106 |
+
new_nodes, new_edges, msg = apply_command(cmd, nodes, edges)
|
| 107 |
+
flow = table_to_flowgraph(new_nodes, new_edges)
|
| 108 |
+
new_diagram = build_mermaid(flow)
|
| 109 |
+
# Clear the command box after execution
|
| 110 |
+
return "", new_nodes, new_edges, msg, new_diagram
|
| 111 |
+
|
| 112 |
update_btn.click(update_diagram, [nodes_df, edges_df], [diagram_md])
|
| 113 |
simulate_btn.click(simulate, [nodes_df, edges_df], [sim_log])
|
| 114 |
+
|
| 115 |
+
run_cmd_btn.click(
|
| 116 |
+
run_command,
|
| 117 |
+
[command_box, nodes_df, edges_df],
|
| 118 |
+
[command_box, nodes_df, edges_df, command_output, diagram_md],
|
| 119 |
+
)
|