Test
Browse files
app.py
CHANGED
@@ -26,6 +26,10 @@ class Input:
|
|
26 |
|
27 |
|
28 |
class AITask:
|
|
|
|
|
|
|
|
|
29 |
def render(self, visible: bool) -> gr.Box:
|
30 |
with gr.Box(visible=visible) as gr_component:
|
31 |
gr.Markdown(f"AI task")
|
@@ -52,22 +56,23 @@ class AITask:
|
|
52 |
|
53 |
|
54 |
class Component:
|
55 |
-
def __init__(self, id_: int, internal: Union[Input, AITask], visible:
|
56 |
self._id = id_
|
57 |
self.component_id: gr.Textbox
|
58 |
-
self.
|
59 |
self.gr_component = gr.Box
|
60 |
-
self.
|
61 |
self.output_name: gr.Textbox
|
62 |
self.output: gr.Textbox
|
63 |
self.source: gr.Textbox
|
64 |
|
65 |
def render(self) -> None:
|
66 |
self.component_id = gr.Textbox(value=str(self._id), visible=False)
|
67 |
-
self.source = gr.Textbox(value=self.
|
68 |
-
self.
|
69 |
-
self.
|
70 |
-
self.
|
|
|
71 |
|
72 |
|
73 |
class Variable(NamedTuple):
|
@@ -80,12 +85,9 @@ class Variable(NamedTuple):
|
|
80 |
all_inputs = [Component(i, Input()) for i in range(MAX_INPUTS)]
|
81 |
all_tasks = [Component(i, AITask()) for i in range(MAX_TASKS)]
|
82 |
all_components = all_inputs + all_tasks
|
83 |
-
all_variables = {} # Will be updated once rendered
|
84 |
|
85 |
-
all_inputs[0].
|
86 |
-
all_tasks[0].
|
87 |
-
next_input = 1
|
88 |
-
next_task = 1
|
89 |
|
90 |
|
91 |
def _update_components(i: int, max: int):
|
@@ -127,13 +129,6 @@ def execute(output_names, outputs):
|
|
127 |
print(output_name)
|
128 |
|
129 |
|
130 |
-
def update_scope_variables(component_id, source, output_name, output):
|
131 |
-
all_variables[f"{source}.{component_id}"] = Variable(
|
132 |
-
component_id, source, output_name, output
|
133 |
-
)
|
134 |
-
print(all_variables)
|
135 |
-
|
136 |
-
|
137 |
with gr.Blocks() as demo:
|
138 |
# Initial layout
|
139 |
for i in all_inputs:
|
@@ -180,12 +175,4 @@ with gr.Blocks() as demo:
|
|
180 |
outputs=[t.gr_component for t in all_tasks],
|
181 |
)
|
182 |
|
183 |
-
# Execution
|
184 |
-
for c in all_components:
|
185 |
-
c.output_name.change(
|
186 |
-
update_scope_variables,
|
187 |
-
inputs=[c.component_id, c.source, c.output_name, c.output],
|
188 |
-
outputs=[],
|
189 |
-
)
|
190 |
-
|
191 |
demo.launch()
|
|
|
26 |
|
27 |
|
28 |
class AITask:
|
29 |
+
@property
|
30 |
+
def vars(self):
|
31 |
+
return [self.prompt]
|
32 |
+
|
33 |
def render(self, visible: bool) -> gr.Box:
|
34 |
with gr.Box(visible=visible) as gr_component:
|
35 |
gr.Markdown(f"AI task")
|
|
|
56 |
|
57 |
|
58 |
class Component:
|
59 |
+
def __init__(self, id_: int, internal: Union[Input, AITask], visible: str = "0"):
|
60 |
self._id = id_
|
61 |
self.component_id: gr.Textbox
|
62 |
+
self.internal = internal
|
63 |
self.gr_component = gr.Box
|
64 |
+
self._visible = visible
|
65 |
self.output_name: gr.Textbox
|
66 |
self.output: gr.Textbox
|
67 |
self.source: gr.Textbox
|
68 |
|
69 |
def render(self) -> None:
|
70 |
self.component_id = gr.Textbox(value=str(self._id), visible=False)
|
71 |
+
self.source = gr.Textbox(value=self.internal.__class__.__name__, visible=False)
|
72 |
+
self.visible = gr.Textbox(value=self._visible, visible=False)
|
73 |
+
self.gr_component = self.internal.render(bool(self._visible))
|
74 |
+
self.output_name = self.internal.output_name
|
75 |
+
self.output = self.internal.output
|
76 |
|
77 |
|
78 |
class Variable(NamedTuple):
|
|
|
85 |
all_inputs = [Component(i, Input()) for i in range(MAX_INPUTS)]
|
86 |
all_tasks = [Component(i, AITask()) for i in range(MAX_TASKS)]
|
87 |
all_components = all_inputs + all_tasks
|
|
|
88 |
|
89 |
+
all_inputs[0]._visible = "1"
|
90 |
+
all_tasks[0]._visible = "1"
|
|
|
|
|
91 |
|
92 |
|
93 |
def _update_components(i: int, max: int):
|
|
|
129 |
print(output_name)
|
130 |
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
with gr.Blocks() as demo:
|
133 |
# Initial layout
|
134 |
for i in all_inputs:
|
|
|
175 |
outputs=[t.gr_component for t in all_tasks],
|
176 |
)
|
177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
demo.launch()
|