Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| import os | |
| from collections.abc import Callable | |
| from typing import Any | |
| def gpu_task(duration: int = 120, *, always: bool = False): | |
| """Use ZeroGPU on Spaces and remain a no-op during local development.""" | |
| def decorate(function: Callable[..., Any]): | |
| if not always and os.getenv("GUARD_BACKEND", "mock").lower() != "gemma": | |
| return function | |
| try: | |
| import spaces | |
| except ImportError: | |
| return function | |
| return spaces.GPU(duration=duration)(function) | |
| return decorate | |