import requests import json import time # API base URL (replace with your actual Hugging Face Space URL) API_URL = "https://fbetteo-clip-vit-b-32-test.hf.space" def get_image_embedding(image_url: str) -> dict: """ Get image embedding from the CLIP API. Args: image_url: URL of the image to process Returns: Dictionary containing embedding and dimension """ endpoint = f"{API_URL}/embed-image" payload = {"image_url": image_url} response = requests.post(endpoint, json=payload) response.raise_for_status() return response.json() # Example usage if __name__ == "__main__": # Test image URL image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png" try: start_time = time.time() result = get_image_embedding(image_url) end_time = time.time() elapsed_time = end_time - start_time print(f"Response time: {elapsed_time:.2f} seconds") print(f"Embedding dimension: {result['embedding_dimension']}") print(f"First 5 values: {result['embedding'][:5]}") except requests.exceptions.RequestException as e: print(f"Error: {e}")