| |
| """ |
| 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""" |
| |
| img_array = np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8) |
| img = Image.fromarray(img_array) |
| |
| |
| 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) |
| |
| |
| 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}") |
| |
| |
| 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}") |
| |
| |
| try: |
| |
| 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}") |
| |
| |
| 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) |
| |
| |
| 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() |
|
|