Lemontropia-Suite/verify_vision.py

99 lines
2.9 KiB
Python

"""
Verify and fix Computer Vision dependencies
"""
import subprocess
import sys
def check_torch():
"""Check PyTorch installation."""
try:
import torch
print(f"✅ PyTorch {torch.__version__} installed")
print(f" CUDA available: {torch.cuda.is_available()}")
return True
except Exception as e:
print(f"❌ PyTorch error: {e}")
return False
def check_paddle():
"""Check PaddlePaddle installation."""
try:
import paddle
print(f"✅ PaddlePaddle {paddle.__version__} installed")
return True
except Exception as e:
print(f"❌ PaddlePaddle error: {e}")
return False
def check_paddleocr():
"""Check PaddleOCR installation."""
try:
from paddleocr import PaddleOCR
print(f"✅ PaddleOCR installed")
return True
except Exception as e:
print(f"❌ PaddleOCR error: {e}")
return False
def check_opencv():
"""Check OpenCV installation."""
try:
import cv2
print(f"✅ OpenCV {cv2.__version__} installed")
return True
except Exception as e:
print(f"❌ OpenCV error: {e}")
return False
def install_fix():
"""Install working versions."""
print("\n🔧 Installing fixed versions...")
packages = [
"torch==2.1.2",
"torchvision==0.16.2",
"--index-url", "https://download.pytorch.org/whl/cpu"
]
print("Installing PyTorch CPU version...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "--force-reinstall"] + packages)
print("Installing PaddlePaddle...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "--force-reinstall", "paddlepaddle==2.5.2"])
print("Installing PaddleOCR...")
subprocess.check_call([sys.executable, "-m", "pip", "install", "--force-reinstall", "paddleocr==2.7.0.3"])
print("\n✅ Installation complete!")
if __name__ == "__main__":
print("=" * 50)
print("Computer Vision Dependency Check")
print("=" * 50)
print()
all_ok = True
all_ok &= check_torch()
all_ok &= check_paddle()
all_ok &= check_paddleocr()
all_ok &= check_opencv()
print()
print("=" * 50)
if all_ok:
print("✅ All dependencies OK! Computer Vision should work.")
else:
print("❌ Some dependencies missing or broken.")
response = input("\nWould you like to auto-fix? (y/n): ")
if response.lower() == 'y':
install_fix()
print("\nPlease restart the app.")
else:
print("\nManual fix instructions:")
print("1. pip uninstall torch torchvision paddlepaddle paddleocr")
print("2. pip install torch==2.1.2 torchvision==0.16.2 --index-url https://download.pytorch.org/whl/cpu")
print("3. pip install paddlepaddle==2.5.2 paddleocr==2.7.0.3")
print()
input("Press Enter to exit...")