Spaces:
Sleeping
Sleeping
File size: 5,112 Bytes
8b8c9d3 |
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
"""
Test script for BuildTheFuture application
Tests the core functionality without requiring API keys
"""
import os
import sys
from PIL import Image
import numpy as np
def create_test_image():
"""Create a simple test image for testing purposes"""
# Create a simple construction site image
width, height = 400, 300
img = Image.new('RGB', (width, height), color='gray')
# Add some basic construction elements
pixels = np.array(img)
# Add a foundation (dark gray rectangle)
pixels[200:280, 50:350] = [64, 64, 64]
# Add some steel beams (dark lines)
pixels[180:190, 50:350] = [32, 32, 32]
pixels[190:200, 50:350] = [32, 32, 32]
# Add some incomplete walls (light gray)
pixels[120:180, 100:150] = [128, 128, 128]
pixels[120:180, 250:300] = [128, 128, 128]
return Image.fromarray(pixels)
def test_image_processing():
"""Test basic image processing functionality"""
print("π§ͺ Testing image processing...")
try:
# Create test image
test_img = create_test_image()
print("β
Test image created successfully")
# Test image properties
print(f" Image size: {test_img.size}")
print(f" Image mode: {test_img.mode}")
# Save test image
test_img.save("test_construction.jpg")
print("β
Test image saved as 'test_construction.jpg'")
return True
except Exception as e:
print(f"β Image processing test failed: {e}")
return False
def test_imports():
"""Test if all required modules can be imported"""
print("π§ͺ Testing imports...")
modules = [
("gradio", "gr"),
("PIL", "Image"),
("numpy", "np"),
("cv2", "cv2"),
("google.generativeai", "genai"),
("ultralytics", "YOLO"),
("requests", "requests"),
("elevenlabs", "generate"),
]
failed_imports = []
for module_name, alias in modules:
try:
if alias:
exec(f"import {module_name} as {alias}")
else:
exec(f"import {module_name}")
print(f"β
{module_name}")
except ImportError as e:
print(f"β {module_name}: {e}")
failed_imports.append(module_name)
if failed_imports:
print(f"\nβ οΈ Failed imports: {', '.join(failed_imports)}")
print("Run: pip install -r requirements.txt")
return False
print("β
All imports successful")
return True
def test_gradio_interface():
"""Test if Gradio interface can be created"""
print("π§ͺ Testing Gradio interface...")
try:
import gradio as gr
# Create a simple test interface
def test_function(image):
return image
with gr.Blocks() as demo:
gr.Markdown("# Test Interface")
image_input = gr.Image()
image_output = gr.Image()
image_input.change(test_function, inputs=image_input, outputs=image_output)
print("β
Gradio interface created successfully")
return True
except Exception as e:
print(f"β Gradio interface test failed: {e}")
return False
def test_yolo_model():
"""Test YOLO model loading"""
print("π§ͺ Testing YOLO model...")
try:
from ultralytics import YOLO
# Try to load a small YOLO model
model = YOLO('yolov11n.pt')
print("β
YOLO model loaded successfully")
# Test with a simple image
test_img = create_test_image()
results = model(test_img)
print("β
YOLO inference test successful")
return True
except Exception as e:
print(f"β YOLO model test failed: {e}")
return False
def main():
"""Run all tests"""
print("ποΈ BuildTheFuture Test Suite")
print("=" * 50)
tests = [
("Import Test", test_imports),
("Image Processing Test", test_image_processing),
("Gradio Interface Test", test_gradio_interface),
("YOLO Model Test", test_yolo_model),
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"\n{test_name}:")
print("-" * 30)
if test_func():
passed += 1
print()
print("=" * 50)
print(f"Test Results: {passed}/{total} tests passed")
if passed == total:
print("π All tests passed! The application is ready to run.")
print("\nNext steps:")
print("1. Set up your API keys in .env file")
print("2. Run: python app.py")
else:
print("β οΈ Some tests failed. Please fix the issues before running the application.")
return passed == total
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)
|