File size: 3,876 Bytes
355774b | 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | #!/usr/bin/env python3
"""
Test script for Devam Jersey Server
"""
import requests
import json
from PIL import Image
import numpy as np
import io
def create_test_image():
"""Create a simple test image"""
# Create a 224x224 RGB test image
img_array = np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)
img = Image.fromarray(img_array)
# Convert to bytes
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='PNG')
img_byte_arr = img_byte_arr.getvalue()
return img_byte_arr
def test_endpoints(base_url="http://localhost:7860"):
"""Test all endpoints of the server"""
print(f"π§ͺ Testing server at {base_url}")
print("=" * 50)
# Test root endpoint
try:
response = requests.get(f"{base_url}/")
if response.status_code == 200:
print("β
Root endpoint working")
data = response.json()
print(f" Status: {data.get('status')}")
print(f" Models loaded: {data.get('models_loaded')}")
else:
print(f"β Root endpoint failed: {response.status_code}")
except Exception as e:
print(f"β Root endpoint error: {e}")
# Test DINO endpoint
try:
test_image = create_test_image()
files = {'file': ('test.png', test_image, 'image/png')}
response = requests.post(f"{base_url}/dino", files=files)
if response.status_code == 200:
print("β
DINO endpoint working")
data = response.json()
print(f" Features length: {len(data.get('features', []))}")
else:
print(f"β DINO endpoint failed: {response.status_code}")
print(f" Response: {response.text}")
except Exception as e:
print(f"β DINO endpoint error: {e}")
# Test FAISS endpoint
try:
# Create dummy features (768-dimensional for DINOv2 base)
dummy_features = np.random.random(768).tolist()
payload = {"features": dummy_features}
response = requests.post(f"{base_url}/faiss", json=payload)
if response.status_code == 200:
print("β
FAISS endpoint working")
data = response.json()
results = data.get('results', [])
print(f" Results count: {len(results)}")
else:
print(f"β FAISS endpoint failed: {response.status_code}")
print(f" Response: {response.text}")
except Exception as e:
print(f"β FAISS endpoint error: {e}")
# Test YOLO endpoint
try:
test_image = create_test_image()
files = {'file': ('test.png', test_image, 'image/png')}
response = requests.post(f"{base_url}/yolo", files=files)
if response.status_code == 200:
print("β
YOLO endpoint working")
data = response.json()
polygons = data.get('polygons', [])
print(f" Polygons found: {len(polygons)}")
else:
print(f"β YOLO endpoint failed: {response.status_code}")
print(f" Response: {response.text}")
except Exception as e:
print(f"β YOLO endpoint error: {e}")
def main():
print("π Devam Jersey Server - Local Test")
print("=" * 50)
# Check if server is running
try:
response = requests.get("http://localhost:7860/", timeout=5)
print("β
Server is running locally")
test_endpoints()
except requests.exceptions.ConnectionError:
print("β Server is not running locally")
print("\nπ To start the server locally:")
print("1. Install dependencies: pip install -r requirements.txt")
print("2. Start server: python inference_server.py")
print("3. Run this test again")
except Exception as e:
print(f"β Error testing server: {e}")
if __name__ == "__main__":
main()
|