Spaces:
Running
Running
File size: 4,698 Bytes
c1b7fff | 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 | import sys
import importlib
import subprocess
import platform
import os
from pathlib import Path
def print_status(message, success):
if success:
print(f"\033[92m[✓]\033[0m {message}")
else:
print(f"\033[91m[✗]\033[0m {message}")
def main():
os_name = platform.system()
# Enable ANSI colors for Windows terminal
if os_name == 'Windows':
os.system('color')
print("\n--- MedSight AI Environment Verification ---\n")
all_passed = True
issues = []
# 1. Check Python Version
py_version = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
if py_version == "3.10.13":
print_status(f"Python Version: {py_version}", True)
else:
print_status(f"Python Version: {py_version} (Expected 3.10.13)", False)
all_passed = False
issues.append("Install exact Python 3.10.13 via Conda.")
# 2. Check PyTorch & CUDA
try:
import torch
if torch.__version__.startswith("2.2.0"):
print_status(f"PyTorch Version: {torch.__version__}", True)
else:
print_status(f"PyTorch Version: {torch.__version__} (Expected 2.2.0)", False)
all_passed = False
issues.append("Reinstall PyTorch 2.2.0 for CUDA 11.8.")
if torch.cuda.is_available():
vram_gb = torch.cuda.get_device_properties(0).total_memory / (1024**3)
print_status(f"CUDA Available: YES ({torch.cuda.get_device_name(0)} - {vram_gb:.1f}GB VRAM)", True)
else:
print_status("CUDA Available: NO", False)
all_passed = False
issues.append("CUDA is not accessible. Check NVIDIA drivers and PyTorch CUDA build.")
except ImportError:
print_status("PyTorch not installed", False)
all_passed = False
issues.append("Install PyTorch.")
# 3. Check Transformers
try:
import transformers
if transformers.__version__ == "4.38.2":
print_status(f"Transformers Version: {transformers.__version__}", True)
else:
print_status(f"Transformers Version: {transformers.__version__} (Expected 4.38.2)", False)
all_passed = False
issues.append("Install exact transformers version from requirements.txt.")
except ImportError:
print_status("Transformers not installed", False)
all_passed = False
# 4. Check Packages importable
packages_to_test = ["fastapi", "sqlalchemy", "chromadb", "cv2", "PIL", "jose"]
for pkg in packages_to_test:
try:
importlib.import_module(pkg)
except ImportError:
print_status(f"Package missing: {pkg}", False)
all_passed = False
issues.append(f"Install missing package: {pkg}")
print_status("All key packages imported", len(issues) == 0 or all_passed)
# 5. Check HF_HOME
hf_home = os.getenv("HF_HOME")
if hf_home:
path = Path(hf_home)
try:
path.mkdir(parents=True, exist_ok=True)
print_status(f"HF_HOME is set and writable ({hf_home})", True)
except Exception:
print_status(f"HF_HOME is set but NOT writable ({hf_home})", False)
all_passed = False
issues.append("Fix permissions for HF_HOME directory.")
else:
print_status("HF_HOME is NOT set", False)
all_passed = False
issues.append("Set HF_HOME environment variable permanently via PowerShell.")
# 6. Test HuggingFace Download
try:
from huggingface_hub import hf_hub_download
hf_hub_download(repo_id="lysandre/helloworld", filename="config.json")
print_status("HuggingFace Hub download successful", True)
except Exception as e:
print_status("HuggingFace Hub download failed", False)
all_passed = False
issues.append(f"HuggingFace connection/download error: {e}")
# 7. Check ffmpeg
try:
subprocess.run(["ffmpeg", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
print_status("ffmpeg accessible in PATH", True)
except (subprocess.CalledProcessError, FileNotFoundError):
print_status("ffmpeg NOT accessible in PATH", False)
all_passed = False
issues.append("Install ffmpeg and add to Windows PATH.")
print("\n--------------------------------------------")
if all_passed:
print("\033[92m🟢 ALL SYSTEMS GO\033[0m\n")
else:
print("\033[91m🔴 FIX THESE ISSUES:\033[0m")
for idx, issue in enumerate(issues, 1):
print(f" {idx}. {issue}")
print()
if __name__ == "__main__":
main()
|