Spaces:
Sleeping
Sleeping
File size: 758 Bytes
0cdb4e8 | 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 | """Shared helpers for deciding whether the optional ML stack should be used."""
from __future__ import annotations
import functools
import importlib.util
from ..config import settings
@functools.lru_cache(maxsize=1)
def _torch_importable() -> bool:
return importlib.util.find_spec("torch") is not None
def ml_available() -> bool:
"""Resolve the ENABLE_ML tri-state against what's actually installed.
- "false" -> never use ML (always heuristic fallback)
- "true" -> prefer ML (individual modules still degrade on runtime errors)
- "auto" -> use ML iff torch is importable
"""
mode = settings.ENABLE_ML
if mode == "false":
return False
if mode == "true":
return True
return _torch_importable()
|