Spaces:
Sleeping
Sleeping
File size: 1,617 Bytes
842ca78 |
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 |
import os
import json
from agents.visual_analyst import VisualAnalyst
def test_gemini_visual_analyst():
print("π Starting Visual Analyst Test (Gemini 1.5 Flash)...")
# 1. Initialize
try:
agent = VisualAnalyst()
except Exception as e:
print(f"β Failed to initialize VisualAnalyst: {e}")
return
# 2. Define Image Path (Use a known existing image or creating dummy if needed,
# but better to use one if available. previous context showed 'test_image.jpg')
image_path = "test_image.jpg"
if not os.path.exists(image_path):
print(f"β οΈ {image_path} not found. Using 'screen.jpg' if available or skipping.")
image_path = "screen.jpg"
if not os.path.exists(image_path):
print("β No test image found.")
return
print(f"πΈ Analyzing image: {image_path}")
# 3. Analyze
try:
result = agent.analyze_image(image_path)
print("β
Raw Result:", result)
# 4. Verify Structure
required_keys = ["main_color", "product_type", "design_style", "visual_features"]
missing = [k for k in required_keys if k not in result]
if missing:
print(f"β Missing keys in JSON: {missing}")
else:
print("β
JSON Structure Validated")
print("π¨ Main Color:", result.get("main_color"))
print("π¦ Product Type:", result.get("product_type"))
except Exception as e:
print(f"β Analysis failed with exception: {e}")
if __name__ == "__main__":
test_gemini_visual_analyst()
|