Execute tasks and gen code for demos
Browse files- actions.py +0 -4
- app.py +1 -1
- components.py +0 -30
- examples/__init__.py +14 -2
- examples/best_clubs.py +54 -0
- examples/generate_ad.py +3 -3
actions.py
CHANGED
@@ -98,7 +98,3 @@ def execute_task(task_id: int, active_index: int, error_value, *args):
|
|
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)
|
|
|
98 |
visible=True,
|
99 |
)
|
100 |
]
|
|
|
|
|
|
|
|
app.py
CHANGED
@@ -27,7 +27,7 @@ with gr.Blocks() as demo:
|
|
27 |
add_task_btn = gr.Button("Add task")
|
28 |
remove_task_btn = gr.Button("Remove task")
|
29 |
error_message = gr.HighlightedText(value=None, visible=False)
|
30 |
-
execute_btn = gr.Button("Execute")
|
31 |
|
32 |
# Edit layout
|
33 |
add_task_btn.click(
|
|
|
27 |
add_task_btn = gr.Button("Add task")
|
28 |
remove_task_btn = gr.Button("Remove task")
|
29 |
error_message = gr.HighlightedText(value=None, visible=False)
|
30 |
+
execute_btn = gr.Button("Execute tasks")
|
31 |
|
32 |
# Edit layout
|
33 |
add_task_btn.click(
|
components.py
CHANGED
@@ -337,36 +337,6 @@ class Task(Component):
|
|
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 |
|
|
|
337 |
print(f"Executing {self._source}: {self._id}")
|
338 |
return inner_task.execute(*args, vars_in_scope)
|
339 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
|
341 |
MAX_TASKS = 10
|
342 |
|
examples/__init__.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
from typing import List
|
2 |
import gradio as gr
|
3 |
|
4 |
-
from components import Task, TaskComponent
|
5 |
|
6 |
|
7 |
def demo_buttons(demo_id, tasks: List[TaskComponent]):
|
8 |
error_message = gr.HighlightedText(value=None, visible=False)
|
9 |
-
execute_btn = gr.Button("
|
10 |
|
11 |
# Sequential execution
|
12 |
execution_event = execute_btn.click(
|
@@ -17,6 +17,18 @@ def demo_buttons(demo_id, tasks: List[TaskComponent]):
|
|
17 |
)
|
18 |
prev_tasks = []
|
19 |
for task in tasks:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
execution_event = execution_event.then(
|
21 |
execute_task,
|
22 |
inputs=[demo_id, task.component_id, error_message]
|
|
|
1 |
from typing import List
|
2 |
import gradio as gr
|
3 |
|
4 |
+
from components import CodeTask, Task, TaskComponent
|
5 |
|
6 |
|
7 |
def demo_buttons(demo_id, tasks: List[TaskComponent]):
|
8 |
error_message = gr.HighlightedText(value=None, visible=False)
|
9 |
+
execute_btn = gr.Button("Generate code and execute tasks")
|
10 |
|
11 |
# Sequential execution
|
12 |
execution_event = execute_btn.click(
|
|
|
17 |
)
|
18 |
prev_tasks = []
|
19 |
for task in tasks:
|
20 |
+
if isinstance(task, CodeTask):
|
21 |
+
execution_event = execution_event.then(
|
22 |
+
task.generate_code,
|
23 |
+
inputs=[task.code_prompt],
|
24 |
+
outputs=[
|
25 |
+
task.raw_output,
|
26 |
+
task.packages,
|
27 |
+
task.script,
|
28 |
+
task.error_message,
|
29 |
+
task.accordion,
|
30 |
+
],
|
31 |
+
)
|
32 |
execution_event = execution_event.then(
|
33 |
execute_task,
|
34 |
inputs=[demo_id, task.component_id, error_message]
|
examples/best_clubs.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from components import AITask, CodeTask
|
3 |
+
|
4 |
+
from examples import demo_buttons, demo_tasks
|
5 |
+
|
6 |
+
|
7 |
+
DEMO_ID = __name__
|
8 |
+
tasks = [
|
9 |
+
CodeTask(
|
10 |
+
0,
|
11 |
+
"https://openai.com/",
|
12 |
+
visible=True,
|
13 |
+
code_value="Make a google search.",
|
14 |
+
),
|
15 |
+
AITask(
|
16 |
+
1,
|
17 |
+
"""Your goal is to create an ad for a website.
|
18 |
+
You will use an AI image generator to generate an image for your ad.
|
19 |
+
|
20 |
+
Here is the text from the website:
|
21 |
+
{t0}
|
22 |
+
|
23 |
+
Create a prompt for the AI image generator.
|
24 |
+
Avoid logos.""",
|
25 |
+
visible=True,
|
26 |
+
),
|
27 |
+
CodeTask(
|
28 |
+
2,
|
29 |
+
"{t1}",
|
30 |
+
visible=True,
|
31 |
+
code_value="Use openai key <put_your_key_in_here>. Generate an image from a prompt. Return the url.",
|
32 |
+
),
|
33 |
+
AITask(
|
34 |
+
1,
|
35 |
+
"""Here is the text from a website:
|
36 |
+
{t0}
|
37 |
+
|
38 |
+
Here is a prompt that was used by an AI image generator to generate an image for an ad:
|
39 |
+
{t1}
|
40 |
+
|
41 |
+
Consider the website content and the prompt to create a headline for an ad.""",
|
42 |
+
visible=True,
|
43 |
+
),
|
44 |
+
]
|
45 |
+
demo_tasks[DEMO_ID] = tasks
|
46 |
+
|
47 |
+
|
48 |
+
def render():
|
49 |
+
demo_id = gr.Textbox(DEMO_ID, visible=False)
|
50 |
+
tasks[0].render()
|
51 |
+
tasks[1].render()
|
52 |
+
tasks[2].render()
|
53 |
+
tasks[3].render()
|
54 |
+
demo_buttons(demo_id, tasks)
|
examples/generate_ad.py
CHANGED
@@ -15,13 +15,13 @@ tasks = [
|
|
15 |
AITask(
|
16 |
1,
|
17 |
"""Your goal is to create an ad for a website.
|
18 |
-
You are an expert in prompt engineering.
|
19 |
You will use an AI image generator to generate an image for your ad.
|
20 |
|
21 |
Here is the text from the website:
|
22 |
{t0}
|
23 |
|
24 |
-
Create a prompt for the AI image generator.
|
|
|
25 |
visible=True,
|
26 |
),
|
27 |
CodeTask(
|
@@ -38,7 +38,7 @@ Create a prompt for the AI image generator.""",
|
|
38 |
Here is a prompt that was used by an AI image generator to generate an image for an ad:
|
39 |
{t1}
|
40 |
|
41 |
-
|
42 |
visible=True,
|
43 |
),
|
44 |
]
|
|
|
15 |
AITask(
|
16 |
1,
|
17 |
"""Your goal is to create an ad for a website.
|
|
|
18 |
You will use an AI image generator to generate an image for your ad.
|
19 |
|
20 |
Here is the text from the website:
|
21 |
{t0}
|
22 |
|
23 |
+
Create a prompt for the AI image generator.
|
24 |
+
Avoid logos.""",
|
25 |
visible=True,
|
26 |
),
|
27 |
CodeTask(
|
|
|
38 |
Here is a prompt that was used by an AI image generator to generate an image for an ad:
|
39 |
{t1}
|
40 |
|
41 |
+
Consider the website content and the prompt to create a headline for an ad.""",
|
42 |
visible=True,
|
43 |
),
|
44 |
]
|