lgaleana commited on
Commit
44c82d2
1 Parent(s): f81e511

Generate code as part of sequential execution

Browse files
Files changed (2) hide show
  1. actions.py +4 -0
  2. components.py +42 -9
actions.py CHANGED
@@ -98,3 +98,7 @@ def execute_task(task_id: int, active_index: int, error_value, *args):
98
  visible=True,
99
  )
100
  ]
 
 
 
 
 
98
  visible=True,
99
  )
100
  ]
101
+
102
+
103
+ def generate_code(task_id: int, active_index: int, code_prompt: str):
104
+ return all_tasks[int(task_id)].generate_code(active_index, code_prompt)
components.py CHANGED
@@ -111,13 +111,15 @@ class AITask(TaskComponent):
111
  class CodeTask(TaskComponent):
112
  name = "Code Task"
113
 
114
- def __init__(self, id_: int, value: str = "", visible: bool = False, code_value: str = ""):
 
 
115
  super().__init__(id_, value, visible)
116
  self._initial_code_value = code_value
117
 
118
  def _render(self) -> gr.Column:
119
  with gr.Column(visible=self._initial_visbility) as gr_component:
120
- code_prompt = gr.Textbox(
121
  label="What would you like to do?",
122
  interactive=True,
123
  value=self._initial_code_value,
@@ -126,6 +128,7 @@ class CodeTask(TaskComponent):
126
  with gr.Row():
127
  with gr.Column():
128
  with gr.Accordion(label="Generated code", open=False) as accordion:
 
129
  self.raw_output = gr.Textbox(
130
  label="Raw output",
131
  lines=5,
@@ -140,12 +143,12 @@ class CodeTask(TaskComponent):
140
  lines=10,
141
  interactive=True,
142
  )
143
- error_message = gr.HighlightedText(value=None, visible=False)
 
 
144
 
145
  self.input = gr.Textbox(
146
- label="Input",
147
- interactive=True,
148
- value=self._initial_value
149
  )
150
  with gr.Column():
151
  self.output = gr.Textbox(
@@ -156,13 +159,13 @@ class CodeTask(TaskComponent):
156
 
157
  generate_code.click(
158
  self.generate_code,
159
- inputs=[code_prompt],
160
  outputs=[
161
  self.raw_output,
162
  self.packages,
163
  self.script,
164
- error_message,
165
- accordion,
166
  ],
167
  )
168
 
@@ -339,6 +342,36 @@ class Task(Component):
339
  print(f"Executing {self._source}: {self._id}")
340
  return inner_task.execute(*args, vars_in_scope)
341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
 
343
  MAX_TASKS = 10
344
 
 
111
  class CodeTask(TaskComponent):
112
  name = "Code Task"
113
 
114
+ def __init__(
115
+ self, id_: int, value: str = "", visible: bool = False, code_value: str = ""
116
+ ):
117
  super().__init__(id_, value, visible)
118
  self._initial_code_value = code_value
119
 
120
  def _render(self) -> gr.Column:
121
  with gr.Column(visible=self._initial_visbility) as gr_component:
122
+ self.code_prompt = gr.Textbox(
123
  label="What would you like to do?",
124
  interactive=True,
125
  value=self._initial_code_value,
 
128
  with gr.Row():
129
  with gr.Column():
130
  with gr.Accordion(label="Generated code", open=False) as accordion:
131
+ self.accordion = accordion
132
  self.raw_output = gr.Textbox(
133
  label="Raw output",
134
  lines=5,
 
143
  lines=10,
144
  interactive=True,
145
  )
146
+ self.error_message = gr.HighlightedText(
147
+ value=None, visible=False
148
+ )
149
 
150
  self.input = gr.Textbox(
151
+ label="Input", interactive=True, value=self._initial_value
 
 
152
  )
153
  with gr.Column():
154
  self.output = gr.Textbox(
 
159
 
160
  generate_code.click(
161
  self.generate_code,
162
+ inputs=[self.code_prompt],
163
  outputs=[
164
  self.raw_output,
165
  self.packages,
166
  self.script,
167
+ self.error_message,
168
+ self.accordion,
169
  ],
170
  )
171
 
 
342
  print(f"Executing {self._source}: {self._id}")
343
  return inner_task.execute(*args, vars_in_scope)
344
 
345
+ @property
346
+ def generate_code_input(self) -> gr.Textbox:
347
+ "This function only works for CodeTask"
348
+ return self._inner_tasks[1].code_prompt
349
+
350
+ @property
351
+ def generate_code_outputs(self):
352
+ "This function only works for CodeTask"
353
+ inner_task = self._inner_tasks[1]
354
+ return (
355
+ inner_task.raw_output,
356
+ inner_task.packages,
357
+ inner_task.script,
358
+ inner_task.error_message,
359
+ inner_task.accordion,
360
+ )
361
+
362
+ def generate_code(self, active_index, code_prompt: str = ""):
363
+ "This function only works for CodeTask"
364
+ inner_task = self._inner_tasks[active_index]
365
+ if isinstance(inner_task, CodeTask):
366
+ return CodeTask.generate_code(code_prompt)
367
+ return (
368
+ gr.Textbox.update(),
369
+ gr.Textbox.update(),
370
+ gr.Textbox.update(),
371
+ gr.HighlightedText.update(),
372
+ gr.Accordion.update(),
373
+ )
374
+
375
 
376
  MAX_TASKS = 10
377