| 1234567891011121314151617 |
- import os
- import vertexai
- from vertexai.vision_models import Image, MultiModalEmbeddingModel
- from typing import List
- class VertexVisionService:
- def __init__(self, project_id: str, location: str):
- # Ensure credentials are set before init if using service account key
- # os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "gemini-service-key.json"
- vertexai.init(project=project_id, location=location)
- self.model = MultiModalEmbeddingModel.from_pretrained("multimodalembedding@001")
- def get_image_embedding(self, image_path: str) -> List[float]:
- image = Image.load_from_file(image_path)
- # Standardizing to 1408 dimensions for consistency
- embeddings = self.model.get_embeddings(image=image, dimension=1408)
- return embeddings.image_embedding
|