File size: 463 Bytes
645c216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os

zero_is_available = "SPACES_ZERO_GPU" in os.environ

if zero_is_available:
    import spaces  # type: ignore

    print("ZeroGPU is available")
else:
    print("ZeroGPU is not available")


# a decorator that applies the spaces.GPU decorator if zero is available
def zero(duration=60):
    def wrapper(func):
        if zero_is_available:
            return spaces.GPU(func, duration=duration)
        else:
            return func

    return wrapper