Spaces:
Sleeping
Sleeping
Update visualizer.py
Browse files- visualizer.py +1 -202
visualizer.py
CHANGED
|
@@ -1,204 +1,3 @@
|
|
| 1 |
-
# import os
|
| 2 |
-
# import glob
|
| 3 |
-
# import json
|
| 4 |
-
# import base64
|
| 5 |
-
# import pandas as pd
|
| 6 |
-
# import gradio as gr
|
| 7 |
-
# import re
|
| 8 |
-
|
| 9 |
-
# # --- Data Loading ---
|
| 10 |
-
# ABS_DATA_PATH = "data"
|
| 11 |
-
# if os.path.exists(ABS_DATA_PATH):
|
| 12 |
-
# os.chdir(ABS_DATA_PATH)
|
| 13 |
-
|
| 14 |
-
# AITW_DATA_ROOT = "."
|
| 15 |
-
|
| 16 |
-
# MODEL_DISPLAY_MAPPING = {
|
| 17 |
-
# "gpt": "GPT-4o",
|
| 18 |
-
# "gemini": "Gemini 2.5 Pro",
|
| 19 |
-
# "qwen": "Qwen 2.5 VL 72B"
|
| 20 |
-
# }
|
| 21 |
-
# MODELS_IN_ORDER = ["gpt", "gemini", "qwen"]
|
| 22 |
-
|
| 23 |
-
# def image_to_base64_markdown(img_path):
|
| 24 |
-
# if not img_path or not os.path.exists(img_path):
|
| 25 |
-
# return "Image not found"
|
| 26 |
-
# try:
|
| 27 |
-
# with open(img_path, "rb") as f:
|
| 28 |
-
# encoded = base64.b64encode(f.read()).decode("utf-8")
|
| 29 |
-
# ext = os.path.splitext(img_path)[-1].lstrip(".").lower()
|
| 30 |
-
# if ext not in ['png', 'jpg', 'jpeg', 'gif', 'bmp']:
|
| 31 |
-
# ext = 'png'
|
| 32 |
-
# return f""
|
| 33 |
-
# except Exception as e:
|
| 34 |
-
# print(f"Error encoding image {img_path}: {e}")
|
| 35 |
-
# return "Error loading image"
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
# def load_and_prepare_data(data_root_path):
|
| 39 |
-
# primary_model_dir = os.path.join(data_root_path, MODELS_IN_ORDER[0])
|
| 40 |
-
# if not os.path.isdir(primary_model_dir):
|
| 41 |
-
# print(f"Error: Primary model directory not found at '{primary_model_dir}'")
|
| 42 |
-
# return pd.DataFrame()
|
| 43 |
-
|
| 44 |
-
# all_rows = []
|
| 45 |
-
|
| 46 |
-
# json_files = glob.glob(os.path.join(primary_model_dir, "*.json"))
|
| 47 |
-
|
| 48 |
-
# for json_path in json_files:
|
| 49 |
-
# with open(json_path, 'r', encoding='utf-8') as f:
|
| 50 |
-
# data = json.load(f)
|
| 51 |
-
|
| 52 |
-
# for episode_id, episode_data in data.items():
|
| 53 |
-
# episode_goal = episode_data.get("episode_goal", "N/A")
|
| 54 |
-
|
| 55 |
-
# for step in episode_data.get("steps", []):
|
| 56 |
-
# question_block = step.get("questions", {})
|
| 57 |
-
# question = question_block.get("question", "N/A")
|
| 58 |
-
# options = question_block.get("options", [])
|
| 59 |
-
# answer_index = question_block.get("correct_answer_index")
|
| 60 |
-
|
| 61 |
-
# valid_answer_index = -1
|
| 62 |
-
# if answer_index is not None:
|
| 63 |
-
# try:
|
| 64 |
-
# valid_answer_index = int(answer_index)
|
| 65 |
-
# except (ValueError, TypeError):
|
| 66 |
-
# pass
|
| 67 |
-
|
| 68 |
-
# formatted_options = "\n".join(f"{i+1}. {opt}" for i, opt in enumerate(options))
|
| 69 |
-
|
| 70 |
-
# correct_option_text = "N/A"
|
| 71 |
-
# if 0 <= valid_answer_index < len(options):
|
| 72 |
-
# correct_option_text = options[valid_answer_index]
|
| 73 |
-
|
| 74 |
-
# image_markdown = {}
|
| 75 |
-
# base_screenshot_path = step.get("screenshot_path", "").lstrip("/")
|
| 76 |
-
|
| 77 |
-
# for model_key in MODELS_IN_ORDER:
|
| 78 |
-
# img_path = os.path.join(data_root_path, model_key, base_screenshot_path)
|
| 79 |
-
# image_markdown[model_key] = image_to_base64_markdown(img_path)
|
| 80 |
-
|
| 81 |
-
# row = [
|
| 82 |
-
# episode_goal,
|
| 83 |
-
# question,
|
| 84 |
-
# formatted_options,
|
| 85 |
-
# correct_option_text,
|
| 86 |
-
# image_markdown.get("gpt"),
|
| 87 |
-
# image_markdown.get("gemini"),
|
| 88 |
-
# image_markdown.get("qwen")
|
| 89 |
-
# ]
|
| 90 |
-
# all_rows.append(row)
|
| 91 |
-
|
| 92 |
-
# headers = [
|
| 93 |
-
# "Episode Goal", "Question", "Options", "Correct Option",
|
| 94 |
-
# MODEL_DISPLAY_MAPPING["gpt"],
|
| 95 |
-
# MODEL_DISPLAY_MAPPING["gemini"],
|
| 96 |
-
# MODEL_DISPLAY_MAPPING["qwen"]
|
| 97 |
-
# ]
|
| 98 |
-
|
| 99 |
-
# return pd.DataFrame(all_rows, columns=headers)
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
# # --- CSS for the modal overlay ---
|
| 103 |
-
# modal_css = """
|
| 104 |
-
# #image-modal {
|
| 105 |
-
# position: fixed;
|
| 106 |
-
# top: 0;
|
| 107 |
-
# left: 0;
|
| 108 |
-
# width: 100%;
|
| 109 |
-
# height: 100%;
|
| 110 |
-
# background-color: rgba(0, 0, 0, 0.8);
|
| 111 |
-
# display: flex;
|
| 112 |
-
# justify-content: center;
|
| 113 |
-
# align-items: center;
|
| 114 |
-
# z-index: 9999;
|
| 115 |
-
# }
|
| 116 |
-
# #image-modal .modal-content {
|
| 117 |
-
# background-color: white;
|
| 118 |
-
# padding: 20px;
|
| 119 |
-
# border-radius: 10px;
|
| 120 |
-
# max-width: 90vw;
|
| 121 |
-
# max-height: 90vh;
|
| 122 |
-
# display: flex;
|
| 123 |
-
# flex-direction: column;
|
| 124 |
-
# align-items: center;
|
| 125 |
-
# }
|
| 126 |
-
# #image-modal .modal-content img {
|
| 127 |
-
# max-width: 100%;
|
| 128 |
-
# max-height: calc(90vh - 80px);
|
| 129 |
-
# object-fit: contain;
|
| 130 |
-
# }
|
| 131 |
-
# #close-modal-btn {
|
| 132 |
-
# margin-top: 15px;
|
| 133 |
-
# }
|
| 134 |
-
# """
|
| 135 |
-
|
| 136 |
-
# # --- Gradio Interface ---
|
| 137 |
-
# with gr.Blocks(theme=gr.themes.Default(spacing_size=gr.themes.sizes.spacing_sm),
|
| 138 |
-
# css=modal_css) as demo:
|
| 139 |
-
|
| 140 |
-
# gr.Markdown("# AITW Benchmark Visualizer")
|
| 141 |
-
# gr.Markdown("Visual comparison of model outputs for the Android in the Wild (AITW) benchmark.")
|
| 142 |
-
|
| 143 |
-
# full_df_state = gr.State()
|
| 144 |
-
|
| 145 |
-
# display_df = gr.DataFrame(
|
| 146 |
-
# headers=[
|
| 147 |
-
# "Episode Goal", "Question", "Options", "Correct Option",
|
| 148 |
-
# MODEL_DISPLAY_MAPPING["gpt"],
|
| 149 |
-
# MODEL_DISPLAY_MAPPING["gemini"],
|
| 150 |
-
# MODEL_DISPLAY_MAPPING["qwen"]
|
| 151 |
-
# ],
|
| 152 |
-
# datatype=["markdown", "markdown", "markdown", "markdown", "markdown", "markdown", "markdown"],
|
| 153 |
-
# interactive=False,
|
| 154 |
-
# row_count=(20, "dynamic")
|
| 155 |
-
# )
|
| 156 |
-
|
| 157 |
-
# # --- The hidden modal for displaying the zoomed image ---
|
| 158 |
-
# with gr.Column(visible=False, elem_id="image-modal") as modal:
|
| 159 |
-
# # --- FIX: Replaced gr.Box with gr.Column ---
|
| 160 |
-
# with gr.Column(elem_classes=["modal-content"]):
|
| 161 |
-
# modal_image = gr.Image(interactive=False)
|
| 162 |
-
# close_modal_btn = gr.Button("Close", elem_id="close-modal-btn")
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
# def load_initial_data():
|
| 166 |
-
# print(f"Current working directory: {os.getcwd()}")
|
| 167 |
-
# print("Loading and preparing AITW data...")
|
| 168 |
-
# prepared_df = load_and_prepare_data(AITW_DATA_ROOT)
|
| 169 |
-
# if prepared_df.empty:
|
| 170 |
-
# gr.Warning(f"No data loaded. Please check that the '{AITW_DATA_ROOT}' directory is structured correctly.")
|
| 171 |
-
# else:
|
| 172 |
-
# print(f"Successfully loaded {len(prepared_df)} steps.")
|
| 173 |
-
# return prepared_df, prepared_df
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
# def show_image_in_modal(df_state, evt: gr.SelectData):
|
| 177 |
-
# if evt.index is None or evt.value is None:
|
| 178 |
-
# return gr.update(visible=False), gr.update(visible=False)
|
| 179 |
-
|
| 180 |
-
# if evt.index[1] not in [4, 5, 6]:
|
| 181 |
-
# return gr.update(visible=False), gr.update(visible=False)
|
| 182 |
-
|
| 183 |
-
# match = re.search(r'\(data:image/[^)]+\)', evt.value)
|
| 184 |
-
# if not match:
|
| 185 |
-
# return gr.update(visible=False), gr.update(visible=False)
|
| 186 |
-
|
| 187 |
-
# image_data_uri = match.group(0).strip('()')
|
| 188 |
-
|
| 189 |
-
# return gr.update(visible=True), gr.update(value=image_data_uri, visible=True)
|
| 190 |
-
|
| 191 |
-
# def close_modal():
|
| 192 |
-
# return gr.update(visible=False), gr.update(visible=False)
|
| 193 |
-
|
| 194 |
-
# # --- Event Wiring ---
|
| 195 |
-
# demo.load(fn=load_initial_data, inputs=None, outputs=[display_df, full_df_state])
|
| 196 |
-
# display_df.select(fn=show_image_in_modal, inputs=[full_df_state], outputs=[modal, modal_image], show_progress=False)
|
| 197 |
-
# close_modal_btn.click(fn=close_modal, inputs=None, outputs=[modal, modal_image], show_progress=False)
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
# if __name__ == "__main__":
|
| 201 |
-
# demo.launch(share=True, debug=True)
|
| 202 |
|
| 203 |
import os
|
| 204 |
import glob
|
|
@@ -217,7 +16,7 @@ if os.path.exists(ABS_DATA_PATH):
|
|
| 217 |
AITW_DATA_ROOT = "."
|
| 218 |
|
| 219 |
MODEL_DISPLAY_MAPPING = {
|
| 220 |
-
"gpt": "
|
| 221 |
"gemini": "Gemini 2.5 Pro",
|
| 222 |
"qwen": "Qwen 2.5 VL 72B"
|
| 223 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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