File size: 2,458 Bytes
d5b1bca
 
a35fa4d
2ecf740
c121218
5c20801
 
d5b1bca
759ceaa
169710f
 
db9c02a
f81e511
7a5c823
db9c02a
7a5c823
bdf4e20
2ecf740
db9c02a
b2c28f8
169710f
 
cc70e87
 
 
 
 
 
 
e8d9d9c
846ae23
cc70e87
 
 
 
 
 
 
 
 
 
 
846ae23
cc70e87
 
 
 
 
 
5c20801
cc70e87
 
 
 
 
 
 
 
 
 
 
d2a7c88
 
 
2ecf740
d2a7c88
2ecf740
214044a
5c20801
846ae23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import gradio as gr

import actions as a
from examples import authenticate_google, best_clubs, generate_ad, seo, summarize_website
from components import all_tasks, Tasks


with gr.Blocks() as demo:
    # Initial layout
    gr.Markdown(
        """
    # Toolkit
    Assemble tasks to build an E2E application with everyday language.
    <br>There are 2 types of tasks.
    <br>
    <br>**AI Task**: Ask ChatGPT to do something for you. Eg, summarize a text.
    <br>**Code Task**: You will need code to do certain things that ChatGPT can't do, like access the internet or iterate over 4k+ tokens.
    <br> With this task, ChatGPT will generate code and then execute. The code must be generated before executing all tasks.
    <br>
    <br>Output from previous tasks can be referenced in subsequen tasks with {tn}. Max 10 tasks allowed (for now).
    """
    )
    with gr.Tab("Toolkit"):
        for t in all_tasks.values():
            t.render()
        with gr.Row():
            add_task_btn = gr.Button("Add task")
            remove_task_btn = gr.Button("Remove task")
        error_message = gr.HighlightedText(value=None, visible=False)
        execute_btn = gr.Button("Execute tasks")

        # Edit layout
        add_task_btn.click(
            a.add_task,
            inputs=Tasks.visibilities(),
            outputs=Tasks.gr_components() + Tasks.visibilities(),
        )
        remove_task_btn.click(
            a.remove_task,
            inputs=Tasks.visibilities(),
            outputs=Tasks.gr_components() + Tasks.visibilities(),
        )

        # Sequential execution
        execution_event = execute_btn.click(
            # Clear error message
            lambda: gr.HighlightedText.update(value=None, visible=False),
            inputs=[],
            outputs=[error_message],
        )
        prev_tasks = []
        for i, task in all_tasks.items():
            execution_event = execution_event.then(
                a.execute_task,
                inputs=[task.component_id, task.active_index, error_message]
                + task.inputs
                + [t.active_index for t in prev_tasks]
                + [o for t in prev_tasks for o in t.outputs],
                outputs=task.outputs + [error_message],
            )
            prev_tasks.append(task)

    # Examples
    summarize_website.render()
    seo.render()
    best_clubs.render()
    generate_ad.render()
    authenticate_google.render()

demo.launch()