Skip to content

Commit

Permalink
feat(models): implement search result directory creation and JSON log…
Browse files Browse the repository at this point in the history
…ging in GPT4V_MMMU model
  • Loading branch information
pufanyi committed Dec 16, 2024
1 parent bf5ad24 commit 8abc737
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lmms_eval/models/gpt4v_mmmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
from copy import deepcopy
from io import BytesIO
from pathlib import Path
from typing import List, Tuple, Union

import numpy as np
Expand Down Expand Up @@ -219,6 +220,9 @@ def generate_until(self, requests) -> List[str]:
continue

try:
search_dir = Path("temp") / "search" / task / split / str(doc_id)
if not search_dir.exists():
search_dir.mkdir(parents=True)
visuals = [doc_to_visual(self.task_dict[task][split][doc_id])]
visuals = self.flatten(visuals)
imgs = [] # multiple images or frames for video
Expand Down Expand Up @@ -279,6 +283,18 @@ def generate_until(self, requests) -> List[str]:

search_content = requery.search_text

with open(search_dir / "search_content.json", "w") as f:
json.dump(
{
"doc_id": doc_id,
"contexts": contexts,
"search_content": search_content,
"simple_response": str(simple_response),
"review": review,
},
f,
)

# Search using DuckDuckGo and get first result URL
ddgs = DDGS(timeout=50)
news_results = ddgs.text(keywords=search_content, region="wt-wt", safesearch="off", timelimit="m", max_results=10)
Expand Down Expand Up @@ -309,7 +325,8 @@ def generate_until(self, requests) -> List[str]:
driver.execute_script(f"window.scrollTo(0, {1024 * i})")
time.sleep(1) # Wait for content to load

screenshot_path = f"temp/search_result_{url_idx}_{i}.png"
screenshot_path = search_dir / f"search_result_{url_idx}_{i}.png"

driver.save_screenshot(screenshot_path)

# Load and encode screenshot
Expand Down

0 comments on commit 8abc737

Please sign in to comment.