Spaces:
Sleeping
Sleeping
Download scripts/check_environment.py from suplo6669/sharpify-ai-inference: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/spaces/suplo6669/sharpify-ai-inference/resolve/main/scripts/check_environment.py
- Command line
-
hf download hf://spaces/suplo6669/sharpify-ai-inference/scripts/check_environment.py
-
curl -L -o check_environment.py https://huggingface.co/spaces/suplo6669/sharpify-ai-inference/resolve/main/scripts/check_environment.py
2.16 kB
| """Report import, model-wheel, CPU, CUDA, and checkpoint readiness.""" | |
| from __future__ import annotations | |
| import importlib.metadata | |
| import json | |
| import sys | |
| from pathlib import Path | |
| BACKEND_ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(BACKEND_ROOT)) | |
| def main() -> int: | |
| import cv2 | |
| import numpy | |
| import torch | |
| from app.config import settings | |
| from basicsr.archs.rrdbnet_arch import RRDBNet | |
| from realesrgan import RealESRGANer | |
| from torchvision.ops import nms | |
| version_checks = { | |
| name: importlib.metadata.version(name) | |
| for name in ( | |
| "torch", | |
| "torchvision", | |
| "basicsr", | |
| "realesrgan", | |
| "numpy", | |
| "Pillow", | |
| "opencv-python", | |
| ) | |
| } | |
| checks = { | |
| "python": sys.version.split()[0], | |
| "python_supported": sys.version_info[:2] == (3, 11), | |
| "package_versions": version_checks, | |
| "numpy": numpy.__version__, | |
| "opencv": cv2.__version__, | |
| "torch": torch.__version__, | |
| "torch_cuda_build": torch.version.cuda, | |
| "cuda_available": torch.cuda.is_available(), | |
| "device_selected_by_auto": "cuda" if torch.cuda.is_available() else "cpu", | |
| "torchvision_cpu_operator": False, | |
| "cuda_compiled_operator": False, | |
| "model_architecture_import": RRDBNet.__name__, | |
| "realesrgan_import": RealESRGANer.__name__, | |
| "weights_path": str(settings.resolved_model_path), | |
| "weights_present": settings.resolved_model_path.is_file(), | |
| } | |
| boxes = torch.tensor([[0.0, 0.0, 1.0, 1.0]]) | |
| scores = torch.tensor([0.9]) | |
| nms(boxes, scores, 0.5) | |
| checks["torchvision_cpu_operator"] = True | |
| if checks["cuda_available"]: | |
| nms(boxes.cuda(), scores.cuda(), 0.5) | |
| checks["cuda_compiled_operator"] = True | |
| print(json.dumps(checks, indent=2)) | |
| if not checks["python_supported"]: | |
| print( | |
| "Run this check using the backend Python 3.11 environment.", file=sys.stderr | |
| ) | |
| return 1 | |
| return 0 if checks["weights_present"] else 2 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |