Coverage for /home/ubuntu/baas/python/baas/server/api.py: 95%
20 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 01:40 +0000
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 01:40 +0000
1import os
3import modal
5_TAG = os.environ.get('BAAS_DEPLOYMENT_TAG', 'prod-latest')
6_MIN_CONTAINERS = int(os.environ.get('BAAS_MIN_CONTAINERS', '0'))
7_MAX_CONTAINERS = int(os.environ.get('BAAS_MAX_CONTAINERS', '4'))
8_GPU = os.environ.get('BAAS_GPU', None)
9# ------------------------------------------------------------------------------
11'''
12The following environment variables are used to configure the modal
13deployment:
15.. list-table::
16 :widths: 25 25 10
17 :header-rows: 1
19 * - NAME
20 - DESCRIPTION
21 - DEFAULT
22 * - BAAS_DEPLOYMENT_TAG
23 - BaaS image tag. Default
24 - prod-latest
25 * - BAAS_MIN_CONTAINERS
26 - Minimum number of containers
27 - 0
28 * - BAAS_MAX_CONTAINERS
29 - Maximum number of containers
30 - 4
31 * - BAAS_GPU
32 - GPU type
33 - None
34'''
37def get_app(tag='prod-latest'):
38 # type: (str) -> tuple[modal.App, modal.Image]
39 '''
40 Creates a BaaS modal app.
42 Args:
43 tag (str): BaaS image tag. Default: prod-latest.
45 Returns:
46 (modal.App, modal.Image): BaaS app and image.
47 '''
48 registry = '502554252943.dkr.ecr.us-east-2.amazonaws.com/repos'
49 repo = 'baas'
50 secret = modal.Secret.from_name(
51 'aws',
52 environment_name='main',
53 required_keys=[
54 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_REGION'
55 ],
56 )
57 image = modal.Image \
58 .from_aws_ecr(
59 tag=f'{registry}/{repo}:{tag}', secret=secret, add_python='3.11'
60 ) \
61 .workdir('/home/ubuntu')
62 app = modal.App('baas', image=image)
63 return app, image
66app, image = get_app(tag=_TAG)
67with image.imports():
68 import baas.blender.blender_tools as blt
71@app.function(
72 image=image,
73 min_containers=_MIN_CONTAINERS,
74 max_containers=_MAX_CONTAINERS,
75 scaledown_window=3 * 60,
76 timeout=5 * 60,
77 gpu=_GPU,
78)
79def convert_mesh(content, source_format, target_format):
80 # type: (bytes, str, str) -> bytes
81 '''
82 Converts a given mesh from a source format to a target format.
83 The following formats are supported:
85 * abc
86 * dae
87 * fbx
88 * glb
89 * obj
90 * stl
91 * usd
92 * usdc
93 * usdz
95 Args:
96 content (bytes): File content.
97 source_format (str): Source file format.
98 target_format (str): Target file format.
100 Returns:
101 bytes: Target file as bytes.
102 '''
103 return blt.convert_mesh(content, source_format, target_format)