|
1 | 1 | import base64 |
| 2 | +import json |
2 | 3 | import os |
3 | 4 | import traceback |
4 | 5 | from copy import deepcopy |
|
30 | 31 | TASK_SEED_KEY = "env.task_seed" |
31 | 32 |
|
32 | 33 |
|
| 34 | +def dict_to_markdown(data, level=1): |
| 35 | + """ |
| 36 | + Convert a nested dictionary to a Markdown string with hierarchical headers. |
| 37 | +
|
| 38 | + Parameters: |
| 39 | + data (dict): The dictionary to convert. |
| 40 | + level (int): The current header level (default is 1). |
| 41 | +
|
| 42 | + Returns: |
| 43 | + str: The formatted Markdown string. |
| 44 | + """ |
| 45 | + markdown = "" |
| 46 | + |
| 47 | + for key, value in data.items(): |
| 48 | + if isinstance(value, dict): |
| 49 | + # Add a header for the key and recursively process the dictionary |
| 50 | + markdown += f"{'#' * level} {key}\n" |
| 51 | + markdown += dict_to_markdown(value, level + 1) |
| 52 | + else: |
| 53 | + # Add the key-value pair with indentation |
| 54 | + markdown += f"{'#' * level} {key}\n" |
| 55 | + markdown += f" {value}\n" |
| 56 | + |
| 57 | + return markdown |
| 58 | + |
| 59 | + |
33 | 60 | def display_table(df: pd.DataFrame): |
34 | 61 | df = df.copy() |
35 | 62 | df.columns = clean_column_names(df.columns) |
@@ -358,6 +385,9 @@ def run_gradio(results_dir: Path): |
358 | 385 | with gr.Tab("Task Error") as tab_error: |
359 | 386 | task_error = gr.Markdown() |
360 | 387 |
|
| 388 | + with gr.Tab("Error Analysis") as tab_error_analysis: |
| 389 | + error_analysis = gr.Markdown() |
| 390 | + |
361 | 391 | with gr.Tab("Logs") as tab_logs: |
362 | 392 | logs = gr.Code(language=None, **code_args) |
363 | 393 |
|
@@ -485,6 +515,7 @@ def run_gradio(results_dir: Path): |
485 | 515 | tab_axtree.select(fn=update_axtree, outputs=axtree_code) |
486 | 516 | tab_chat.select(fn=update_chat_messages, outputs=chat_messages) |
487 | 517 | tab_error.select(fn=update_task_error, outputs=task_error) |
| 518 | + tab_error_analysis.select(fn=update_error_analysis, outputs=error_analysis) |
488 | 519 | tab_logs.select(fn=update_logs, outputs=logs) |
489 | 520 | tab_stats.select(fn=update_stats, outputs=stats) |
490 | 521 | tab_agent_info_html.select(fn=update_agent_info_html, outputs=agent_info_html) |
@@ -612,6 +643,20 @@ def update_task_error(): |
612 | 643 | return "No Task Error" |
613 | 644 |
|
614 | 645 |
|
| 646 | +def update_error_analysis(): |
| 647 | + global info |
| 648 | + try: |
| 649 | + error_analysis = info.exp_result.exp_dir / "error_analysis.json" |
| 650 | + if not error_analysis.exists(): |
| 651 | + return "No Error Analysis Found" |
| 652 | + with error_analysis.open("r") as f: |
| 653 | + json_data = json.load(f) |
| 654 | + res = dict_to_markdown(json_data) |
| 655 | + return res |
| 656 | + except FileNotFoundError: |
| 657 | + return "No Error Analysis" |
| 658 | + |
| 659 | + |
615 | 660 | def update_logs(): |
616 | 661 | global info |
617 | 662 | try: |
@@ -1200,3 +1245,4 @@ def main(): |
1200 | 1245 |
|
1201 | 1246 | if __name__ == "__main__": |
1202 | 1247 | main() |
| 1248 | + main() |
0 commit comments