Spaces:
Build error
Build error
dai
commited on
Commit
·
05e2cb7
1
Parent(s):
3057ef1
update gradio to nightly. change UI
Browse files- README.md +2 -2
- app.py +22 -21
- requirements.txt +1 -1
README.md
CHANGED
@@ -4,9 +4,9 @@ emoji: 🗣🦾
|
|
4 |
colorFrom: purple
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
-
pinned:
|
10 |
license: apache-2.0
|
11 |
duplicated_from: jackyliang42/code-as-policies
|
12 |
---
|
|
|
4 |
colorFrom: purple
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.23.0
|
8 |
app_file: app.py
|
9 |
+
pinned: true
|
10 |
license: apache-2.0
|
11 |
duplicated_from: jackyliang42/code-as-policies
|
12 |
---
|
app.py
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
|
|
2 |
import openai
|
3 |
import numpy as np
|
4 |
from tempfile import NamedTemporaryFile
|
@@ -9,7 +14,6 @@ from shapely.affinity import *
|
|
9 |
from omegaconf import OmegaConf
|
10 |
from moviepy.editor import ImageSequenceClip
|
11 |
import gradio as gr
|
12 |
-
from gradio import processing_utils
|
13 |
|
14 |
from lmp import LMP, LMPFGen
|
15 |
from sim import PickPlaceEnv, LMP_wrapper
|
@@ -21,14 +25,13 @@ 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
|
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
|
@@ -97,7 +100,7 @@ class DemoRunner(processing_utils.TempFileManager):
|
|
97 |
|
98 |
def run(self, instruction, history):
|
99 |
if self._env is None:
|
100 |
-
return 'Please run setup first!', None,
|
101 |
|
102 |
self._env.cache_video = []
|
103 |
self._md_logger.clear()
|
@@ -105,35 +108,32 @@ class DemoRunner(processing_utils.TempFileManager):
|
|
105 |
try:
|
106 |
self._lmp_tabletop_ui(instruction, f'objects = {self._env.object_list}')
|
107 |
except Exception as e:
|
108 |
-
return f'Error: {e}', None,
|
109 |
-
|
110 |
-
video_file_name = None
|
111 |
-
if self._env.cache_video:
|
112 |
-
rendered_clip = ImageSequenceClip(self._env.cache_video, fps=25)
|
113 |
-
video_file_name = NamedTemporaryFile(suffix='.mp4').name
|
114 |
-
rendered_clip.write_videofile(video_file_name, fps=25)
|
115 |
|
116 |
# Update chat messages
|
117 |
for message in self._md_logger.get_messages():
|
118 |
history.append((None, message))
|
|
|
119 |
if self._env.cache_video:
|
120 |
-
|
121 |
-
|
|
|
|
|
122 |
|
123 |
-
return self._md_logger.get_log(), self._env.get_camera_image(),
|
124 |
|
125 |
|
126 |
def setup(api_key, model_name, n_blocks, n_bowls):
|
127 |
if not api_key:
|
128 |
-
return 'Please enter your OpenAI API key!', None
|
129 |
if n_blocks + n_bowls == 0:
|
130 |
-
return 'Please select at least one object!', None
|
131 |
|
132 |
demo_runner = DemoRunner()
|
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):
|
@@ -198,12 +198,12 @@ with gr.Blocks() as demo:
|
|
198 |
info_run = gr.Markdown(label='Generated Code')
|
199 |
with gr.Column():
|
200 |
img_setup = gr.Image(label='Current Simulation State')
|
201 |
-
video_run = gr.Video(label='Most Recent Manipulation')
|
202 |
|
203 |
btn_setup.click(
|
204 |
setup,
|
205 |
inputs=[inp_api_key, inp_model_name, inp_n_blocks, inp_n_bowls],
|
206 |
-
outputs=[info_setup, img_setup, state, chat_box,
|
207 |
)
|
208 |
btn_add_cot.click(
|
209 |
add_cot,
|
@@ -222,7 +222,7 @@ with gr.Blocks() as demo:
|
|
222 |
).then(
|
223 |
run,
|
224 |
inputs=[state, chat_box],
|
225 |
-
outputs=[info_run, img_setup,
|
226 |
)
|
227 |
inp_instruction.submit(
|
228 |
submit_chat,
|
@@ -231,9 +231,10 @@ with gr.Blocks() as demo:
|
|
231 |
).then(
|
232 |
run,
|
233 |
inputs=[state, chat_box],
|
234 |
-
outputs=[info_run, img_setup,
|
235 |
)
|
236 |
|
237 |
if __name__ == '__main__':
|
|
|
238 |
demo.queue(concurrency_count=10)
|
239 |
demo.launch()
|
|
|
1 |
import os
|
2 |
+
|
3 |
+
# HACK use the dev version
|
4 |
+
os.system('pip uninstall gradio')
|
5 |
+
os.system('pip install https://gradio-main-build.s3.amazonaws.com/7140903dd63568e8fd1eb763b53126a19d0d9599/gradio-3.23.0-py3-none-any.whl')
|
6 |
+
|
7 |
import openai
|
8 |
import numpy as np
|
9 |
from tempfile import NamedTemporaryFile
|
|
|
14 |
from omegaconf import OmegaConf
|
15 |
from moviepy.editor import ImageSequenceClip
|
16 |
import gradio as gr
|
|
|
17 |
|
18 |
from lmp import LMP, LMPFGen
|
19 |
from sim import PickPlaceEnv, LMP_wrapper
|
|
|
25 |
ask_for_clarification_affix = ' or ask for clarification if you feel unclear'
|
26 |
|
27 |
|
28 |
+
class DemoRunner:
|
29 |
|
30 |
def __init__(self):
|
31 |
self._cfg = OmegaConf.to_container(OmegaConf.load('cfg.yaml'), resolve=True)
|
32 |
self._env = None
|
33 |
self._model_name = ''
|
34 |
self._md_logger = MarkdownLogger()
|
|
|
35 |
|
36 |
def make_LMP(self, env):
|
37 |
# LMP env wrapper
|
|
|
100 |
|
101 |
def run(self, instruction, history):
|
102 |
if self._env is None:
|
103 |
+
return 'Please run setup first!', None, history
|
104 |
|
105 |
self._env.cache_video = []
|
106 |
self._md_logger.clear()
|
|
|
108 |
try:
|
109 |
self._lmp_tabletop_ui(instruction, f'objects = {self._env.object_list}')
|
110 |
except Exception as e:
|
111 |
+
return f'Error: {e}', None, history
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
# Update chat messages
|
114 |
for message in self._md_logger.get_messages():
|
115 |
history.append((None, message))
|
116 |
+
|
117 |
if self._env.cache_video:
|
118 |
+
rendered_clip = ImageSequenceClip(self._env.cache_video, fps=25)
|
119 |
+
video_file_name = NamedTemporaryFile(suffix='.mp4').name
|
120 |
+
rendered_clip.write_videofile(video_file_name, fps=25)
|
121 |
+
history.append((None, (video_file_name, )))
|
122 |
|
123 |
+
return self._md_logger.get_log(), self._env.get_camera_image(), history
|
124 |
|
125 |
|
126 |
def setup(api_key, model_name, n_blocks, n_bowls):
|
127 |
if not api_key:
|
128 |
+
return 'Please enter your OpenAI API key!', None
|
129 |
if n_blocks + n_bowls == 0:
|
130 |
+
return 'Please select at least one object!', None
|
131 |
|
132 |
demo_runner = DemoRunner()
|
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):
|
|
|
198 |
info_run = gr.Markdown(label='Generated Code')
|
199 |
with gr.Column():
|
200 |
img_setup = gr.Image(label='Current Simulation State')
|
201 |
+
# video_run = gr.Video(label='Most Recent Manipulation')
|
202 |
|
203 |
btn_setup.click(
|
204 |
setup,
|
205 |
inputs=[inp_api_key, inp_model_name, inp_n_blocks, inp_n_bowls],
|
206 |
+
outputs=[info_setup, img_setup, state, chat_box, info_run],
|
207 |
)
|
208 |
btn_add_cot.click(
|
209 |
add_cot,
|
|
|
222 |
).then(
|
223 |
run,
|
224 |
inputs=[state, chat_box],
|
225 |
+
outputs=[info_run, img_setup, chat_box, inp_instruction],
|
226 |
)
|
227 |
inp_instruction.submit(
|
228 |
submit_chat,
|
|
|
231 |
).then(
|
232 |
run,
|
233 |
inputs=[state, chat_box],
|
234 |
+
outputs=[info_run, img_setup, chat_box, inp_instruction],
|
235 |
)
|
236 |
|
237 |
if __name__ == '__main__':
|
238 |
+
print(gr.__version__)
|
239 |
demo.queue(concurrency_count=10)
|
240 |
demo.launch()
|
requirements.txt
CHANGED
@@ -9,4 +9,4 @@ imageio==2.4.1
|
|
9 |
imageio-ffmpeg
|
10 |
moviepy
|
11 |
omegaconf
|
12 |
-
gradio
|
|
|
9 |
imageio-ffmpeg
|
10 |
moviepy
|
11 |
omegaconf
|
12 |
+
gradio
|