Spaces:
Running
Running
File size: 1,260 Bytes
f9130b9 20e9ec8 f9130b9 |
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 |
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}")
|