File size: 890 Bytes
176823e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e81c08f
 
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
import json
import os

import gradio as gr

import modelscope_studio as mgr
from modelscope_studio.components.Flow import 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)


with gr.Blocks() as demo:
    flow = mgr.Flow(value=data, schema=schema, sync_on_data_change=True)
    flow.data_change(fn=on_data_change, inputs=[flow])

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