Spaces:
Sleeping
Sleeping
#!/usr/bin/env python3 | |
""" | |
Simple test script for the embedding API | |
""" | |
import requests | |
import json | |
import time | |
def test_api(base_url="https://aurasystems-spanish-embeddings-api.hf.space"): | |
"""Test the API endpoints""" | |
print(f"Testing API at {base_url}") | |
# Test root endpoint | |
try: | |
response = requests.get(f"{base_url}/") | |
print(f"✓ Root endpoint: {response.status_code}") | |
print(f" Response: {response.json()}") | |
except Exception as e: | |
print(f"✗ Root endpoint failed: {e}") | |
return False | |
# Test health endpoint | |
try: | |
response = requests.get(f"{base_url}/health") | |
print(f"✓ Health endpoint: {response.status_code}") | |
health_data = response.json() | |
print(f" Models loaded: {health_data.get('models_loaded', False)}") | |
print(f" Available models: {health_data.get('available_models', [])}") | |
except Exception as e: | |
print(f"✗ Health endpoint failed: {e}") | |
# Test models endpoint | |
try: | |
response = requests.get(f"{base_url}/models") | |
print(f"✓ Models endpoint: {response.status_code}") | |
models = response.json() | |
print(f" Found {len(models)} model definitions") | |
except Exception as e: | |
print(f"✗ Models endpoint failed: {e}") | |
# Test embedding endpoint | |
try: | |
payload = { | |
"texts": ["Hello world", "Test text"], | |
"model": "jina", | |
"normalize": True | |
} | |
response = requests.post(f"{base_url}/embed", json=payload) | |
print(f"✓ Embed endpoint: {response.status_code}") | |
if response.status_code == 200: | |
data = response.json() | |
print(f" Generated {data.get('num_texts', 0)} embeddings") | |
print(f" Dimensions: {data.get('dimensions', 0)}") | |
else: | |
print(f" Error: {response.text}") | |
except Exception as e: | |
print(f"✗ Embed endpoint failed: {e}") | |
return True | |
if __name__ == "__main__": | |
test_api() |