| |
| """ |
| Quick test script to trigger a prediction and see full logs. |
| Creates a dummy tissue image and runs through diagnosis endpoint. |
| """ |
|
|
| import sys |
| import os |
| import requests |
| import json |
| from pathlib import Path |
|
|
| |
| sys.path.insert(0, str(Path(__file__).parent / "backend")) |
|
|
| import numpy as np |
| from PIL import Image |
| import io |
|
|
| |
| API_URL = "http://localhost:8000/api" |
| TEST_IMAGE_SIZE = (224, 224) |
|
|
| def create_dummy_tissue_image() -> bytes: |
| """Create a simple synthetic tissue-like image for testing.""" |
| |
| img_array = np.random.randint(50, 200, (TEST_IMAGE_SIZE[0], TEST_IMAGE_SIZE[1], 3), dtype=np.uint8) |
| |
| |
| for _ in range(10): |
| y, x = np.random.randint(0, TEST_IMAGE_SIZE[0], 2) |
| radius = np.random.randint(5, 30) |
| yy, xx = np.ogrid[:TEST_IMAGE_SIZE[0], :TEST_IMAGE_SIZE[1]] |
| mask = (yy - y)**2 + (xx - x)**2 <= radius**2 |
| img_array[mask] = np.random.randint(30, 180, 3, dtype=np.uint8) |
| |
| |
| img = Image.fromarray(img_array, 'RGB') |
| |
| |
| img_bytes = io.BytesIO() |
| img.save(img_bytes, format='JPEG') |
| img_bytes.seek(0) |
| return img_bytes.getvalue() |
|
|
| def test_diagnosis(): |
| """Test diagnosis prediction endpoint.""" |
| print("\n" + "="*80) |
| print("π§ͺ TESTING DIAGNOSIS PREDICTION") |
| print("="*80 + "\n") |
| |
| |
| print("1οΈβ£ Creating dummy tissue image...") |
| image_bytes = create_dummy_tissue_image() |
| print(f" β
Image created: {len(image_bytes)} bytes\n") |
| |
| |
| print("2οΈβ£ Preparing diagnosis request...") |
| |
| files = {'file': ('test.jpg', image_bytes, 'image/jpeg')} |
| |
| |
| print("3οΈβ£ Calling /api/diagnosis/upload-and-predict endpoint...") |
| print(f" URL: {API_URL}/diagnosis/upload-and-predict\n") |
| |
| try: |
| response = requests.post( |
| f"{API_URL}/diagnosis/upload-and-predict", |
| files=files, |
| timeout=60 |
| ) |
| |
| print(f"\n Status Code: {response.status_code}") |
| |
| if response.status_code == 200: |
| result = response.json() |
| print("\nβ
PREDICTION SUCCESSFUL!\n") |
| print(json.dumps(result, indent=2)) |
| else: |
| print(f"\nβ ERROR: {response.status_code}") |
| print(response.text) |
| |
| except Exception as e: |
| print(f"\nβ EXCEPTION: {e}") |
| import traceback |
| traceback.print_exc() |
| |
| print("\n" + "="*80) |
| print("π CHECK BACKEND TERMINAL FOR DETAILED LOGS:") |
| print(" - Disease order mapping") |
| print(" - Raw prediction logits") |
| print(" - Label mappings") |
| print("="*80 + "\n") |
|
|
| if __name__ == "__main__": |
| print(""" |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| β CYTOSIGHT PREDICTION TEST β |
| β β |
| β This script will: β |
| β 1. Create a dummy tissue image β |
| β 2. Send it to the diagnosis endpoint β |
| β 3. Print the response β |
| β β |
| β π WATCH THE BACKEND TERMINAL FOR FULL LOGS! β |
| β Look for the emoji-decorated log lines showing: β |
| β - Disease order [0][1][2]... β |
| β - Raw logits and probabilities β |
| β - Label mapping results β |
| β β |
| β Terminal ID: 48f1e260-090b-4bf9-9017-686ad61d2015 β |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ |
| """) |
| |
| test_diagnosis() |
|
|