Spaces:
Runtime error
Runtime error
for testing purposes
Browse files- testing_api.py +44 -0
testing_api.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
# API base URL (replace with your actual Hugging Face Space URL)
|
| 6 |
+
API_URL = "https://fbetteo-clip-vit-b-32-test.hf.space"
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_image_embedding(image_url: str) -> dict:
|
| 10 |
+
"""
|
| 11 |
+
Get image embedding from the CLIP API.
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
image_url: URL of the image to process
|
| 15 |
+
|
| 16 |
+
Returns:
|
| 17 |
+
Dictionary containing embedding and dimension
|
| 18 |
+
"""
|
| 19 |
+
endpoint = f"{API_URL}/embed-image"
|
| 20 |
+
payload = {"image_url": image_url}
|
| 21 |
+
|
| 22 |
+
response = requests.post(endpoint, json=payload)
|
| 23 |
+
response.raise_for_status()
|
| 24 |
+
|
| 25 |
+
return response.json()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Example usage
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
# Test image URL
|
| 31 |
+
image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"
|
| 32 |
+
|
| 33 |
+
image_url = "https://cloud.toto.com.uy:9000/Fotos/73-2ZY9D63_PINK_GT22663_1.jpg"
|
| 34 |
+
|
| 35 |
+
try:
|
| 36 |
+
start_time = time.time()
|
| 37 |
+
result = get_image_embedding(image_url)
|
| 38 |
+
end_time = time.time()
|
| 39 |
+
elapsed_time = end_time - start_time
|
| 40 |
+
print(f"Response time: {elapsed_time:.2f} seconds")
|
| 41 |
+
print(f"Embedding dimension: {result['embedding_dimension']}")
|
| 42 |
+
print(f"First 5 values: {result['embedding'][:5]}")
|
| 43 |
+
except requests.exceptions.RequestException as e:
|
| 44 |
+
print(f"Error: {e}")
|