Spaces:
Build error
Build error
File size: 947 Bytes
837e221 |
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 |
import io
from typing import Dict, Any
import requests
from PIL import Image
from smolagents import tool
@tool
def analyze_image(image_url: str) -> Dict[str, Any]:
"""
Analyze an image and extract information from it.
Args:
image_url: URL of the image to analyze
Returns:
Dictionary containing information about the image
"""
try:
# Download the image
response = requests.get(image_url)
response.raise_for_status()
# Open the image
img = Image.open(io.BytesIO(response.content))
# Extract basic image information
width, height = img.size
format_type = img.format
mode = img.mode
return {
"width": width,
"height": height,
"format": format_type,
"mode": mode,
"aspect_ratio": width / height,
}
except Exception as e:
return {"error": str(e)} |