Spaces:
Runtime error
Runtime error
File size: 1,606 Bytes
290ff9e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """Smoke test for the Image Analyzer node.
Runs the analyzer on the sample images from datasources/report-sample.json
using the real API. Requires ANTHROPIC_API_KEY (or whichever provider is
configured in the default model config).
Usage:
uv run python scripts/test_image_analyzer.py
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
from dotenv import load_dotenv
REPORT_SAMPLE_FILE = (
Path(__file__).resolve().parents[1] / "docs" / "datasources" / "report-sample.json"
)
from ergo_agentic.nodes.image_analyzer import analyze_image
from ergo_agentic.state import ImageInput
def main() -> int:
load_dotenv()
with REPORT_SAMPLE_FILE.open() as f:
report = json.load(f)
urls = report.get("uploadedImages", [])
if not urls:
print("No images in sample report", file=sys.stderr)
return 1
print(f"Analyzing {len(urls)} images sequentially...\n")
for i, url in enumerate(urls, start=1):
image: ImageInput = {
"image_id": f"img_{i}",
"url": url,
"label": None,
}
print(f"--- Image {i}: {url} ---")
try:
result = analyze_image(
{"image": image, "model_id": "google_genai:gemini-2.5-flash"}
)
manifest = result["image_manifests"][0]
print(manifest.model_dump_json(indent=2))
except Exception as e:
print(f"ERROR: {e}")
print()
return 0
if __name__ == "__main__":
sys.exit(main())
|