Spaces:
Runtime error
Runtime error
File size: 844 Bytes
bbf59eb 1bc7525 bbf59eb 1bc7525 bbf59eb 1bc7525 bbf59eb 1bc7525 bbf59eb 1bc7525 bbf59eb 1bc7525 bbf59eb 1bc7525 |
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 |
from concurrent.futures import ThreadPoolExecutor
from typing import Dict, List
from dotenv import load_dotenv
from google.cloud import vision
from code_tasks.image_dimensions import get_image_dimensions
load_dotenv()
def get_image_info(url: str) -> Dict:
client = vision.ImageAnnotatorClient()
image = vision.Image()
image.source.image_uri = url # type: ignore
response = client.label_detection(image=image) # type: ignore
labels = [label.description for label in response.label_annotations]
dimensions = get_image_dimensions(url)
return {
"url": url,
"labels": ", ".join(labels),
"dimensions": f"{dimensions[0]}x{dimensions[1]}",
}
def get_info_for_images(urls) -> List[Dict]:
with ThreadPoolExecutor() as executor:
return list(executor.map(get_image_info, urls))
|