denis26/retrievalapi
0
1#!/usr/bin/env python32"""3Test script to verify Firebase URL and base64 image integration4"""5 6import requests7import json8import base649from PIL import Image10import io11 12# Configuration13BASE_URL = "http://localhost:7860" # Change this to your HF Space URL when deployed14 15def create_test_image():16 """Create a simple test image and return it as base64"""17 # Create a simple test image18 img = Image.new('RGB', (100, 100), color='white')19 img_io = io.BytesIO()20 img.save(img_io, 'JPEG')21 img_io.seek(0)22 return base64.b64encode(img_io.getvalue()).decode('utf-8')23 24def test_base64_image():25 """Test endpoints with base64 encoded image"""26 print("๐ Testing with base64 encoded image...")27 28 # Create a test image29 test_image_b64 = create_test_image()30 31 # Test room detection with base6432 print("\n๐ Testing /detect-rooms with base64 image...")33 try:34 payload = {35 "image_path": f"data:image/jpeg;base64,{test_image_b64}"36 }37 response = requests.post(f"{BASE_URL}/detect-rooms", json=payload)38 print(f" Status Code: {response.status_code}")39 print(f" Response: {response.text[:200]}...")40 41 if response.status_code == 200:42 print(" โ
Base64 image processing successful")43 else:44 print(f" โ ๏ธ Unexpected status code: {response.status_code}")45 except Exception as e:46 print(f" โ Error: {e}")47 48 # Test door detection with base6449 print("\n๐ Testing /detect-doors with base64 image...")50 try:51 payload = {52 "image_path": f"data:image/jpeg;base64,{test_image_b64}"53 }54 response = requests.post(f"{BASE_URL}/detect-doors", json=payload)55 print(f" Status Code: {response.status_code}")56 print(f" Response: {response.text[:200]}...")57 58 if response.status_code == 200:59 print(" โ
Base64 image processing successful")60 else:61 print(f" โ ๏ธ Unexpected status code: {response.status_code}")62 except Exception as e:63 print(f" โ Error: {e}")64 65def test_firebase_url():66 """Test endpoints with Firebase URL (using a placeholder)"""67 print("\n๐ Testing with Firebase URL...")68 69 # Note: This is a placeholder URL - replace with actual Firebase URL70 firebase_url = "https://firebasestorage.googleapis.com/v0/b/your-project/o/blueprint.jpg?alt=media"71 72 print("\n๐ Testing /detect-rooms with Firebase URL...")73 try:74 payload = {75 "image_path": firebase_url76 }77 response = requests.post(f"{BASE_URL}/detect-rooms", json=payload)78 print(f" Status Code: {response.status_code}")79 print(f" Response: {response.text[:200]}...")80 81 if response.status_code in [400, 500]:82 print(" โ
Firebase URL processing attempted (expected error for invalid URL)")83 else:84 print(f" โ ๏ธ Unexpected status code: {response.status_code}")85 except Exception as e:86 print(f" โ Error: {e}")87 88def test_blueprint_comparison():89 """Test blueprint comparison with base64 images"""90 print("\n๐ Testing blueprint comparison with base64 images...")91 92 # Create test images93 test_image_b64 = create_test_image()94 95 try:96 payload = {97 "blueprint_a_path": f"data:image/jpeg;base64,{test_image_b64}",98 "blueprint_b_path": f"data:image/jpeg;base64,{test_image_b64}"99 }100 response = requests.post(f"{BASE_URL}/compare-blueprints", json=payload)101 print(f" Status Code: {response.status_code}")102 print(f" Response: {response.text[:200]}...")103 104 if response.status_code in [200, 503]: # 503 if Gemini not configured105 print(" โ
Blueprint comparison processing successful")106 else:107 print(f" โ ๏ธ Unexpected status code: {response.status_code}")108 except Exception as e:109 print(f" โ Error: {e}")110 111def test_root_endpoint():112 """Test the root endpoint"""113 print("๐ Testing root endpoint...")114 try:115 response = requests.get(f"{BASE_URL}/")116 if response.status_code == 200:117 data = response.json()118 print("โ
Root endpoint working")119 print(f"๐ Available endpoints: {list(data.get('endpoints', {}).keys())}")120 return True121 else:122 print(f"โ Root endpoint failed: {response.status_code}")123 return False124 except Exception as e:125 print(f"โ Root endpoint error: {e}")126 return False127 128if __name__ == "__main__":129 print("๐ Starting Firebase integration tests...")130 print(f"๐ Testing against: {BASE_URL}")131 132 # Test root endpoint first133 if test_root_endpoint():134 # Test base64 images135 test_base64_image()136 137 # Test Firebase URLs138 test_firebase_url()139 140 # Test blueprint comparison141 test_blueprint_comparison()142 else:143 print("โ Cannot test endpoints - root endpoint not working")144 