Devam / test_server.py
Devam0's picture
corrections
355774b
Raw
History Blame Contribute Delete
3.88 kB
#!/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()