Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fixes for Image2Struct #2890

Merged
merged 10 commits into from
Aug 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import tempfile

from helm.benchmark.annotation.image2structure.image_compiler_annotator import ImageCompilerAnnotator, CompilationError
from helm.benchmark.annotation.image2struct.image_compiler_annotator import ImageCompilerAnnotator, CompilationError
from helm.benchmark.adaptation.request_state import RequestState
from helm.common.cache import CacheConfig
from helm.common.optional_dependencies import handle_module_not_found_error, OptionalDependencyNotInstalled
Expand Down
4 changes: 2 additions & 2 deletions src/helm/benchmark/presentation/run_entries_image2struct.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ entries: [
{description: "image2webpage:subset=javascript,difficulty=hard,model=vlm", priority: 1}

# wild examples
{description: "image2webpage:subset=real,model=vlm", priority: 1}
{description: "image2latex:subset=real,model=vlm", priority: 1}
{description: "image2webpage:subset=wild,model=vlm", priority: 1}
{description: "image2latex:subset=wild,model=vlm", priority: 1}
]
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,3 @@ def latex_to_image(
return handle_latex_error(e, original_latex_code, assets_path, crop, resize_to, num_try_remaining)
except Exception as e:
return handle_latex_error(e, original_latex_code, assets_path, crop, resize_to, num_try_remaining)


if __name__ == "__main__":
with open("/home/josselin/helm/test.txt", "r") as file:
latex_code = file.read()
image, infos = latex_to_image(latex_code, assets_path=".", crop=True)
image.save("test.png")
print(infos)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, List, Any
from typing import Dict, List, Any, Optional

from helm.benchmark.scenarios.scenario import VALID_SPLIT
from helm.benchmark.scenarios.vision_language.image2struct.image2struct_scenario import (
Expand Down Expand Up @@ -77,22 +77,25 @@ def serve_and_take_screenshot(

# Take a screenshot of a random page
success = False
error: Exception
error: Optional[Exception] = None

for _ in range(max_tries):
try:
infos: Dict[str, Any] = save_random_screenshot(destination_path, port=port, options=screenshot_options)
success = True
break
except Exception as e:
error = e

if "net::ERR_CONNECTION_REFUSED" in str(e):
error = e
server.stop()
time.sleep(0.5)
server.start()
time.sleep(0.5)
else:
# Do not retry
break

if not success:
raise ValueError(f"Failed to take a screenshot: {error}")

Expand Down