Spaces:
Build error
Build error
dai
commited on
Commit
·
0a431d7
1
Parent(s):
35015b6
add modifiers. change default LM. change UI
Browse files
app.py
CHANGED
@@ -17,15 +17,18 @@ from consts import ALL_BLOCKS, ALL_BOWLS
|
|
17 |
from md_logger import MarkdownLogger
|
18 |
|
19 |
default_open_ai_key = os.getenv('OPEN_AI_SECRET')
|
|
|
|
|
20 |
|
21 |
-
|
|
|
22 |
|
23 |
def __init__(self):
|
24 |
self._cfg = OmegaConf.to_container(OmegaConf.load('cfg.yaml'), resolve=True)
|
25 |
self._env = None
|
26 |
self._model_name = ''
|
27 |
self._md_logger = MarkdownLogger()
|
28 |
-
|
29 |
|
30 |
def make_LMP(self, env):
|
31 |
# LMP env wrapper
|
@@ -114,7 +117,7 @@ class DemoRunner:
|
|
114 |
for message in self._md_logger.get_messages():
|
115 |
history.append((None, message))
|
116 |
if self._env.cache_video:
|
117 |
-
temp_name = self.
|
118 |
history.append((None, (temp_name, )))
|
119 |
|
120 |
return self._md_logger.get_log(), self._env.get_camera_image(), video_file_name, history
|
@@ -130,7 +133,7 @@ def setup(api_key, model_name, n_blocks, n_bowls):
|
|
130 |
|
131 |
info, img = demo_runner.setup(api_key, model_name, n_blocks, n_bowls)
|
132 |
welcome_message = 'How can I help you?'
|
133 |
-
return info, img, demo_runner, [(None, welcome_message)]
|
134 |
|
135 |
|
136 |
def run(demo_runner, chat_history):
|
@@ -143,74 +146,93 @@ def submit_chat(chat_message, history):
|
|
143 |
history += [[chat_message, None]]
|
144 |
return '', history
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
with gr.
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
|
|
215 |
demo.queue()
|
216 |
demo.launch()
|
|
|
17 |
from md_logger import MarkdownLogger
|
18 |
|
19 |
default_open_ai_key = os.getenv('OPEN_AI_SECRET')
|
20 |
+
chain_of_thought_affix = ' with a step by step explanation'
|
21 |
+
ask_for_clarification_affix = ' or ask for clarification if you feel unclear'
|
22 |
|
23 |
+
|
24 |
+
class DemoRunner(processing_utils.TempFileManager):
|
25 |
|
26 |
def __init__(self):
|
27 |
self._cfg = OmegaConf.to_container(OmegaConf.load('cfg.yaml'), resolve=True)
|
28 |
self._env = None
|
29 |
self._model_name = ''
|
30 |
self._md_logger = MarkdownLogger()
|
31 |
+
processing_utils.TempFileManager.__init__(self)
|
32 |
|
33 |
def make_LMP(self, env):
|
34 |
# LMP env wrapper
|
|
|
117 |
for message in self._md_logger.get_messages():
|
118 |
history.append((None, message))
|
119 |
if self._env.cache_video:
|
120 |
+
temp_name = self.make_temp_copy_if_needed(video_file_name)
|
121 |
history.append((None, (temp_name, )))
|
122 |
|
123 |
return self._md_logger.get_log(), self._env.get_camera_image(), video_file_name, history
|
|
|
133 |
|
134 |
info, img = demo_runner.setup(api_key, model_name, n_blocks, n_bowls)
|
135 |
welcome_message = 'How can I help you?'
|
136 |
+
return info, img, demo_runner, [(None, welcome_message)], None
|
137 |
|
138 |
|
139 |
def run(demo_runner, chat_history):
|
|
|
146 |
history += [[chat_message, None]]
|
147 |
return '', history
|
148 |
|
149 |
+
def add_cot(chat_messsage):
|
150 |
+
return chat_messsage.strip() + chain_of_thought_affix
|
151 |
+
|
152 |
+
def add_clarification(chat_message):
|
153 |
+
return chat_message.strip() + ask_for_clarification_affix
|
154 |
+
|
155 |
+
|
156 |
+
with open('README.md', 'r') as f:
|
157 |
+
for _ in range(12):
|
158 |
+
next(f)
|
159 |
+
readme_text = f.read()
|
160 |
+
|
161 |
+
with gr.Blocks() as demo:
|
162 |
+
state = gr.State(None)
|
163 |
+
|
164 |
+
gr.Markdown(readme_text)
|
165 |
+
gr.Markdown('# Interactive Demo')
|
166 |
+
with gr.Row():
|
167 |
+
with gr.Column():
|
168 |
+
with gr.Row():
|
169 |
+
inp_api_key = gr.Textbox(value=default_open_ai_key,
|
170 |
+
label='OpenAI API Key (this is not stored anywhere)', lines=1)
|
171 |
+
inp_model_name = gr.Dropdown(label='Model Name', choices=['code-davinci-002', 'text-davinci-003', 'text-davinci-002'], value='text-davinci-003')
|
172 |
+
with gr.Row():
|
173 |
+
inp_n_blocks = gr.Slider(label='Number of Blocks', minimum=0, maximum=5, value=3, step=1)
|
174 |
+
inp_n_bowls = gr.Slider(label='Number of Bowls', minimum=0, maximum=5, value=3, step=1)
|
175 |
+
|
176 |
+
btn_setup = gr.Button("Setup/Reset Simulation")
|
177 |
+
info_setup = gr.Markdown(label='Setup Info')
|
178 |
+
|
179 |
+
with gr.Row():
|
180 |
+
with gr.Column():
|
181 |
+
chat_box = gr.Chatbot()
|
182 |
+
inp_instruction = gr.Textbox(label='Instruction', lines=1)
|
183 |
+
examples = gr.Examples(
|
184 |
+
[
|
185 |
+
'stack two of the blocks',
|
186 |
+
'what color is the rightmost block?',
|
187 |
+
'arrange the blocks into figure 3',
|
188 |
+
'put blocks into non-matching bowls',
|
189 |
+
'swap the positions of one block and another',
|
190 |
+
],
|
191 |
+
inp_instruction,
|
192 |
+
)
|
193 |
+
btn_add_cot = gr.Button(f'+{chain_of_thought_affix} (chain-of-thought)')
|
194 |
+
btn_add_cla = gr.Button(
|
195 |
+
f'+{ask_for_clarification_affix} (conversation)')
|
196 |
+
btn_run = gr.Button("Run (this may take 30+ seconds)")
|
197 |
+
info_run = gr.Markdown(label='Generated Code')
|
198 |
+
with gr.Column():
|
199 |
+
img_setup = gr.Image(label='Current Simulation State')
|
200 |
+
video_run = gr.Video(label='Most Recent Manipulation')
|
201 |
+
|
202 |
+
btn_setup.click(
|
203 |
+
setup,
|
204 |
+
inputs=[inp_api_key, inp_model_name, inp_n_blocks, inp_n_bowls],
|
205 |
+
outputs=[info_setup, img_setup, state, chat_box, video_run],
|
206 |
+
)
|
207 |
+
btn_add_cot.click(
|
208 |
+
add_cot,
|
209 |
+
inp_instruction,
|
210 |
+
inp_instruction,
|
211 |
+
)
|
212 |
+
btn_add_cla.click(
|
213 |
+
add_clarification,
|
214 |
+
inp_instruction,
|
215 |
+
inp_instruction,
|
216 |
+
)
|
217 |
+
btn_run.click(
|
218 |
+
submit_chat,
|
219 |
+
[inp_instruction, chat_box],
|
220 |
+
[inp_instruction, chat_box],
|
221 |
+
).then(
|
222 |
+
run,
|
223 |
+
inputs=[state, chat_box],
|
224 |
+
outputs=[info_run, img_setup, video_run, chat_box, inp_instruction],
|
225 |
+
)
|
226 |
+
inp_instruction.submit(
|
227 |
+
submit_chat,
|
228 |
+
[inp_instruction, chat_box],
|
229 |
+
[inp_instruction, chat_box],
|
230 |
+
).then(
|
231 |
+
run,
|
232 |
+
inputs=[state, chat_box],
|
233 |
+
outputs=[info_run, img_setup, video_run, chat_box, inp_instruction],
|
234 |
+
)
|
235 |
|
236 |
+
if __name__ == '__main__':
|
237 |
demo.queue()
|
238 |
demo.launch()
|