File size: 787 Bytes
dc09dcc
 
 
 
 
 
 
 
 
 
 
 
 
3ed7361
 
 
 
 
 
 
dc09dcc
fb59dba
dc09dcc
 
fb59dba
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
"""Optional ZeroGPU adapter; local runs do not import or require spaces."""
import spaces

_pipeline = None


def initialize(pipeline):
    global _pipeline
    # Load and place models during CUDA emulation, before reserving a shared GPU.
    pipeline.initialize()
    _pipeline = pipeline


def startup():
    # The pinned spaces SDK normally invokes this through Blocks.launch().
    # Our mounted FastAPI application must report startup explicitly instead.
    from spaces.zero import startup as report_startup
    report_startup()


@spaces.GPU(duration=120)
def predict(images, camera, options, prepared=None):
    if _pipeline is None:
        raise RuntimeError('ZeroGPU models have not been initialized.')
    return _pipeline.predict(images, camera, options, prepared=prepared)