File size: 2,509 Bytes
9a6610f
cd07fae
7082c91
aa366dd
711f1b0
9a6610f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd07fae
9a6610f
 
 
 
 
cd07fae
 
 
 
 
9a6610f
 
 
cd07fae
 
 
4c88397
097fda5
 
992b91f
0bfd609
 
 
880d06d
 
4c88397
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import yaml  # Import the pyyaml package
from services import ServiceOne, ServiceTwo
import json
from pathlib import Path

# List of available services
services = {
    "Service One": ServiceOne(),
    "Service Two": ServiceTwo()
}

# User selects services and parameters
selected_services = st.multiselect("Select Services", list(services.keys()))
parameters = {}

# Allow users to input parameters for selected services
for service_name in selected_services:
    service_instance = services[service_name]
    parameters[service_name] = {}
    for param_name in service_instance.parameters:
        parameters[service_name][param_name] = st.text_input(f"Enter {param_name} for {service_name}")

# User-defined workflow execution
if st.button("Run Workflow"):
    input_data = ...  # Define your input data
    workflow_config = []  # List to store the workflow configuration
    for service_name in selected_services:
        service_instance = services[service_name]
        service_instance.parameters = parameters[service_name]
        output_data = service_instance.execute(input_data)
        input_data = output_data
        # Store the service name and parameters in the workflow configuration
        workflow_config.append({
            "service": service_name,
            "parameters": service_instance.parameters
        })

    # Display the final output
    st.success("Workflow executed successfully. Output: {}".format(input_data))

    # Export workflow configuration as YAML or JSON
    export_format = st.radio("Export Format", ["YAML", "JSON"])

    with open("workflow_config.json", "w") as json_file:
        json.dump(workflow_config, json_file, indent=4)

    # with open("workflow_config.json", "w") as json_file:
    st.download_button("Export Config",    
                       data=Path("workflow_config.json").read_text(),
                        file_name="workflow_config.json",
                        mime="application/json")
    
    # if st.download_button("Export Workflow"):
    #     if export_format == "YAML":
    #         with open("workflow_config.yaml", "w") as yaml_file:
    #             yaml.dump(workflow_config, yaml_file)
    #         st.success("Workflow configuration exported as YAML.")
    #     elif export_format == "JSON":
    #         with open("workflow_config.json", "w") as json_file:
    #             json.dump(workflow_config, json_file, indent=4)
    #         st.success("Workflow configuration exported as JSON.")