Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Really working logs
Browse files
app.py
CHANGED
@@ -451,17 +451,11 @@ def chat_message_to_json(obj):
|
|
451 |
return obj
|
452 |
|
453 |
|
454 |
-
def save_final_status(folder, status: str,
|
455 |
metadata_path = os.path.join(folder, "metadata.json")
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
if getattr(memory_step, "observations_images", None):
|
460 |
-
memory_step.observations_images = None
|
461 |
-
a = open(metadata_path,"w")
|
462 |
-
summary = memory.get_succinct_steps()
|
463 |
-
a.write(json.dumps({"status":status, "summary":summary, "error_message": error_message}, default=chat_message_to_json))
|
464 |
-
a.close()
|
465 |
|
466 |
def initialize_session(interactive_mode, request: gr.Request):
|
467 |
session_hash = request.session_hash
|
@@ -504,9 +498,12 @@ class EnrichedGradioUI(GradioUI):
|
|
504 |
os.makedirs(data_dir)
|
505 |
|
506 |
|
507 |
-
if "agent"
|
|
|
|
|
508 |
session_state["agent"] = create_agent(data_dir=data_dir, desktop=desktop)
|
509 |
|
|
|
510 |
# Construct the full task with instructions
|
511 |
full_task = task_input + dedent(f"""
|
512 |
The desktop has a resolution of {WIDTH}x{HEIGHT}, take it into account to decide clicking coordinates.
|
@@ -536,7 +533,13 @@ class EnrichedGradioUI(GradioUI):
|
|
536 |
yield stored_messages
|
537 |
|
538 |
yield stored_messages
|
539 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
540 |
|
541 |
# # TODO: uncomment below after testing
|
542 |
except Exception as e:
|
@@ -544,7 +547,7 @@ class EnrichedGradioUI(GradioUI):
|
|
544 |
stored_messages.append(gr.ChatMessage(role="assistant", content=error_message))
|
545 |
yield stored_messages
|
546 |
raise e
|
547 |
-
save_final_status(data_dir, "failed", summary=
|
548 |
|
549 |
finally:
|
550 |
upload_to_hf_and_remove(data_dir)
|
@@ -708,14 +711,12 @@ with gr.Blocks(theme=theme, css=custom_css, js=custom_js, fill_width=True) as de
|
|
708 |
fn=clear_and_set_view_only,
|
709 |
inputs=[task_input],
|
710 |
outputs=[results_output, sandbox_html, results_container]
|
711 |
-
)
|
712 |
-
view_only_event.then(agent_ui.interact_with_agent, [task_input, stored_messages, session_state, session_hash_state], [chatbot_display]).then(
|
713 |
fn=set_interactive,
|
714 |
inputs=[],
|
715 |
outputs=sandbox_html
|
716 |
)
|
717 |
|
718 |
-
|
719 |
demo.load(
|
720 |
fn=initialize_session,
|
721 |
inputs=[is_interactive],
|
|
|
451 |
return obj
|
452 |
|
453 |
|
454 |
+
def save_final_status(folder, status: str, summary, error_message = None) -> None:
|
455 |
metadata_path = os.path.join(folder, "metadata.json")
|
456 |
+
output_file = open(metadata_path,"w")
|
457 |
+
output_file.write(json.dumps({"status":status, "summary":summary, "error_message": error_message}, default=chat_message_to_json))
|
458 |
+
output_file.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
|
460 |
def initialize_session(interactive_mode, request: gr.Request):
|
461 |
session_hash = request.session_hash
|
|
|
498 |
os.makedirs(data_dir)
|
499 |
|
500 |
|
501 |
+
if "agent" in session_state:
|
502 |
+
session_state["agent"].data_dir = data_dir # Update data dir to new interaction
|
503 |
+
else:
|
504 |
session_state["agent"] = create_agent(data_dir=data_dir, desktop=desktop)
|
505 |
|
506 |
+
|
507 |
# Construct the full task with instructions
|
508 |
full_task = task_input + dedent(f"""
|
509 |
The desktop has a resolution of {WIDTH}x{HEIGHT}, take it into account to decide clicking coordinates.
|
|
|
533 |
yield stored_messages
|
534 |
|
535 |
yield stored_messages
|
536 |
+
# THIS ERASES IMAGES FROM MEMORY, USE WITH CAUTION
|
537 |
+
memory = session_state["agent"].memory
|
538 |
+
for memory_step in memory.steps:
|
539 |
+
if getattr(memory_step, "observations_images", None):
|
540 |
+
memory_step.observations_images = None
|
541 |
+
summary = memory.get_succinct_steps()
|
542 |
+
save_final_status(data_dir, "completed", summary = summary)
|
543 |
|
544 |
# # TODO: uncomment below after testing
|
545 |
except Exception as e:
|
|
|
547 |
stored_messages.append(gr.ChatMessage(role="assistant", content=error_message))
|
548 |
yield stored_messages
|
549 |
raise e
|
550 |
+
save_final_status(data_dir, "failed", summary=[], error_message=error_message)
|
551 |
|
552 |
finally:
|
553 |
upload_to_hf_and_remove(data_dir)
|
|
|
711 |
fn=clear_and_set_view_only,
|
712 |
inputs=[task_input],
|
713 |
outputs=[results_output, sandbox_html, results_container]
|
714 |
+
).then(agent_ui.interact_with_agent, [task_input, stored_messages, session_state, session_hash_state], [chatbot_display]).then(
|
|
|
715 |
fn=set_interactive,
|
716 |
inputs=[],
|
717 |
outputs=sandbox_html
|
718 |
)
|
719 |
|
|
|
720 |
demo.load(
|
721 |
fn=initialize_session,
|
722 |
inputs=[is_interactive],
|