lgaleana commited on
Commit
06d5574
2 Parent(s): 2f0960b 44c82d2

Merge branch 'gen_code'

Browse files
Files changed (2) hide show
  1. actions.py +4 -0
  2. components.py +38 -5
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
@@ -119,7 +119,7 @@ class CodeTask(TaskComponent):
119
 
120
  def _render(self) -> gr.Column:
121
  with gr.Column(visible=self._initial_visbility) as gr_component:
122
- code_prompt = gr.Textbox(
123
  label="What would you like to do?",
124
  interactive=True,
125
  value=self._initial_code_value,
@@ -128,6 +128,7 @@ class CodeTask(TaskComponent):
128
  with gr.Row():
129
  with gr.Column():
130
  with gr.Accordion(label="Generated code", open=False) as accordion:
 
131
  self.raw_output = gr.Textbox(
132
  label="Raw output",
133
  lines=5,
@@ -142,7 +143,9 @@ class CodeTask(TaskComponent):
142
  lines=10,
143
  interactive=True,
144
  )
145
- error_message = gr.HighlightedText(value=None, visible=False)
 
 
146
 
147
  self.input = gr.Textbox(
148
  label="Input", interactive=True, value=self._initial_value
@@ -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
 
@@ -334,6 +337,36 @@ class Task(Component):
334
  print(f"Executing {self._source}: {self._id}")
335
  return inner_task.execute(*args, vars_in_scope)
336
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
 
338
  MAX_TASKS = 10
339
 
 
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
 
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
 
 
337
  print(f"Executing {self._source}: {self._id}")
338
  return inner_task.execute(*args, vars_in_scope)
339
 
340
+ @property
341
+ def generate_code_input(self) -> gr.Textbox:
342
+ "This function only works for CodeTask"
343
+ return self._inner_tasks[1].code_prompt
344
+
345
+ @property
346
+ def generate_code_outputs(self):
347
+ "This function only works for CodeTask"
348
+ inner_task = self._inner_tasks[1]
349
+ return (
350
+ inner_task.raw_output,
351
+ inner_task.packages,
352
+ inner_task.script,
353
+ inner_task.error_message,
354
+ inner_task.accordion,
355
+ )
356
+
357
+ def generate_code(self, active_index, code_prompt: str = ""):
358
+ "This function only works for CodeTask"
359
+ inner_task = self._inner_tasks[active_index]
360
+ if isinstance(inner_task, CodeTask):
361
+ return CodeTask.generate_code(code_prompt)
362
+ return (
363
+ gr.Textbox.update(),
364
+ gr.Textbox.update(),
365
+ gr.Textbox.update(),
366
+ gr.HighlightedText.update(),
367
+ gr.Accordion.update(),
368
+ )
369
+
370
 
371
  MAX_TASKS = 10
372