-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdesign_ui.py
147 lines (125 loc) · 5.75 KB
/
design_ui.py
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import streamlit as st
import streamlit.components.v1 as components
from graph_data_generator import generators, GeneratorType, Generator
import os
import logging
import datetime
import json
import sys
import io
def load_string(filepath: str, default=None):
if os.path.isfile(filepath) == False and os.access(filepath, os.R_OK) == False:
with io.open(os.path.join(filepath), 'r') as _:
logging.info(f"file_utils.py: No file at {filepath}")
return default
with open(filepath, 'r') as f:
return f.read()
def filtered_generators(
search_term: str,
type_filter: str,
generators: dict[str, Generator]):
def passes_search(search_term: str,
generator: Generator):
if search_term is None:
return True
if search_term != "" and search_term.lower() not in generator.name.lower() and search_term.lower() not in generator.description.lower():
return False
return True
def passes_type_filter(type_filter: str,
generator: Generator):
if type_filter != "All" and type_filter != generator.type.to_string():
return False
return True
return [generator for key, generator in sorted(generators.items(), key=lambda gen:(gen[1].name)) if passes_search(search_term, generator) and passes_type_filter(type_filter, generator)]
# Why isn't this working outside of this class files?
def generators_ui():
search_term = st.text_input("Search Generators by keyword", "", help="Generators are functions for creating mock data.")
# st.write(generators)
type_filter = st.radio("Filter Generator outputs by type", ["All", "String", "Bool", "Integer", "Float", "Function", "Datetime", "Assignment"], index=0)
total_count = len(generators)
display_generators = filtered_generators(search_term, type_filter, generators)
count = len(display_generators)
st.write(f"Displaying {count} of {total_count} generators:")
for generator in display_generators:
with st.expander(generator.name):
# st.markdown("------------------")
st.write(generator.name)
st.write(f"\n {generator.description}")
args = generator.args
arg_inputs = []
for arg in args:
if arg.type == GeneratorType.STRING:
arg_inputs.append(st.text_input(
label=arg.label,
value = arg.default,
key = f'{generator.name}_{arg.label}',
placeholder = f'{arg.hint}',
help = f'{arg.description}'
))
if arg.type == GeneratorType.INT or arg.type == GeneratorType.FLOAT:
arg_inputs.append(st.number_input(
label= arg.label,
value= arg.default,
key = f'{generator.name}_{arg.label}'
))
if arg.type == GeneratorType.BOOL:
options = ["True", "False"]
default = str(arg.default)
default_index = options.index(default)
arg_inputs.append(st.radio(
label=arg.label,
index=default_index,
options = options,
key = f'{generator.name}_{arg.label}'
))
if arg.type == GeneratorType.DATETIME:
arg_inputs.append(st.date_input(
label=arg.label,
value=datetime.datetime.fromisoformat(arg.default),
key = f'{generator.name}_{arg.label}'
))
# if c.button("Generate Example Output", key=f"run_{generator.name}"):
# try:
# module = __import__(generator.import_url(), fromlist=['generate'])
# # logging.info(f'arg_inputs: {arg_inputs}')
# # TODO: Need a fake list of Node Mappings to test out assignment generators
# result = module.generate(arg_inputs)
# c.write(f'Output: {result}')
# except:
# c.error(f"Problem running generator {generator.name}: {sys.exc_info()[0]}")
# Property Code
# name = generator.name
args = arg_inputs
obj = {
generator.gid: args
}
json_string = json.dumps(obj, default=str)
st.write('Copy & paste below as a node/relationship property value in arrows.app')
# st.code widgets automatically include a copy and paste button
st.code(f'{json_string}')
def arrows_ui():
st.markdown(
"""
Use the arrows app to quickly design your mock data. When ready, click on the `Download/Export` button, select the `JSON` tab, then copy the .JSON data to the **② Generate** section
"""
)
# Read from state if a graphGPT model has been created and load that
uri = "https://arrows.app"
if "ARROWS_URI" in st.session_state:
prior_uri = st.session_state["ARROWS_URI"]
logging.info(f'Previously saved arrows uri: {prior_uri}')
if prior_uri is not None:
uri = prior_uri
logging.info(f'Previously saved arrows uri should have loaded')
else:
logging.info(f'No prior arrows uri found. Uri: {uri}')
# components.iframe(uri, height=1000, scrolling=False)
components.html(
f"""
<iframe src="{uri}"
width=100% height="600">
</iframe>
""", height=600, scrolling=False
)
logging.info(f'Arrows source URI rendered: {uri}')
st.session_state["ARROWS_URI"] = None