|
1 | 1 | import base64 |
| 2 | +import html |
2 | 3 | import os |
3 | 4 | import traceback |
4 | 5 | from copy import deepcopy |
|
18 | 19 | from PIL import Image |
19 | 20 |
|
20 | 21 | from agentlab.analyze import inspect_results |
| 22 | +from agentlab.analyze.episode_to_html import exp_result_to_html |
21 | 23 | from agentlab.analyze.overlay_utils import annotate_action |
22 | 24 | from agentlab.experiments.exp_utils import RESULTS_DIR |
23 | 25 | from agentlab.experiments.loop import ExpResult, StepInfo |
24 | 26 | from agentlab.experiments.study import get_most_recent_study |
25 | 27 | from agentlab.llm.chat_api import make_system_message, make_user_message |
26 | 28 | from agentlab.llm.llm_utils import BaseMessage as AgentLabBaseMessage |
27 | 29 | from agentlab.llm.llm_utils import Discussion |
28 | | -from agentlab.llm.response_api import MessageBuilder |
29 | | -from agentlab.llm.response_api import ToolCalls |
| 30 | +from agentlab.llm.response_api import MessageBuilder, ToolCalls |
30 | 31 |
|
31 | 32 | select_dir_instructions = "Select Experiment Directory" |
32 | 33 | AGENT_NAME_KEY = "agent.agent_name" |
@@ -349,6 +350,9 @@ def run_gradio(results_dir: Path): |
349 | 350 | preview=True, |
350 | 351 | ) |
351 | 352 |
|
| 353 | + with gr.Tab("Episode") as tab_episode: |
| 354 | + episode = gr.HTML() |
| 355 | + |
352 | 356 | with gr.Tab("DOM HTML") as tab_html: |
353 | 357 | html_code = gr.Code(language="html", **code_args) |
354 | 358 |
|
@@ -458,6 +462,7 @@ def run_gradio(results_dir: Path): |
458 | 462 | outputs=[screenshot_gallery], |
459 | 463 | ) |
460 | 464 | screenshot_gallery.select(fn=gallery_step_change, inputs=episode_id, outputs=step_id) |
| 465 | + episode_id.change(fn=if_active("Episode")(update_episode), outputs=episode) |
461 | 466 | step_id.change(fn=if_active("DOM HTML")(update_html), outputs=html_code) |
462 | 467 | step_id.change( |
463 | 468 | fn=if_active("Pruned DOM HTML")(update_pruned_html), outputs=pruned_html_code |
@@ -486,6 +491,7 @@ def run_gradio(results_dir: Path): |
486 | 491 | tab_screenshot_gallery.select( |
487 | 492 | fn=update_screenshot_gallery, inputs=som_or_not, outputs=[screenshot_gallery] |
488 | 493 | ) |
| 494 | + tab_episode.select(fn=update_episode, outputs=episode) |
489 | 495 | tab_html.select(fn=update_html, outputs=html_code) |
490 | 496 | tab_pruned_html.select(fn=update_pruned_html, outputs=pruned_html_code) |
491 | 497 | tab_axtree.select(fn=update_axtree, outputs=axtree_code) |
@@ -649,6 +655,18 @@ def gallery_step_change(evt: gr.SelectData, episode_id: EpisodeId): |
649 | 655 | return StepId(episode_id=episode_id, step=evt.index) |
650 | 656 |
|
651 | 657 |
|
| 658 | +# def update_episode(): |
| 659 | +# # get exp_results for the given episode_id |
| 660 | +# return exp_result_to_html(info.exp_result) |
| 661 | +def update_episode(): |
| 662 | + html_content = exp_result_to_html(info.exp_result) |
| 663 | + |
| 664 | + # Use srcdoc instead of data URL |
| 665 | + return f"""<iframe srcdoc="{html.escape(html_content, quote=True)}" |
| 666 | + style="width: 100%; height: 800px; border: none; background-color: white;"> |
| 667 | + </iframe>""" |
| 668 | + |
| 669 | + |
652 | 670 | def update_html(): |
653 | 671 | return get_obs(key="dom_txt", default="No DOM HTML") |
654 | 672 |
|
|
0 commit comments