File size: 3,856 Bytes
176823e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e81c08f
 
176823e
 
 
 
 
 
 
 
 
 
 
 
 
 
41f94d6
 
176823e
 
 
41f94d6
176823e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41f94d6
 
176823e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41f94d6
 
176823e
 
 
41f94d6
 
176823e
 
 
 
 
 
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
import json
import os

import gradio as gr

import modelscope_studio as mgr
from modelscope_studio.components.Flow import BackgroundPropsDict, Edge, Node

with open((os.path.join(os.path.dirname(__file__),
                        "../schema/agents_schema.json"))) as f:
    schema = json.load(f)

# define the initial value of the flow
data = {
    "nodes": [
        Node(id="start-node", name="start", position=dict(x=0, y=0)),
        Node(id="initial-agent-node",
             name="agent",
             position=dict(x=200, y=0),
             data=dict(condition=['']))
    ],
    "edges": [Edge(source='start-node', target="initial-agent-node")],
}


def on_data_change(_flow):
    print(_flow)


flow_props = ["show_sidebar", "show_minimap", "show_controls"]


def on_change(_flow_config, _bgc_variant, _bgc_color, _bgc_bg_color, _bgc_gap,
              _bgc_size, _bgc_offset, _bgc_line_width):
    new_props = {}
    new_background_props = {
        "variant": _bgc_variant,
        "bgColor": _bgc_bg_color,
        "color": _bgc_color,
        "gap": _bgc_gap,
        "size": _bgc_size,
        "offset": _bgc_offset,
        'lineWidth': _bgc_line_width
    }
    for choice in flow_props:
        if choice in _flow_config:
            new_props[choice] = True
        else:
            new_props[choice] = False
    return gr.update(**new_props, background_props=new_background_props)


with gr.Blocks() as demo:
    with gr.Accordion(label="Flow Options"):
        flow_config = gr.CheckboxGroup(
            container=False,
            value=["show_sidebar", "show_minimap", "show_controls"],
            choices=flow_props)
        with gr.Accordion(label="Background Props"):
            with gr.Row():
                with gr.Column():
                    bgc_variant = gr.Radio(choices=["dots", "lines", "cross"],
                                           label="variant",
                                           value="dots")
                with gr.Column():
                    bgc_color = gr.ColorPicker(label="color", value="")
                with gr.Column():
                    bgc_bg_color = gr.ColorPicker(label="bgColor", value="")
                with gr.Column():
                    bgc_gap = gr.Slider(label="gap", value=28)
                with gr.Column():
                    bgc_size = gr.Slider(label="size",
                                         value=1,
                                         maximum=10,
                                         step=1)
                with gr.Column():
                    bgc_offset = gr.Slider(label="offset",
                                           value=1,
                                           step=1,
                                           maximum=10)
                with gr.Column():
                    bgc_line_width = gr.Slider(label="lineWidth",
                                               value=1,
                                               step=1,
                                               maximum=10)

    flow = mgr.Flow(value=data,
                    schema=schema,
                    show_controls=True,
                    show_minimap=True,
                    show_sidebar=True,
                    sync_on_data_change=True,
                    background_props=BackgroundPropsDict(variant='dots'))
    gr.on(triggers=[
        flow_config.change, bgc_variant.change, bgc_color.change,
        bgc_bg_color.change, bgc_gap.change, bgc_size.change,
        bgc_offset.change, bgc_line_width.change
    ],
          fn=on_change,
          inputs=[
              flow_config, bgc_variant, bgc_color, bgc_bg_color, bgc_gap,
              bgc_size, bgc_offset, bgc_line_width
          ],
          outputs=[flow])
    flow.data_change(fn=on_data_change, inputs=[flow])

if __name__ == "__main__":
    demo.queue().launch()