Fixed E2E
Browse files- actions.py +10 -15
- components.py +11 -13
actions.py
CHANGED
|
@@ -1,18 +1,10 @@
|
|
| 1 |
import re
|
| 2 |
-
from typing import List
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
from components import MAX_TASKS, all_tasks, Task
|
| 7 |
|
| 8 |
|
| 9 |
-
def _is_task_row_fully_invisible(row: List[int]) -> bool:
|
| 10 |
-
for visible in row:
|
| 11 |
-
if bool(visible):
|
| 12 |
-
return False
|
| 13 |
-
return True
|
| 14 |
-
|
| 15 |
-
|
| 16 |
def add_task(*visibilities):
|
| 17 |
for i, visible in enumerate(visibilities, 1):
|
| 18 |
if not bool(visible):
|
|
@@ -45,20 +37,23 @@ def execute_task(task_id: int, active_index: int, error_value, *args):
|
|
| 45 |
- prev_error_value: I carry around whether there is an error in the execution, to be displayed at the end.
|
| 46 |
- args: Other variables that will be decomposed.
|
| 47 |
"""
|
| 48 |
-
task_id = int(task_id)
|
| 49 |
-
active_index = int(active_index)
|
| 50 |
n_avail_tasks = len(Task.available_tasks)
|
| 51 |
-
|
| 52 |
-
task_input = args[:n_avail_tasks][active_index]
|
| 53 |
-
prev_active_indexes = args[n_avail_tasks : n_avail_tasks + task_id]
|
| 54 |
-
prev_task_outputs = args[n_avail_tasks + task_id :]
|
| 55 |
-
|
| 56 |
error_update = gr.HighlightedText.update(
|
| 57 |
value=error_value, visible=error_value is not None
|
| 58 |
)
|
| 59 |
# We need to return outputs for all tasks in the row.
|
| 60 |
outputs = [""] * n_avail_tasks
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
if not task_input:
|
| 63 |
return outputs + [error_update]
|
| 64 |
|
|
|
|
| 1 |
import re
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
from components import MAX_TASKS, all_tasks, Task
|
| 6 |
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def add_task(*visibilities):
|
| 9 |
for i, visible in enumerate(visibilities, 1):
|
| 10 |
if not bool(visible):
|
|
|
|
| 37 |
- prev_error_value: I carry around whether there is an error in the execution, to be displayed at the end.
|
| 38 |
- args: Other variables that will be decomposed.
|
| 39 |
"""
|
|
|
|
|
|
|
| 40 |
n_avail_tasks = len(Task.available_tasks)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
error_update = gr.HighlightedText.update(
|
| 42 |
value=error_value, visible=error_value is not None
|
| 43 |
)
|
| 44 |
# We need to return outputs for all tasks in the row.
|
| 45 |
outputs = [""] * n_avail_tasks
|
| 46 |
|
| 47 |
+
if active_index is None: # Active index could be 0 == not active_index
|
| 48 |
+
return outputs + [error_update]
|
| 49 |
+
|
| 50 |
+
task_id = int(task_id)
|
| 51 |
+
active_index = int(active_index)
|
| 52 |
+
|
| 53 |
+
task_input = args[:n_avail_tasks][active_index]
|
| 54 |
+
prev_active_indexes = args[n_avail_tasks : n_avail_tasks + task_id]
|
| 55 |
+
prev_task_outputs = args[n_avail_tasks + task_id :]
|
| 56 |
+
|
| 57 |
if not task_input:
|
| 58 |
return outputs + [error_update]
|
| 59 |
|
components.py
CHANGED
|
@@ -51,10 +51,10 @@ class TaskComponent(ABC):
|
|
| 51 |
self.gr_component: gr.Box
|
| 52 |
self.input: gr.Textbox
|
| 53 |
self.output: gr.Textbox
|
|
|
|
| 54 |
|
| 55 |
def render(self, id_: int) -> None:
|
| 56 |
self.gr_component = self._render(id_)
|
| 57 |
-
self.gr_component.visible = False
|
| 58 |
|
| 59 |
@abstractmethod
|
| 60 |
def _render(self, id_) -> gr.Box:
|
|
@@ -69,11 +69,11 @@ class AITask(TaskComponent):
|
|
| 69 |
name = "AI Task"
|
| 70 |
|
| 71 |
def _render(self, id_: int) -> gr.Box:
|
| 72 |
-
with gr.Box() as gr_component:
|
| 73 |
-
gr.Markdown("
|
| 74 |
with gr.Row():
|
| 75 |
self.input = gr.Textbox(
|
| 76 |
-
label="
|
| 77 |
lines=10,
|
| 78 |
interactive=True,
|
| 79 |
placeholder="Example: summarize this text: {v0}",
|
|
@@ -93,8 +93,8 @@ class VisitURL(TaskComponent):
|
|
| 93 |
name = "Visit URL"
|
| 94 |
|
| 95 |
def _render(self, id_: int) -> gr.Box:
|
| 96 |
-
with gr.Box() as gr_component:
|
| 97 |
-
gr.Markdown("
|
| 98 |
with gr.Row():
|
| 99 |
self.input = gr.Textbox(
|
| 100 |
interactive=True,
|
|
@@ -123,19 +123,17 @@ class Task(Component):
|
|
| 123 |
|
| 124 |
def _render(self, id_: int) -> gr.Box:
|
| 125 |
with gr.Box(visible=False) as gr_component:
|
| 126 |
-
self.
|
| 127 |
[AITask.name, VisitURL.name],
|
| 128 |
-
value=AITask.name,
|
| 129 |
label="Pick a new Task",
|
| 130 |
type="index",
|
| 131 |
)
|
| 132 |
-
self.active_index = gr.Number(-1, visible=False)
|
| 133 |
for t in self._inner_tasks:
|
| 134 |
t.render(id_)
|
| 135 |
|
| 136 |
-
self.
|
| 137 |
self.pick_task,
|
| 138 |
-
inputs=[self.
|
| 139 |
outputs=[t.gr_component for t in self._inner_tasks],
|
| 140 |
)
|
| 141 |
return gr_component
|
|
@@ -154,7 +152,7 @@ class Task(Component):
|
|
| 154 |
|
| 155 |
def execute(self, active_index, input):
|
| 156 |
inner_task = self._inner_tasks[active_index]
|
| 157 |
-
print(f"Executing {
|
| 158 |
return inner_task.execute(input)
|
| 159 |
|
| 160 |
|
|
@@ -169,7 +167,7 @@ class Tasks:
|
|
| 169 |
return [t.visible for t in all_tasks.values()]
|
| 170 |
|
| 171 |
@classmethod
|
| 172 |
-
def active_indexes(cls) -> List[gr.
|
| 173 |
return [t.active_index for t in all_tasks.values()]
|
| 174 |
|
| 175 |
@classmethod
|
|
|
|
| 51 |
self.gr_component: gr.Box
|
| 52 |
self.input: gr.Textbox
|
| 53 |
self.output: gr.Textbox
|
| 54 |
+
self._source = self.__class__.__name__
|
| 55 |
|
| 56 |
def render(self, id_: int) -> None:
|
| 57 |
self.gr_component = self._render(id_)
|
|
|
|
| 58 |
|
| 59 |
@abstractmethod
|
| 60 |
def _render(self, id_) -> gr.Box:
|
|
|
|
| 69 |
name = "AI Task"
|
| 70 |
|
| 71 |
def _render(self, id_: int) -> gr.Box:
|
| 72 |
+
with gr.Box(visible=False) as gr_component:
|
| 73 |
+
gr.Markdown("Send a message to ChatGPT.")
|
| 74 |
with gr.Row():
|
| 75 |
self.input = gr.Textbox(
|
| 76 |
+
label="Prompt",
|
| 77 |
lines=10,
|
| 78 |
interactive=True,
|
| 79 |
placeholder="Example: summarize this text: {v0}",
|
|
|
|
| 93 |
name = "Visit URL"
|
| 94 |
|
| 95 |
def _render(self, id_: int) -> gr.Box:
|
| 96 |
+
with gr.Box(visible=False) as gr_component:
|
| 97 |
+
gr.Markdown("Get the content from an URL.")
|
| 98 |
with gr.Row():
|
| 99 |
self.input = gr.Textbox(
|
| 100 |
interactive=True,
|
|
|
|
| 123 |
|
| 124 |
def _render(self, id_: int) -> gr.Box:
|
| 125 |
with gr.Box(visible=False) as gr_component:
|
| 126 |
+
self.active_index = gr.Dropdown(
|
| 127 |
[AITask.name, VisitURL.name],
|
|
|
|
| 128 |
label="Pick a new Task",
|
| 129 |
type="index",
|
| 130 |
)
|
|
|
|
| 131 |
for t in self._inner_tasks:
|
| 132 |
t.render(id_)
|
| 133 |
|
| 134 |
+
self.active_index.select(
|
| 135 |
self.pick_task,
|
| 136 |
+
inputs=[self.active_index],
|
| 137 |
outputs=[t.gr_component for t in self._inner_tasks],
|
| 138 |
)
|
| 139 |
return gr_component
|
|
|
|
| 152 |
|
| 153 |
def execute(self, active_index, input):
|
| 154 |
inner_task = self._inner_tasks[active_index]
|
| 155 |
+
print(f"Executing {self._source}: {self._id}")
|
| 156 |
return inner_task.execute(input)
|
| 157 |
|
| 158 |
|
|
|
|
| 167 |
return [t.visible for t in all_tasks.values()]
|
| 168 |
|
| 169 |
@classmethod
|
| 170 |
+
def active_indexes(cls) -> List[gr.Dropdown]:
|
| 171 |
return [t.active_index for t in all_tasks.values()]
|
| 172 |
|
| 173 |
@classmethod
|