lgaleana commited on
Commit
f81e511
β€’
1 Parent(s): 541b9a9

Update demo

Browse files
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
 
3
  import actions as a
4
- from examples import hello
5
  from components import all_tasks, Tasks
6
 
7
 
@@ -10,18 +10,14 @@ with gr.Blocks() as demo:
10
  gr.Markdown(
11
  """
12
  # Toolkit
13
- Assemble tasks to build an E2E application. Give instructions with text.
14
  <br>There are 2 types of tasks.
15
  <br>
16
  <br>**AI Task**: Ask ChatGPT to do something for you. Eg, summarize a text.
17
  <br>**Code Task**: ChatGPT will create a python function to do something for you. Eg, get the text from a website.
18
- <br> The code for the Code Tasks must be generated before executing the whole application.
19
  <br>
20
  <br>Output from previous tasks can be referenced in subsequen tasks with {tn}. Max 10 tasks allowed (for now).
21
- <br>
22
- <br>Example application:
23
- <br>1. Code Task: Get the text from a website.
24
- <br>2. AI Task: Summarize {t0}.
25
  """
26
  )
27
  with gr.Tab("Toolkit"):
@@ -63,7 +59,7 @@ with gr.Blocks() as demo:
63
  outputs=task.outputs + [error_message],
64
  )
65
  prev_tasks.append(task)
66
- with gr.Tab("Example: Hello world"):
67
- hello.render()
68
 
69
  demo.launch()
 
1
  import gradio as gr
2
 
3
  import actions as a
4
+ from examples import summarize_website
5
  from components import all_tasks, Tasks
6
 
7
 
 
10
  gr.Markdown(
11
  """
12
  # Toolkit
13
+ Assemble tasks to build an E2E application with everyday language.
14
  <br>There are 2 types of tasks.
15
  <br>
16
  <br>**AI Task**: Ask ChatGPT to do something for you. Eg, summarize a text.
17
  <br>**Code Task**: ChatGPT will create a python function to do something for you. Eg, get the text from a website.
18
+ <br> Use this task for things that ChatGPT can't do on its own, like access the internet or iterate over 4K+ tokens.
19
  <br>
20
  <br>Output from previous tasks can be referenced in subsequen tasks with {tn}. Max 10 tasks allowed (for now).
 
 
 
 
21
  """
22
  )
23
  with gr.Tab("Toolkit"):
 
59
  outputs=task.outputs + [error_message],
60
  )
61
  prev_tasks.append(task)
62
+ with gr.Tab("Example: Summarize website"):
63
+ summarize_website.render()
64
 
65
  demo.launch()
components.py CHANGED
@@ -1,7 +1,7 @@
1
  from concurrent.futures import ThreadPoolExecutor
2
  import re
3
  from abc import ABC, abstractmethod
4
- from typing import Any, Dict, List, Union
5
 
6
  import gradio as gr
7
 
@@ -102,20 +102,25 @@ class AITask(TaskComponent):
102
  def inputs(self) -> List[gr.Textbox]:
103
  return [self.input]
104
 
105
- def execute(self, prompt: str, vars_in_scope: Dict[str, Any]) -> str:
106
  formatted_prompt = self.format_input(prompt, vars_in_scope)
107
- return ai.llm.next([{"role": "user", "content": formatted_prompt}])
 
108
 
109
 
110
  class CodeTask(TaskComponent):
111
  name = "Code Task"
112
 
 
 
 
 
113
  def _render(self) -> gr.Column:
114
  with gr.Column(visible=self._initial_visbility) as gr_component:
115
  code_prompt = gr.Textbox(
116
  label="What would you like to do?",
117
  interactive=True,
118
- value=self._initial_value,
119
  )
120
  generate_code = gr.Button("Generate code")
121
  with gr.Row():
@@ -140,6 +145,7 @@ class CodeTask(TaskComponent):
140
  self.input = gr.Textbox(
141
  label="Input",
142
  interactive=True,
 
143
  )
144
  with gr.Column():
145
  self.output = gr.Textbox(
@@ -250,15 +256,19 @@ class CodeTask(TaskComponent):
250
  def execute(
251
  self, packages: str, function: str, input: str, vars_in_scope: Dict[str, Any]
252
  ):
 
 
 
253
  import inspect
254
- import subprocess
255
- import sys
256
 
257
- function = function.strip()
 
 
258
 
259
- for p in eval(packages):
260
- subprocess.check_call([sys.executable, "-m", "pip", "install", p])
261
 
 
262
  exec(function, locals())
263
  # Looking for the last defined function
264
  for var in reversed(locals().values()):
@@ -272,7 +282,11 @@ class CodeTask(TaskComponent):
272
  formatted_input = eval(formatted_input)
273
  except:
274
  pass
275
- return self._toolkit_func(formatted_input)
 
 
 
 
276
  return self._toolkit_func()
277
 
278
 
 
1
  from concurrent.futures import ThreadPoolExecutor
2
  import re
3
  from abc import ABC, abstractmethod
4
+ from typing import Any, Dict, List, Optional, Union
5
 
6
  import gradio as gr
7
 
 
102
  def inputs(self) -> List[gr.Textbox]:
103
  return [self.input]
104
 
105
+ def execute(self, prompt: str, vars_in_scope: Dict[str, Any]) -> Optional[str]:
106
  formatted_prompt = self.format_input(prompt, vars_in_scope)
107
+ if formatted_prompt:
108
+ return ai.llm.next([{"role": "user", "content": formatted_prompt}])
109
 
110
 
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,
124
  )
125
  generate_code = gr.Button("Generate code")
126
  with gr.Row():
 
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(
 
256
  def execute(
257
  self, packages: str, function: str, input: str, vars_in_scope: Dict[str, Any]
258
  ):
259
+ if not function:
260
+ return None
261
+
262
  import inspect
 
 
263
 
264
+ def install():
265
+ import subprocess
266
+ import sys
267
 
268
+ for p in eval(packages):
269
+ subprocess.check_call([sys.executable, "-m", "pip", "install", p])
270
 
271
+ function = function.strip()
272
  exec(function, locals())
273
  # Looking for the last defined function
274
  for var in reversed(locals().values()):
 
282
  formatted_input = eval(formatted_input)
283
  except:
284
  pass
285
+ if formatted_input:
286
+ install()
287
+ return self._toolkit_func(formatted_input)
288
+ return None
289
+ install()
290
  return self._toolkit_func()
291
 
292
 
examples/{hello.py β†’ summarize_website.py} RENAMED
@@ -6,8 +6,13 @@ import examples.actions as ea
6
 
7
  DEMO_ID = "hello"
8
  tasks = [
9
- CodeTask(0, "Say hello world", visible=True),
10
- AITask(1, "Explain this to me: {t0}", visible=True),
 
 
 
 
 
11
  ]
12
  ea.demo_tasks[DEMO_ID] = tasks
13
 
 
6
 
7
  DEMO_ID = "hello"
8
  tasks = [
9
+ CodeTask(
10
+ 0,
11
+ "https://openai.com/",
12
+ visible=True,
13
+ code_value="Get text from a website (no html). No empty lines.",
14
+ ),
15
+ AITask(1, "Summarize: {t0}", visible=True),
16
  ]
17
  ea.demo_tasks[DEMO_ID] = tasks
18