CoolFace
Apppublic

johnwesley756/instance-segmentation

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
test_setup.py128 linesDownload Raw Back to root
1"""2Quick Test Script for Tooth Decay Detection API3Run this to verify the setup is working correctly4"""5 6import os7import sys8 9def test_imports():10    """Test if all required packages are installed"""11    print("=" * 60)12    print("Testing Package Imports...")13    print("=" * 60)14    15    packages = {16        "ultralytics": "YOLO",17        "fastapi": "FastAPI",18        "streamlit": "streamlit",19        "cv2": "opencv-python-headless",20        "PIL": "Pillow",21        "numpy": "numpy",22        "uvicorn": "uvicorn",23        "requests": "requests"24    }25    26    all_good = True27    for module, package in packages.items():28        try:29            __import__(module)30            print(f"✓ {package:30} - OK")31        except ImportError:32            print(f"✗ {package:30} - MISSING")33            all_good = False34    35    return all_good36 37def test_model():38    """Test if model file exists and can be loaded"""39    print("\n" + "=" * 60)40    print("Testing Model...")41    print("=" * 60)42    43    model_path = "best.pt"44    45    if not os.path.exists(model_path):46        print(f"✗ Model file '{model_path}' not found!")47        return False48    49    print(f"✓ Model file exists: {model_path}")50    print(f"  Size: {os.path.getsize(model_path) / (1024*1024):.2f} MB")51    52    try:53        from ultralytics import YOLO54        model = YOLO(model_path)55        print(f"✓ Model loaded successfully!")56        print(f"  Classes: {list(model.names.values())}")57        return True58    except Exception as e:59        print(f"✗ Failed to load model: {e}")60        return False61 62def test_files():63    """Test if all required files exist"""64    print("\n" + "=" * 60)65    print("Testing Required Files...")66    print("=" * 60)67    68    required_files = [69        "api.py",70        "app.py",71        "best.pt",72        "requirements.txt",73        "Dockerfile",74        "start.sh",75        "start.bat",76        "README.md"77    ]78    79    all_good = True80    for file in required_files:81        if os.path.exists(file):82            print(f"✓ {file:30} - Found")83        else:84            print(f"✗ {file:30} - Missing")85            all_good = False86    87    return all_good88 89def main():90    print("\n")91    print("╔" + "=" * 58 + "╗")92    print("║" + " " * 10 + "Tooth Decay Detection - Setup Test" + " " * 14 + "║")93    print("╚" + "=" * 58 + "╝")94    print()95    96    results = {97        "Files": test_files(),98        "Packages": test_imports(),99        "Model": test_model()100    }101    102    print("\n" + "=" * 60)103    print("Summary")104    print("=" * 60)105    106    for test, passed in results.items():107        status = "✓ PASS" if passed else "✗ FAIL"108        print(f"{test:20} : {status}")109    110    print("\n" + "=" * 60)111    112    if all(results.values()):113        print("✓ All tests passed! You're ready to go!")114        print("\nNext steps:")115        print("1. Start FastAPI:  uvicorn api:app --host 0.0.0.0 --port 8000")116        print("2. Start Streamlit: streamlit run app.py --server.port 7860")117        print("3. Or use: start.bat (Windows) or ./start.sh (Linux/Mac)")118    else:119        print("✗ Some tests failed. Please fix the issues above.")120        print("\nTo install missing packages:")121        print("  pip install -r requirements.txt")122    123    print("=" * 60)124    print()125 126if __name__ == "__main__":127    main()128