Spaces:
Runtime error
Runtime error
refactor charles_actor -> charles_app
Browse files- app.py +1 -1
- charles_actor.py → charles_app.py +3 -47
app.py
CHANGED
|
@@ -51,7 +51,7 @@ def init_ray():
|
|
| 51 |
# charles_actor_proc = subprocess.Popen([sys.executable, "charles_actor.py"])
|
| 52 |
# while charles_actor_instance == None:
|
| 53 |
# try:
|
| 54 |
-
# charles_actor_instance = ray.get_actor("
|
| 55 |
# except ValueError as e:
|
| 56 |
# time.sleep(0.1) # give the subprocess a chance to start
|
| 57 |
# return charles_actor_instance
|
|
|
|
| 51 |
# charles_actor_proc = subprocess.Popen([sys.executable, "charles_actor.py"])
|
| 52 |
# while charles_actor_instance == None:
|
| 53 |
# try:
|
| 54 |
+
# charles_actor_instance = ray.get_actor("CharlesApp")
|
| 55 |
# except ValueError as e:
|
| 56 |
# time.sleep(0.1) # give the subprocess a chance to start
|
| 57 |
# return charles_actor_instance
|
charles_actor.py → charles_app.py
RENAMED
|
@@ -9,11 +9,11 @@ from respond_to_prompt_async import RespondToPromptAsync
|
|
| 9 |
import asyncio
|
| 10 |
import subprocess
|
| 11 |
|
| 12 |
-
class
|
| 13 |
def __init__(self):
|
| 14 |
self._needs_init = True
|
| 15 |
self._charles_actor_debug_output = ""
|
| 16 |
-
self._environment_state:EnvironmentState = EnvironmentState(episode=0, step=0)
|
| 17 |
self._state = "Initializing"
|
| 18 |
self._clip_transform = CLIPTransform()
|
| 19 |
|
|
@@ -246,52 +246,8 @@ async def main():
|
|
| 246 |
if not ray.is_initialized():
|
| 247 |
init_ray()
|
| 248 |
|
| 249 |
-
|
| 250 |
-
# name="CharlesActor",
|
| 251 |
-
# get_if_exists=True,
|
| 252 |
-
# ).remote()
|
| 253 |
-
# future = charles_actor.start.remote()
|
| 254 |
-
charles_actor = CharlesActor()
|
| 255 |
await charles_actor.start()
|
| 256 |
-
|
| 257 |
-
last_step = -1
|
| 258 |
-
last_episode = -1
|
| 259 |
-
try:
|
| 260 |
-
while True:
|
| 261 |
-
ready, _ = ray.wait([future], timeout=0)
|
| 262 |
-
if ready:
|
| 263 |
-
# The start method has terminated. You can fetch the result (if any) with ray.get().
|
| 264 |
-
# If the method raised an exception, it will be re-raised here.
|
| 265 |
-
try:
|
| 266 |
-
result = ray.get(future)
|
| 267 |
-
print(f"The start method has terminated with result: {result}")
|
| 268 |
-
except Exception as e:
|
| 269 |
-
print(f"The start method raised an exception: {e}")
|
| 270 |
-
break
|
| 271 |
-
else:
|
| 272 |
-
# The start method is still running. You can poll for debug information here.
|
| 273 |
-
await asyncio.sleep(1)
|
| 274 |
-
state = await charles_actor.get_state.remote()
|
| 275 |
-
env_state = await charles_actor.get_environment_state.remote()
|
| 276 |
-
if (env_state.episode != last_episode) or (env_state.step != last_step):
|
| 277 |
-
last_episode = env_state.episode
|
| 278 |
-
last_step = env_state.step
|
| 279 |
-
print(f"Charles is in state: {state}")
|
| 280 |
-
# if len(env_state.llm_preview):
|
| 281 |
-
# print (f"llm_preview: {env_state.llm_preview}")
|
| 282 |
-
# if len(env_state.llm_responses):
|
| 283 |
-
# print (f"llm_responses: {env_state.llm_responses}")
|
| 284 |
-
# if len(env_state.tts_raw_chunk_ids):
|
| 285 |
-
# for chunk_json in env_state.tts_raw_chunk_ids:
|
| 286 |
-
# chunk = json.loads(chunk_json)
|
| 287 |
-
# prompt = chunk['prompt']
|
| 288 |
-
# line = chunk['llm_sentence_id']
|
| 289 |
-
# chunk_id = chunk['chunk_count']
|
| 290 |
-
# print(f"Prompt: {prompt}, Line: {line}, Chunk: {chunk_id}")
|
| 291 |
-
|
| 292 |
-
except KeyboardInterrupt as e:
|
| 293 |
-
print("Script was manually terminated")
|
| 294 |
-
raise(e)
|
| 295 |
|
| 296 |
|
| 297 |
if __name__ == "__main__":
|
|
|
|
| 9 |
import asyncio
|
| 10 |
import subprocess
|
| 11 |
|
| 12 |
+
class CharlesApp:
|
| 13 |
def __init__(self):
|
| 14 |
self._needs_init = True
|
| 15 |
self._charles_actor_debug_output = ""
|
| 16 |
+
self._environment_state:EnvironmentState = EnvironmentState(episode=0, step=0)
|
| 17 |
self._state = "Initializing"
|
| 18 |
self._clip_transform = CLIPTransform()
|
| 19 |
|
|
|
|
| 246 |
if not ray.is_initialized():
|
| 247 |
init_ray()
|
| 248 |
|
| 249 |
+
charles_actor = CharlesApp()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
await charles_actor.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
|
| 253 |
if __name__ == "__main__":
|