Merge branch 'dev' into 'main'
Browse filesDev
See merge request aletrn/gis-prediction!1
This view is limited to 50 files because it contains too many changes. Β
See raw diff
- .coveragerc +2 -2
- .dockerignore +7 -0
- .idea/misc.xml +1 -1
- Dockerfile +41 -0
- Pipfile +0 -31
- Pipfile.lock +0 -0
- README.md +55 -37
- dockerfiles/dockerfile-fastapi-fastsam-api +1 -0
- dockerfiles/dockerfile-fastapi-samgeo +0 -38
- dockerfiles/dockerfile-lambda-fastsam-api +10 -8
- dockerfiles/dockerfile-lambda-gdal-runner +0 -32
- dockerfiles/dockerfile-samgis-base +117 -0
- docs/modules.rst +3 -3
- docs/{src.utilities.rst β samgis.io.rst} +22 -14
- docs/{src.prediction_api.rst β samgis.prediction_api.rst} +9 -9
- docs/{src.rst β samgis.rst} +6 -17
- docs/{src.io.rst β samgis.utilities.rst} +15 -15
- events/payload_point.json +1 -1
- events/payload_point2.json +1 -1
- events/payload_point_eolie.json +1 -1
- poetry.lock +0 -0
- pyproject.toml +60 -0
- pytest.ini +2 -2
- requirements_dev.txt +3 -2
- requirements_pip.txt +0 -3
- requirements_poetry.txt +1 -0
- samgis/__init__.py +41 -0
- samgis/__version__.py +1 -0
- {src β samgis}/io/__init__.py +0 -0
- {src β samgis}/io/coordinates_pixel_conversion.py +4 -4
- {src β samgis}/io/geo_helpers.py +2 -2
- {src β samgis}/io/lambda_helpers.py +7 -8
- {src β samgis}/io/tms2geotiff.py +6 -6
- {src β samgis}/prediction_api/__init__.py +0 -0
- {src β samgis}/prediction_api/predictors.py +6 -6
- {src β samgis}/prediction_api/sam_onnx.py +1 -1
- {src β samgis}/utilities/__init__.py +0 -0
- {src β samgis}/utilities/constants.py +0 -0
- {src β samgis}/utilities/serialize.py +2 -2
- {src β samgis}/utilities/type_hints.py +8 -1
- {src β samgis}/utilities/utilities.py +2 -2
- scripts/lambda-entrypoint.sh +12 -2
- src/__init__.py +0 -12
- static/.gitignore +38 -0
- static/.prettierrc.json +8 -0
- static/LICENSE +176 -0
- static/NOTICE +0 -0
- static/README.md +36 -0
- static/env.d.ts +1 -0
- static/index.html +18 -0
.coveragerc
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
[run]
|
2 |
-
source =
|
3 |
omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
|
4 |
|
5 |
[report]
|
6 |
omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
|
7 |
|
8 |
exclude_lines =
|
9 |
-
if __name__ == .__main__.:
|
|
|
1 |
[run]
|
2 |
+
source = samgis
|
3 |
omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
|
4 |
|
5 |
[report]
|
6 |
omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
|
7 |
|
8 |
exclude_lines =
|
9 |
+
if __name__ == .__main__.:
|
.dockerignore
CHANGED
@@ -7,3 +7,10 @@ tmp/
|
|
7 |
__pycache__
|
8 |
.DS_Store
|
9 |
.pytest_cache
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
__pycache__
|
8 |
.DS_Store
|
9 |
.pytest_cache
|
10 |
+
node_modules
|
11 |
+
dist
|
12 |
+
static/node_modules
|
13 |
+
static/dist
|
14 |
+
static/.env*
|
15 |
+
.coverage
|
16 |
+
.git
|
.idea/misc.xml
CHANGED
@@ -3,5 +3,5 @@
|
|
3 |
<component name="Black">
|
4 |
<option name="sdkName" value="Python 3.11 (samgis)" />
|
5 |
</component>
|
6 |
-
<component name="ProjectRootManager" version="2" project-jdk-name="
|
7 |
</project>
|
|
|
3 |
<component name="Black">
|
4 |
<option name="sdkName" value="Python 3.11 (samgis)" />
|
5 |
</component>
|
6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Poetry (samgis)" project-jdk-type="Python SDK" />
|
7 |
</project>
|
Dockerfile
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM localhost/samgis-base-fastapi:latest
|
2 |
+
|
3 |
+
# Include global arg in this stage of the build
|
4 |
+
ARG LAMBDA_TASK_ROOT="/var/task"
|
5 |
+
ARG PYTHONPATH="${LAMBDA_TASK_ROOT}:${PYTHONPATH}:/usr/local/lib/python3/dist-packages"
|
6 |
+
ENV VIRTUAL_ENV=${LAMBDA_TASK_ROOT}/.venv \
|
7 |
+
PATH="${LAMBDA_TASK_ROOT}/.venv/bin:$PATH"
|
8 |
+
|
9 |
+
# Set working directory to function root directory
|
10 |
+
WORKDIR ${LAMBDA_TASK_ROOT}
|
11 |
+
|
12 |
+
# don't copy here the "static" folder, is already present because of dist and node_modules folders
|
13 |
+
COPY machine_learning_models ${LAMBDA_TASK_ROOT}/machine_learning_models
|
14 |
+
COPY samgis ${LAMBDA_TASK_ROOT}/samgis
|
15 |
+
COPY wrappers ${LAMBDA_TASK_ROOT}/wrappers
|
16 |
+
|
17 |
+
RUN ls -l /usr/bin/which
|
18 |
+
RUN /usr/bin/which python
|
19 |
+
RUN python -v
|
20 |
+
RUN echo "PYTHONPATH: ${PYTHONPATH}."
|
21 |
+
RUN echo "PATH: ${PATH}."
|
22 |
+
RUN echo "LAMBDA_TASK_ROOT: ${LAMBDA_TASK_ROOT}."
|
23 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}
|
24 |
+
RUN ls -ld ${LAMBDA_TASK_ROOT}
|
25 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}/machine_learning_models
|
26 |
+
RUN python -c "import sys; print(sys.path)"
|
27 |
+
RUN python -c "import cv2"
|
28 |
+
RUN python -c "import fastapi"
|
29 |
+
RUN python -c "import geopandas"
|
30 |
+
RUN python -c "import loguru"
|
31 |
+
RUN python -c "import onnxruntime"
|
32 |
+
RUN python -c "import rasterio"
|
33 |
+
RUN python -c "import uvicorn"
|
34 |
+
RUN df -h
|
35 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}/samgis/
|
36 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}/wrappers/
|
37 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}/static/
|
38 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}/static/dist
|
39 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}/static/node_modules
|
40 |
+
|
41 |
+
CMD ["uvicorn", "wrappers.fastapi_wrapper:app", "--host", "0.0.0.0", "--port", "7860"]
|
Pipfile
DELETED
@@ -1,31 +0,0 @@
|
|
1 |
-
[[source]]
|
2 |
-
url = "https://pypi.org/simple"
|
3 |
-
verify_ssl = true
|
4 |
-
name = "pypi"
|
5 |
-
|
6 |
-
[packages]
|
7 |
-
sphinx = "*"
|
8 |
-
sphinx-autodoc-typehints = "*"
|
9 |
-
myst-parser = "*"
|
10 |
-
|
11 |
-
[dev-packages]
|
12 |
-
aws-lambda-powertools = "*"
|
13 |
-
awslambdaric = "*"
|
14 |
-
bson = "*"
|
15 |
-
geopandas = "*"
|
16 |
-
jmespath = "*"
|
17 |
-
matplotlib = "*"
|
18 |
-
numpy = "*"
|
19 |
-
onnxruntime = "*"
|
20 |
-
opencv-python-headless = "*"
|
21 |
-
pillow = "*"
|
22 |
-
pydantic = ">=2.0.3"
|
23 |
-
python-dotenv = "*"
|
24 |
-
rasterio = "*"
|
25 |
-
requests = "*"
|
26 |
-
pytest = "*"
|
27 |
-
pytest-cov = "*"
|
28 |
-
|
29 |
-
[requires]
|
30 |
-
python_version = "3.11"
|
31 |
-
python_full_version = "3.11.6"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pipfile.lock
DELETED
The diff for this file is too large to render.
See raw diff
|
|
README.md
CHANGED
@@ -1,36 +1,64 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
##
|
4 |
|
5 |
-
|
6 |
-
2. resolve model paths: OK local
|
7 |
-
3. inference:
|
8 |
-
4. from mask to json (rasterio + geopandas, check for re-projection to EPSG_4326)
|
9 |
-
5. check mandatory dependencies
|
10 |
-
6. check for alternative python interpreters
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
```bash
|
17 |
# clean any old active containers
|
18 |
docker stop $(docker ps -a -q); docker rm $(docker ps -a -q)
|
19 |
|
20 |
# build the base docker image with the docker aws repository tag
|
21 |
-
docker build . -f dockerfiles/dockerfile-
|
22 |
-
|
23 |
-
# OPTIONAL: to build the lambda-gdal-runner image on a x86 machine use the build arg `RIE="https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie"`:
|
24 |
-
docker build . -f dockerfiles/dockerfile-lambda-gdal-runner --build-arg RIE="https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie" --tag 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-gdal-runner --progress=plain
|
25 |
|
26 |
# build the final docker image
|
27 |
-
docker build . -f dockerfiles/dockerfile-lambda-fastsam-api --tag
|
28 |
```
|
29 |
|
30 |
Run the container (keep it on background) and show logs
|
31 |
|
32 |
```bash
|
33 |
-
docker
|
34 |
```
|
35 |
|
36 |
Test it with curl:
|
@@ -43,33 +71,23 @@ curl -X 'POST' \
|
|
43 |
-d '{}'
|
44 |
```
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
aws --profile alessandrotrinca_hotmail_aws_console_ec2_lambda ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin 686901913580.dkr.ecr.eu-west-1.amazonaws.com
|
50 |
-
```
|
51 |
-
2. Build and tag the docker images, then push them:
|
52 |
-
```
|
53 |
-
docker push 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-gdal-runner:latest
|
54 |
-
docker push 686901913580.dkr.ecr.eu-west-1.amazonaws.com/lambda-fastsam-api:latest
|
55 |
-
```
|
56 |
-
3. It's possible to publish a new aws lambda version from cmd or from lambda page
|
57 |
-
|
58 |
-
|
59 |
-
## Dependencies installation and local tests
|
60 |
-
The docker build process needs only the classic requirements.txt (here renamed to `requirements_dockerfile.txt`), instead for local development and sphinx-docs build
|
61 |
-
there is `Pipfile` (sphinx docs is hosted on Cloudflare Pages).
|
62 |
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
|
66 |
Tests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.
|
67 |
|
68 |
```bash
|
69 |
-
python -m pytest --cov=
|
70 |
```
|
71 |
|
72 |
-
|
73 |
|
74 |
Run the sphinx-apidoc: it's a tool for automatic generation of Sphinx sources that, using the autodoc
|
75 |
extension, document a whole package in the style of other automatic API documentation tools. See the
|
@@ -78,10 +96,10 @@ Run the command from the project root:
|
|
78 |
|
79 |
```bash
|
80 |
# missing docs folder (run from project root)
|
81 |
-
cd docs && sphinx-quickstart -p SamGIS -
|
82 |
|
83 |
# update docs folder (from project root)
|
84 |
-
sphinx-apidoc -f -o docs
|
85 |
```
|
86 |
|
87 |
Then it's possible to generate the HTML pages
|
|
|
1 |
+
---
|
2 |
+
title: SamGIS
|
3 |
+
emoji: π
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: blue
|
6 |
+
sdk: docker
|
7 |
+
pinned: false
|
8 |
+
---
|
9 |
|
10 |
+
## SamGIS - HuggingFace version
|
11 |
|
12 |
+
Build the docker image this way:
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
```bash
|
15 |
+
# clean any old active containers
|
16 |
+
docker stop $(docker ps -a -q); docker rm $(docker ps -a -q)
|
17 |
+
|
18 |
+
# build the base docker image with the ARG DEPENDENCY_GROUP=fastapi used by poetry
|
19 |
+
docker build . -f dockerfiles/dockerfile-samgis-base --build-arg DEPENDENCY_GROUP=fastapi --tag localhost/samgis-base-fastapi --progress=plain
|
20 |
|
21 |
+
# build the image, use the tag "samgis-huggingface"
|
22 |
+
docker build . --tag localhost/samgis-huggingface --progress=plain
|
23 |
+
```
|
24 |
+
|
25 |
+
Run the container (keep it on background) and show logs
|
26 |
+
|
27 |
+
```bash
|
28 |
+
docker run -d --name samgis-huggingface -p 7860:7860 localhost/samgis-huggingface; docker logs -f samgis-huggingface
|
29 |
+
```
|
30 |
+
|
31 |
+
Test it with curl:
|
32 |
+
|
33 |
+
```bash
|
34 |
+
curl -X 'POST' \
|
35 |
+
'http://localhost:7860/infer_samgeo' \
|
36 |
+
-H 'accept: application/json' \
|
37 |
+
-d '{}'
|
38 |
+
```
|
39 |
+
|
40 |
+
or better visiting the swagger page on http://localhost:7860/docs
|
41 |
+
|
42 |
+
|
43 |
+
## SamGIS - lambda AWS version
|
44 |
+
|
45 |
+
Build the docker image this way:
|
46 |
|
47 |
```bash
|
48 |
# clean any old active containers
|
49 |
docker stop $(docker ps -a -q); docker rm $(docker ps -a -q)
|
50 |
|
51 |
# build the base docker image with the docker aws repository tag
|
52 |
+
docker build . -f dockerfiles/dockerfile-samgis-base --build-arg DEPENDENCY_GROUP=aws_lambda --tag localhost/samgis-base-aws-lambda --progress=plain
|
|
|
|
|
|
|
53 |
|
54 |
# build the final docker image
|
55 |
+
docker build . -f dockerfiles/dockerfile-lambda-fastsam-api --tag localhost/lambda-fastsam-api --progress=plain
|
56 |
```
|
57 |
|
58 |
Run the container (keep it on background) and show logs
|
59 |
|
60 |
```bash
|
61 |
+
docker run -d --name lambda-fastsam-api -p 8080:8080 lambda-fastsam-api; docker logs -f lambda-fastsam-api
|
62 |
```
|
63 |
|
64 |
Test it with curl:
|
|
|
71 |
-d '{}'
|
72 |
```
|
73 |
|
74 |
+
### Publish the aws lambda docker image
|
75 |
+
Login on aws ECR with the correct aws profile (change the example `localhost/` repository url with the one from
|
76 |
+
the [ECR push command instructions page](https://eu-west-1.console.aws.amazon.com/ecr/repositories/)).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
+
### Dependencies installation and local tests
|
79 |
+
The docker build process needs only the base dependency group plus the `aws_lambda` or `fastapi` optional one.
|
80 |
+
Install also the `test` and/or `docs` groups if needed.
|
81 |
|
82 |
+
### Tests
|
83 |
|
84 |
Tests are defined in the `tests` folder in this project. Use PIP to install the test dependencies and run tests.
|
85 |
|
86 |
```bash
|
87 |
+
python -m pytest --cov=samgis --cov-report=term-missing && coverage html
|
88 |
```
|
89 |
|
90 |
+
### How to update the static documentation with sphinx
|
91 |
|
92 |
Run the sphinx-apidoc: it's a tool for automatic generation of Sphinx sources that, using the autodoc
|
93 |
extension, document a whole package in the style of other automatic API documentation tools. See the
|
|
|
96 |
|
97 |
```bash
|
98 |
# missing docs folder (run from project root)
|
99 |
+
cd docs && sphinx-quickstart -p SamGIS -r 1.0.0 -l python --master index
|
100 |
|
101 |
# update docs folder (from project root)
|
102 |
+
sphinx-apidoc -f -o docs samgis
|
103 |
```
|
104 |
|
105 |
Then it's possible to generate the HTML pages
|
dockerfiles/dockerfile-fastapi-fastsam-api
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Dockerfile
|
dockerfiles/dockerfile-fastapi-samgeo
DELETED
@@ -1,38 +0,0 @@
|
|
1 |
-
FROM ghcr.io/osgeo/gdal:ubuntu-small-3.7.2
|
2 |
-
|
3 |
-
WORKDIR /code
|
4 |
-
COPY ./requirements_dockerfile.txt /code/requirements_dockerfile.txt
|
5 |
-
COPY ./requirements_pip.txt /code/requirements_pip.txt
|
6 |
-
|
7 |
-
RUN apt update && apt install -y g++ make cmake unzip libcurl4-openssl-dev python3-pip
|
8 |
-
|
9 |
-
# avoid segment-geospatial exception caused by missing libGL.so.1 library
|
10 |
-
RUN apt install -y libgl1 curl
|
11 |
-
RUN ls -ld /usr/lib/x86_64-linux-gnu/libGL.so* || echo "libGL.so* not found..."
|
12 |
-
|
13 |
-
RUN which python
|
14 |
-
RUN python --version
|
15 |
-
RUN python -m pip install --no-cache-dir --upgrade -r /code/requirements_pip.txt
|
16 |
-
RUN python -m pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
17 |
-
RUN python -m pip install --no-cache-dir -r /code/requirements_dockerfile.txt
|
18 |
-
|
19 |
-
RUN useradd -m -u 1000 user
|
20 |
-
|
21 |
-
USER user
|
22 |
-
|
23 |
-
ENV HOME=/home/user \
|
24 |
-
PATH=/home/user/.local/bin:$PATH
|
25 |
-
|
26 |
-
WORKDIR $HOME/app
|
27 |
-
|
28 |
-
RUN curl -o ${HOME}/sam_vit_h_4b8939.pth https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth
|
29 |
-
RUN ls -l ${HOME}/
|
30 |
-
COPY --chown=user . $HOME/app
|
31 |
-
|
32 |
-
RUN echo $HOME/app
|
33 |
-
RUN echo $HOME/
|
34 |
-
|
35 |
-
RUN ls -l $HOME/app
|
36 |
-
RUN ls -l $HOME/
|
37 |
-
|
38 |
-
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dockerfiles/dockerfile-lambda-fastsam-api
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
-
FROM
|
2 |
|
3 |
# Include global arg in this stage of the build
|
4 |
ARG LAMBDA_TASK_ROOT="/var/task"
|
5 |
ARG PYTHONPATH="${LAMBDA_TASK_ROOT}:${PYTHONPATH}:/usr/local/lib/python3/dist-packages"
|
|
|
|
|
6 |
|
7 |
# Set working directory to function root directory
|
8 |
WORKDIR ${LAMBDA_TASK_ROOT}
|
9 |
-
COPY ./
|
|
|
10 |
COPY ./machine_learning_models ${LAMBDA_TASK_ROOT}/machine_learning_models
|
11 |
|
12 |
RUN ls -l /usr/bin/which
|
@@ -19,16 +22,15 @@ RUN ls -l ${LAMBDA_TASK_ROOT}
|
|
19 |
RUN ls -ld ${LAMBDA_TASK_ROOT}
|
20 |
RUN ls -l ${LAMBDA_TASK_ROOT}/machine_learning_models
|
21 |
RUN python -c "import sys; print(sys.path)"
|
|
|
22 |
RUN python -c "import cv2"
|
23 |
RUN python -c "import geopandas"
|
24 |
RUN python -c "import onnxruntime"
|
25 |
RUN python -c "import rasterio"
|
26 |
-
RUN python -c "import awslambdaric"
|
27 |
-
RUN python -m pip list
|
28 |
-
RUN python -m pip freeze
|
29 |
RUN df -h
|
30 |
RUN ls -l /lambda-entrypoint.sh
|
31 |
-
RUN ls -l ${LAMBDA_TASK_ROOT}/
|
|
|
32 |
|
33 |
-
|
34 |
-
CMD [ "
|
|
|
1 |
+
FROM localhost/samgis-base-aws-lambda:latest
|
2 |
|
3 |
# Include global arg in this stage of the build
|
4 |
ARG LAMBDA_TASK_ROOT="/var/task"
|
5 |
ARG PYTHONPATH="${LAMBDA_TASK_ROOT}:${PYTHONPATH}:/usr/local/lib/python3/dist-packages"
|
6 |
+
ENV VIRTUAL_ENV=${LAMBDA_TASK_ROOT}/.venv \
|
7 |
+
PATH="${LAMBDA_TASK_ROOT}/.venv/bin:$PATH"
|
8 |
|
9 |
# Set working directory to function root directory
|
10 |
WORKDIR ${LAMBDA_TASK_ROOT}
|
11 |
+
COPY ./samgis ${LAMBDA_TASK_ROOT}/samgis
|
12 |
+
COPY ./wrappers ${LAMBDA_TASK_ROOT}/wrappers
|
13 |
COPY ./machine_learning_models ${LAMBDA_TASK_ROOT}/machine_learning_models
|
14 |
|
15 |
RUN ls -l /usr/bin/which
|
|
|
22 |
RUN ls -ld ${LAMBDA_TASK_ROOT}
|
23 |
RUN ls -l ${LAMBDA_TASK_ROOT}/machine_learning_models
|
24 |
RUN python -c "import sys; print(sys.path)"
|
25 |
+
RUN python -c "import awslambdaric"
|
26 |
RUN python -c "import cv2"
|
27 |
RUN python -c "import geopandas"
|
28 |
RUN python -c "import onnxruntime"
|
29 |
RUN python -c "import rasterio"
|
|
|
|
|
|
|
30 |
RUN df -h
|
31 |
RUN ls -l /lambda-entrypoint.sh
|
32 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}/samgis/
|
33 |
+
RUN ls -l ${LAMBDA_TASK_ROOT}/wrappers/
|
34 |
|
35 |
+
ENTRYPOINT ["/lambda-entrypoint.sh"]
|
36 |
+
CMD [ "wrappers.lambda_wrapper.lambda_handler" ]
|
dockerfiles/dockerfile-lambda-gdal-runner
DELETED
@@ -1,32 +0,0 @@
|
|
1 |
-
FROM python:3.11-slim-bookworm
|
2 |
-
|
3 |
-
# Include global arg in this stage of the build
|
4 |
-
ARG LAMBDA_TASK_ROOT="/var/task"
|
5 |
-
ARG PYTHONPATH="${LAMBDA_TASK_ROOT}:${PYTHONPATH}:/usr/local/lib/python3/dist-packages"
|
6 |
-
ARG RIE="https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie"
|
7 |
-
|
8 |
-
RUN echo "ENV RIE: $RIE ..."
|
9 |
-
|
10 |
-
# Set working directory to function root directory
|
11 |
-
WORKDIR ${LAMBDA_TASK_ROOT}
|
12 |
-
COPY requirements_pip.txt ${LAMBDA_TASK_ROOT}/requirements_pip.txt
|
13 |
-
COPY requirements_dockerfile.txt ${LAMBDA_TASK_ROOT}/requirements_dockerfile.txt
|
14 |
-
|
15 |
-
# avoid segment-geospatial exception caused by missing libGL.so.1 library
|
16 |
-
RUN apt update && apt install -y libgl1 curl python3-pip && apt clean
|
17 |
-
RUN ls -ld /usr/lib/*linux-gnu/libGL.so* || echo "libGL.so* not found..."
|
18 |
-
RUN which python
|
19 |
-
RUN python --version
|
20 |
-
RUN python -m pip install -r ${LAMBDA_TASK_ROOT}/requirements_pip.txt --upgrade --target ${LAMBDA_TASK_ROOT}
|
21 |
-
RUN python -m pip install -r ${LAMBDA_TASK_ROOT}/requirements_dockerfile.txt --target ${LAMBDA_TASK_ROOT}
|
22 |
-
RUN python -c "import sys;print(sys.path)"
|
23 |
-
# RUN python -m pip install pillow awslambdaric aws-lambda-powertools httpx jmespath --target ${LAMBDA_TASK_ROOT}
|
24 |
-
|
25 |
-
RUN curl -Lo /usr/local/bin/aws-lambda-rie ${RIE}
|
26 |
-
RUN chmod +x /usr/local/bin/aws-lambda-rie
|
27 |
-
|
28 |
-
COPY ./scripts/lambda-entrypoint.sh /lambda-entrypoint.sh
|
29 |
-
RUN chmod +x /lambda-entrypoint.sh
|
30 |
-
RUN ls -l /lambda-entrypoint.sh
|
31 |
-
|
32 |
-
ENTRYPOINT ["/lambda-entrypoint.sh"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dockerfiles/dockerfile-samgis-base
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Include global ARGs at the dockerfile top
|
2 |
+
ARG ARCH="x86_64"
|
3 |
+
ARG LAMBDA_TASK_ROOT="/var/task"
|
4 |
+
ARG FASTAPI_STATIC="${LAMBDA_TASK_ROOT}/static"
|
5 |
+
ARG PYTHONPATH="${LAMBDA_TASK_ROOT}:${PYTHONPATH}:/usr/local/lib/python3/dist-packages"
|
6 |
+
ARG POETRY_NO_INTERACTION=1
|
7 |
+
ARG POETRY_VIRTUALENVS_IN_PROJECT=1
|
8 |
+
ARG POETRY_VIRTUALENVS_CREATE=1
|
9 |
+
ARG POETRY_CACHE_DIR=/tmp/poetry_cache
|
10 |
+
ARG RIE="https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie"
|
11 |
+
|
12 |
+
|
13 |
+
FROM python:3.11-bookworm as builder_global
|
14 |
+
|
15 |
+
ARG ARCH
|
16 |
+
ARG LAMBDA_TASK_ROOT
|
17 |
+
ARG PYTHONPATH
|
18 |
+
ARG POETRY_NO_INTERACTION
|
19 |
+
ARG POETRY_VIRTUALENVS_IN_PROJECT
|
20 |
+
ARG POETRY_VIRTUALENVS_CREATE
|
21 |
+
ARG POETRY_CACHE_DIR
|
22 |
+
ARG RIE
|
23 |
+
ARG DEPENDENCY_GROUP
|
24 |
+
|
25 |
+
RUN echo "ARCH: $ARCH ..."
|
26 |
+
|
27 |
+
RUN echo "ARG RIE: $RIE ..."
|
28 |
+
RUN echo "ARG POETRY_CACHE_DIR: ${POETRY_CACHE_DIR} ..."
|
29 |
+
RUN echo "ARG PYTHONPATH: $PYTHONPATH ..."
|
30 |
+
RUN test -n ${DEPENDENCY_GROUP:?}
|
31 |
+
RUN echo "python DEPENDENCY_GROUP: ${DEPENDENCY_GROUP} ..."
|
32 |
+
RUN echo "arg dep:"
|
33 |
+
|
34 |
+
# Set working directory to function root directory
|
35 |
+
WORKDIR ${LAMBDA_TASK_ROOT}
|
36 |
+
COPY requirements_poetry.txt pyproject.toml poetry.lock README.md ${LAMBDA_TASK_ROOT}/
|
37 |
+
|
38 |
+
# avoid segment-geospatial exception caused by missing libGL.so.1 library
|
39 |
+
# RUN apt update && apt install -y libgl1 curl python3-pip && apt clean
|
40 |
+
RUN apt update && apt install -y libgl1 curl
|
41 |
+
RUN apt update && apt install -y python3-pip && apt clean
|
42 |
+
|
43 |
+
# poetry installation path is NOT within ${LAMBDA_TASK_ROOT}: not needed for runtime docker image
|
44 |
+
RUN python -m pip install -r ${LAMBDA_TASK_ROOT}/requirements_poetry.txt
|
45 |
+
|
46 |
+
RUN which poetry && poetry --version && poetry config --list
|
47 |
+
RUN poetry config virtualenvs.path ${LAMBDA_TASK_ROOT}
|
48 |
+
RUN echo "# poetry config --list #" && poetry config --list
|
49 |
+
RUN poetry install --with ${DEPENDENCY_GROUP} --no-root
|
50 |
+
|
51 |
+
RUN curl -Lo /usr/local/bin/aws-lambda-rie ${RIE}
|
52 |
+
|
53 |
+
|
54 |
+
FROM python:3.11-slim-bookworm as runtime
|
55 |
+
|
56 |
+
ARG ARCH
|
57 |
+
ARG LAMBDA_TASK_ROOT
|
58 |
+
|
59 |
+
ENV VIRTUAL_ENV=${LAMBDA_TASK_ROOT}/.venv \
|
60 |
+
PATH="${LAMBDA_TASK_ROOT}/.venv/bin:$PATH"
|
61 |
+
|
62 |
+
RUN echo "COPY --from=builder_global /usr/lib/${ARCH}-linux-gnu/libGL.so* /usr/lib/${ARCH}-linux-gnu/"
|
63 |
+
COPY --from=builder_global /usr/lib/${ARCH}-linux-gnu/libGL.so* /usr/lib/${ARCH}-linux-gnu/
|
64 |
+
COPY --from=builder_global ${LAMBDA_TASK_ROOT}/.venv ${LAMBDA_TASK_ROOT}/.venv
|
65 |
+
|
66 |
+
RUN echo "new LAMBDA_TASK_ROOT after hidden venv copy => ${LAMBDA_TASK_ROOT}"
|
67 |
+
RUN ls -ld ${LAMBDA_TASK_ROOT}/
|
68 |
+
RUN ls -lA ${LAMBDA_TASK_ROOT}/
|
69 |
+
|
70 |
+
COPY --from=builder_global /usr/local/bin/aws-lambda-rie /usr/local/bin/aws-lambda-rie
|
71 |
+
RUN chmod +x /usr/local/bin/aws-lambda-rie
|
72 |
+
COPY ./scripts/lambda-entrypoint.sh /lambda-entrypoint.sh
|
73 |
+
RUN chmod +x /lambda-entrypoint.sh
|
74 |
+
|
75 |
+
|
76 |
+
### conditional section
|
77 |
+
FROM node:20-slim AS node_fastapi
|
78 |
+
|
79 |
+
ARG DEPENDENCY_GROUP
|
80 |
+
ENV PNPM_HOME="/pnpm"
|
81 |
+
ENV PATH="$PNPM_HOME:$PATH"
|
82 |
+
RUN corepack enable
|
83 |
+
|
84 |
+
COPY ./static /appnode
|
85 |
+
WORKDIR /appnode
|
86 |
+
# RUN if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then echo "pnpm store path:" && pnpm store path; fi
|
87 |
+
|
88 |
+
|
89 |
+
FROM node_fastapi AS node_prod_deps
|
90 |
+
|
91 |
+
ARG DEPENDENCY_GROUP
|
92 |
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then \
|
93 |
+
pnpm install --prod --frozen-lockfile; else \
|
94 |
+
echo "DEPENDENCY_GROUP 1: ${DEPENDENCY_GROUP} ..."; fi
|
95 |
+
# here multiple conditions concatenated to avoid failing on check
|
96 |
+
RUN if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then if [ ! -d /appnode/node_modules ]; then echo "no node_modules folder" && exit 1; fi; fi
|
97 |
+
|
98 |
+
|
99 |
+
FROM node_fastapi AS node_build
|
100 |
+
|
101 |
+
ARG DEPENDENCY_GROUP
|
102 |
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then \
|
103 |
+
pnpm install --frozen-lockfile; else \
|
104 |
+
echo "DEPENDENCY_GROUP 2: ${DEPENDENCY_GROUP} ..."; fi
|
105 |
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then \
|
106 |
+
pnpm build; fi
|
107 |
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then \
|
108 |
+
pnpm tailwindcss -i /appnode/src/input.css -o /appnode/dist/output.css; fi
|
109 |
+
RUN if [ "${DEPENDENCY_GROUP}" = "fastapi" ]; then if [ ! -d /appnode/dist ]; then echo "no dist folder" && exit 1; fi; fi
|
110 |
+
|
111 |
+
|
112 |
+
FROM runtime
|
113 |
+
ARG FASTAPI_STATIC
|
114 |
+
RUN mkdir ${FASTAPI_STATIC}
|
115 |
+
|
116 |
+
COPY --from=node_prod_deps /appnode/node_modules* ${FASTAPI_STATIC}/node_modules
|
117 |
+
COPY --from=node_build /appnode/dist* ${FASTAPI_STATIC}/dist
|
docs/modules.rst
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
.. toctree::
|
5 |
:maxdepth: 4
|
6 |
|
7 |
-
|
|
|
1 |
+
samgis
|
2 |
+
======
|
3 |
|
4 |
.. toctree::
|
5 |
:maxdepth: 4
|
6 |
|
7 |
+
samgis
|
docs/{src.utilities.rst β samgis.io.rst}
RENAMED
@@ -1,37 +1,45 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
Submodules
|
5 |
----------
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
.. automodule::
|
11 |
:members:
|
12 |
:undoc-members:
|
13 |
:show-inheritance:
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
.. automodule::
|
19 |
:members:
|
20 |
:undoc-members:
|
21 |
:show-inheritance:
|
22 |
|
23 |
-
|
24 |
--------------------------------
|
25 |
|
26 |
-
.. automodule::
|
27 |
:members:
|
28 |
:undoc-members:
|
29 |
:show-inheritance:
|
30 |
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
.. automodule::
|
35 |
:members:
|
36 |
:undoc-members:
|
37 |
:show-inheritance:
|
@@ -39,7 +47,7 @@ src.utilities.utilities module
|
|
39 |
Module contents
|
40 |
---------------
|
41 |
|
42 |
-
.. automodule::
|
43 |
:members:
|
44 |
:undoc-members:
|
45 |
:show-inheritance:
|
|
|
1 |
+
samgis.io package
|
2 |
+
=================
|
3 |
|
4 |
Submodules
|
5 |
----------
|
6 |
|
7 |
+
samgis.io.coordinates\_pixel\_conversion module
|
8 |
+
-----------------------------------------------
|
9 |
|
10 |
+
.. automodule:: samgis.io.coordinates_pixel_conversion
|
11 |
:members:
|
12 |
:undoc-members:
|
13 |
:show-inheritance:
|
14 |
|
15 |
+
samgis.io.geo\_helpers module
|
16 |
+
-----------------------------
|
17 |
|
18 |
+
.. automodule:: samgis.io.geo_helpers
|
19 |
:members:
|
20 |
:undoc-members:
|
21 |
:show-inheritance:
|
22 |
|
23 |
+
samgis.io.lambda\_helpers module
|
24 |
--------------------------------
|
25 |
|
26 |
+
.. automodule:: samgis.io.lambda_helpers
|
27 |
:members:
|
28 |
:undoc-members:
|
29 |
:show-inheritance:
|
30 |
|
31 |
+
samgis.io.lambda\_wrapper module
|
32 |
+
--------------------------------
|
33 |
+
|
34 |
+
.. automodule:: samgis.io.lambda_wrapper
|
35 |
+
:members:
|
36 |
+
:undoc-members:
|
37 |
+
:show-inheritance:
|
38 |
+
|
39 |
+
samgis.io.tms2geotiff module
|
40 |
+
----------------------------
|
41 |
|
42 |
+
.. automodule:: samgis.io.tms2geotiff
|
43 |
:members:
|
44 |
:undoc-members:
|
45 |
:show-inheritance:
|
|
|
47 |
Module contents
|
48 |
---------------
|
49 |
|
50 |
+
.. automodule:: samgis.io
|
51 |
:members:
|
52 |
:undoc-members:
|
53 |
:show-inheritance:
|
docs/{src.prediction_api.rst β samgis.prediction_api.rst}
RENAMED
@@ -1,21 +1,21 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
Submodules
|
5 |
----------
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
.. automodule::
|
11 |
:members:
|
12 |
:undoc-members:
|
13 |
:show-inheritance:
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
.. automodule::
|
19 |
:members:
|
20 |
:undoc-members:
|
21 |
:show-inheritance:
|
@@ -23,7 +23,7 @@ src.prediction\_api.sam\_onnx module
|
|
23 |
Module contents
|
24 |
---------------
|
25 |
|
26 |
-
.. automodule::
|
27 |
:members:
|
28 |
:undoc-members:
|
29 |
:show-inheritance:
|
|
|
1 |
+
samgis.prediction\_api package
|
2 |
+
==============================
|
3 |
|
4 |
Submodules
|
5 |
----------
|
6 |
|
7 |
+
samgis.prediction\_api.predictors module
|
8 |
+
----------------------------------------
|
9 |
|
10 |
+
.. automodule:: samgis.prediction_api.predictors
|
11 |
:members:
|
12 |
:undoc-members:
|
13 |
:show-inheritance:
|
14 |
|
15 |
+
samgis.prediction\_api.sam\_onnx module
|
16 |
+
---------------------------------------
|
17 |
|
18 |
+
.. automodule:: samgis.prediction_api.sam_onnx
|
19 |
:members:
|
20 |
:undoc-members:
|
21 |
:show-inheritance:
|
|
|
23 |
Module contents
|
24 |
---------------
|
25 |
|
26 |
+
.. automodule:: samgis.prediction_api
|
27 |
:members:
|
28 |
:undoc-members:
|
29 |
:show-inheritance:
|
docs/{src.rst β samgis.rst}
RENAMED
@@ -1,5 +1,5 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
Subpackages
|
5 |
-----------
|
@@ -7,25 +7,14 @@ Subpackages
|
|
7 |
.. toctree::
|
8 |
:maxdepth: 4
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
Submodules
|
15 |
-
----------
|
16 |
-
|
17 |
-
src.app module
|
18 |
-
--------------
|
19 |
-
|
20 |
-
.. automodule:: src.app
|
21 |
-
:members:
|
22 |
-
:undoc-members:
|
23 |
-
:show-inheritance:
|
24 |
|
25 |
Module contents
|
26 |
---------------
|
27 |
|
28 |
-
.. automodule::
|
29 |
:members:
|
30 |
:undoc-members:
|
31 |
:show-inheritance:
|
|
|
1 |
+
samgis package
|
2 |
+
==============
|
3 |
|
4 |
Subpackages
|
5 |
-----------
|
|
|
7 |
.. toctree::
|
8 |
:maxdepth: 4
|
9 |
|
10 |
+
samgis.io
|
11 |
+
samgis.prediction_api
|
12 |
+
samgis.utilities
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
Module contents
|
15 |
---------------
|
16 |
|
17 |
+
.. automodule:: samgis
|
18 |
:members:
|
19 |
:undoc-members:
|
20 |
:show-inheritance:
|
docs/{src.io.rst β samgis.utilities.rst}
RENAMED
@@ -1,37 +1,37 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
Submodules
|
5 |
----------
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
.. automodule::
|
11 |
:members:
|
12 |
:undoc-members:
|
13 |
:show-inheritance:
|
14 |
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
.. automodule::
|
19 |
:members:
|
20 |
:undoc-members:
|
21 |
:show-inheritance:
|
22 |
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
.. automodule::
|
27 |
:members:
|
28 |
:undoc-members:
|
29 |
:show-inheritance:
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
.. automodule::
|
35 |
:members:
|
36 |
:undoc-members:
|
37 |
:show-inheritance:
|
@@ -39,7 +39,7 @@ src.io.tms2geotiff module
|
|
39 |
Module contents
|
40 |
---------------
|
41 |
|
42 |
-
.. automodule::
|
43 |
:members:
|
44 |
:undoc-members:
|
45 |
:show-inheritance:
|
|
|
1 |
+
samgis.utilities package
|
2 |
+
========================
|
3 |
|
4 |
Submodules
|
5 |
----------
|
6 |
|
7 |
+
samgis.utilities.constants module
|
8 |
+
---------------------------------
|
9 |
|
10 |
+
.. automodule:: samgis.utilities.constants
|
11 |
:members:
|
12 |
:undoc-members:
|
13 |
:show-inheritance:
|
14 |
|
15 |
+
samgis.utilities.serialize module
|
16 |
+
---------------------------------
|
17 |
|
18 |
+
.. automodule:: samgis.utilities.serialize
|
19 |
:members:
|
20 |
:undoc-members:
|
21 |
:show-inheritance:
|
22 |
|
23 |
+
samgis.utilities.type\_hints module
|
24 |
+
-----------------------------------
|
25 |
|
26 |
+
.. automodule:: samgis.utilities.type_hints
|
27 |
:members:
|
28 |
:undoc-members:
|
29 |
:show-inheritance:
|
30 |
|
31 |
+
samgis.utilities.utilities module
|
32 |
+
---------------------------------
|
33 |
|
34 |
+
.. automodule:: samgis.utilities.utilities
|
35 |
:members:
|
36 |
:undoc-members:
|
37 |
:show-inheritance:
|
|
|
39 |
Module contents
|
40 |
---------------
|
41 |
|
42 |
+
.. automodule:: samgis.utilities
|
43 |
:members:
|
44 |
:undoc-members:
|
45 |
:show-inheritance:
|
events/payload_point.json
CHANGED
@@ -9,6 +9,6 @@
|
|
9 |
"label": 0
|
10 |
}],
|
11 |
"zoom": 6,
|
12 |
-
"source_type": "
|
13 |
"debug": true
|
14 |
}
|
|
|
9 |
"label": 0
|
10 |
}],
|
11 |
"zoom": 6,
|
12 |
+
"source_type": "OpenStreetMap",
|
13 |
"debug": true
|
14 |
}
|
events/payload_point2.json
CHANGED
@@ -9,6 +9,6 @@
|
|
9 |
"label": 0
|
10 |
}],
|
11 |
"zoom": 10,
|
12 |
-
"source_type": "
|
13 |
"debug": true
|
14 |
}
|
|
|
9 |
"label": 0
|
10 |
}],
|
11 |
"zoom": 10,
|
12 |
+
"source_type": "OpenStreetMap",
|
13 |
"debug": true
|
14 |
}
|
events/payload_point_eolie.json
CHANGED
@@ -20,5 +20,5 @@
|
|
20 |
}
|
21 |
],
|
22 |
"zoom": 10,
|
23 |
-
"source_type": "
|
24 |
}
|
|
|
20 |
}
|
21 |
],
|
22 |
"zoom": 10,
|
23 |
+
"source_type": "OpenStreetMap"
|
24 |
}
|
poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pyproject.toml
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "samgis"
|
3 |
+
version = "1.0.0"
|
4 |
+
description = "A backend for machine learning instance segmentation on geospatial data even without dedicated graphics cards."
|
5 |
+
authors = ["alessandro trinca tornidor <alessandro@trinca.tornidor.com>"]
|
6 |
+
license = "MIT license"
|
7 |
+
readme = "README.md"
|
8 |
+
|
9 |
+
[tool.poetry.dependencies]
|
10 |
+
bson = "^0.5.10"
|
11 |
+
contextily = "^1.4.0"
|
12 |
+
geopandas = "^0.14.1"
|
13 |
+
numpy = "^1.26.2"
|
14 |
+
onnxruntime = "^1.16.3"
|
15 |
+
opencv-python-headless = "^4.8.1.78"
|
16 |
+
python = "^3.11"
|
17 |
+
python-dotenv = "^1.0.0"
|
18 |
+
rasterio = "^1.3.9"
|
19 |
+
requests = "^2.31.0"
|
20 |
+
pillow = "^10.1.0"
|
21 |
+
loguru = "^0.7.2"
|
22 |
+
|
23 |
+
[tool.poetry.group.aws_lambda]
|
24 |
+
optional = true
|
25 |
+
|
26 |
+
[tool.poetry.group.aws_lambda.dependencies]
|
27 |
+
aws-lambda-powertools = "^2.30.2"
|
28 |
+
awslambdaric = "^2.0.8"
|
29 |
+
jmespath = "^1.0.1"
|
30 |
+
pydantic = "^2.5.3"
|
31 |
+
|
32 |
+
[tool.poetry.group.test]
|
33 |
+
optional = true
|
34 |
+
|
35 |
+
[tool.poetry.group.test.dependencies]
|
36 |
+
pytest = "^7.4.3"
|
37 |
+
pytest-cov = "^4.1.0"
|
38 |
+
python-dotenv = "^1.0.0"
|
39 |
+
|
40 |
+
[tool.poetry.group.docs]
|
41 |
+
optional = true
|
42 |
+
|
43 |
+
[tool.poetry.group.docs.dependencies]
|
44 |
+
sphinx = "^7.2.6"
|
45 |
+
sphinx-autodoc-typehints = "^1.25.2"
|
46 |
+
sphinxcontrib-openapi = "^0.8.3"
|
47 |
+
myst-parser = "^2.0.0"
|
48 |
+
|
49 |
+
[tool.poetry.group.fastapi]
|
50 |
+
optional = true
|
51 |
+
|
52 |
+
[tool.poetry.group.fastapi.dependencies]
|
53 |
+
fastapi = "^0.108.0"
|
54 |
+
loguru = "^0.7.2"
|
55 |
+
pydantic = "^2.5.3"
|
56 |
+
uvicorn = "^0.25.0"
|
57 |
+
|
58 |
+
[build-system]
|
59 |
+
requires = ["poetry-core"]
|
60 |
+
build-backend = "poetry.core.masonry.api"
|
pytest.ini
CHANGED
@@ -3,5 +3,5 @@ env_override_existing_values = 1
|
|
3 |
env_files =
|
4 |
test/.test.env
|
5 |
[path]
|
6 |
-
source =
|
7 |
-
omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
|
|
|
3 |
env_files =
|
4 |
test/.test.env
|
5 |
[path]
|
6 |
+
source = samgis
|
7 |
+
omit = ./venv/*,*tests*,*apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py,./tests/*
|
requirements_dev.txt
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
aws-lambda-powertools
|
2 |
awslambdaric
|
3 |
bson
|
|
|
4 |
geopandas
|
5 |
jmespath
|
6 |
-
|
7 |
numpy
|
8 |
onnxruntime
|
9 |
-
opencv-python
|
10 |
pillow
|
11 |
pydantic>=2.0.3
|
12 |
pytest
|
|
|
1 |
aws-lambda-powertools
|
2 |
awslambdaric
|
3 |
bson
|
4 |
+
contextily
|
5 |
geopandas
|
6 |
jmespath
|
7 |
+
myst-parser
|
8 |
numpy
|
9 |
onnxruntime
|
10 |
+
opencv-python-headless
|
11 |
pillow
|
12 |
pydantic>=2.0.3
|
13 |
pytest
|
requirements_pip.txt
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
pip
|
2 |
-
wheel
|
3 |
-
setuptools
|
|
|
|
|
|
|
|
requirements_poetry.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
poetry==1.7.1
|
samgis/__init__.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Get machine learning predictions from geodata raster images"""
|
2 |
+
# not used here but contextily_tile is imported in samgis.io.tms2geotiff
|
3 |
+
from contextily import tile as contextily_tile
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
from samgis.utilities.constants import SERVICE_NAME
|
7 |
+
|
8 |
+
|
9 |
+
PROJECT_ROOT_FOLDER = Path(globals().get("__file__", "./_")).absolute().parent.parent
|
10 |
+
MODEL_FOLDER = Path(PROJECT_ROOT_FOLDER / "machine_learning_models")
|
11 |
+
try:
|
12 |
+
from aws_lambda_powertools import Logger
|
13 |
+
|
14 |
+
app_logger = Logger(service=SERVICE_NAME)
|
15 |
+
except ModuleNotFoundError:
|
16 |
+
import loguru
|
17 |
+
|
18 |
+
def setup_logging(debug: bool = False, formatter: str = "{time} - {level} - ({extra[request_id]}) {message} "
|
19 |
+
) -> loguru.logger:
|
20 |
+
"""
|
21 |
+
Create a logging instance with log string formatter.
|
22 |
+
|
23 |
+
Args:
|
24 |
+
debug: logging debug argument
|
25 |
+
formatter: log string formatter
|
26 |
+
|
27 |
+
Returns:
|
28 |
+
Logger
|
29 |
+
|
30 |
+
"""
|
31 |
+
import sys
|
32 |
+
|
33 |
+
logger = loguru.logger
|
34 |
+
logger.remove()
|
35 |
+
level_logger = "DEBUG" if debug else "INFO"
|
36 |
+
logger.add(sys.stdout, format=formatter, level=level_logger)
|
37 |
+
logger.info(f"type_logger:{type(logger)}, logger:{logger}.")
|
38 |
+
return logger
|
39 |
+
|
40 |
+
|
41 |
+
app_logger = setup_logging(debug=True)
|
samgis/__version__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
__version__ = "1.0.0"
|
{src β samgis}/io/__init__.py
RENAMED
File without changes
|
{src β samgis}/io/coordinates_pixel_conversion.py
RENAMED
@@ -1,8 +1,8 @@
|
|
1 |
"""functions useful to convert to/from latitude-longitude coordinates to pixel image coordinates"""
|
2 |
-
from
|
3 |
-
from
|
4 |
-
from
|
5 |
-
from
|
6 |
|
7 |
|
8 |
def _get_latlng2pixel_projection(latlng: LatLngDict) -> ImagePixelCoordinates:
|
|
|
1 |
"""functions useful to convert to/from latitude-longitude coordinates to pixel image coordinates"""
|
2 |
+
from samgis import app_logger
|
3 |
+
from samgis.utilities.constants import TILE_SIZE, EARTH_EQUATORIAL_RADIUS
|
4 |
+
from samgis.utilities.type_hints import ImagePixelCoordinates, tuple_float, tuple_float_any
|
5 |
+
from samgis.utilities.type_hints import LatLngDict
|
6 |
|
7 |
|
8 |
def _get_latlng2pixel_projection(latlng: LatLngDict) -> ImagePixelCoordinates:
|
{src β samgis}/io/geo_helpers.py
RENAMED
@@ -2,8 +2,8 @@
|
|
2 |
from affine import Affine
|
3 |
from numpy import ndarray as np_ndarray
|
4 |
|
5 |
-
from
|
6 |
-
from
|
7 |
|
8 |
|
9 |
def load_affine_transformation_from_matrix(matrix_source_coefficients: list_float) -> Affine:
|
|
|
2 |
from affine import Affine
|
3 |
from numpy import ndarray as np_ndarray
|
4 |
|
5 |
+
from samgis import app_logger
|
6 |
+
from samgis.utilities.type_hints import list_float, tuple_float, dict_str_int
|
7 |
|
8 |
|
9 |
def load_affine_transformation_from_matrix(matrix_source_coefficients: list_float) -> Affine:
|
{src β samgis}/io/lambda_helpers.py
RENAMED
@@ -1,13 +1,12 @@
|
|
1 |
"""lambda helper functions"""
|
2 |
from typing import Dict
|
3 |
from xyzservices import providers
|
4 |
-
from aws_lambda_powertools.event_handler import content_types
|
5 |
|
6 |
-
from
|
7 |
-
from
|
8 |
-
from
|
9 |
-
from
|
10 |
-
from
|
11 |
|
12 |
|
13 |
def get_response(status: int, start_time: float, request_id: str, response_body: Dict = None) -> str:
|
@@ -34,7 +33,7 @@ def get_response(status: int, start_time: float, request_id: str, response_body:
|
|
34 |
|
35 |
response = {
|
36 |
"statusCode": status,
|
37 |
-
"header": {"Content-Type":
|
38 |
"body": dumps(response_body),
|
39 |
"isBase64Encoded": False
|
40 |
}
|
@@ -154,7 +153,7 @@ def get_parsed_request_body(event: Dict or str) -> ApiRequestBody:
|
|
154 |
|
155 |
|
156 |
def get_url_tile(source_type: str):
|
157 |
-
from
|
158 |
|
159 |
if source_type.lower() == DEFAULT_TMS_NAME_SHORT:
|
160 |
return providers.query_name(DEFAULT_TMS_NAME)
|
|
|
1 |
"""lambda helper functions"""
|
2 |
from typing import Dict
|
3 |
from xyzservices import providers
|
|
|
4 |
|
5 |
+
from samgis import app_logger
|
6 |
+
from samgis.io.coordinates_pixel_conversion import get_latlng_to_pixel_coordinates
|
7 |
+
from samgis.utilities.constants import CUSTOM_RESPONSE_MESSAGES
|
8 |
+
from samgis.utilities.type_hints import ApiRequestBody, ContentTypes
|
9 |
+
from samgis.utilities.utilities import base64_decode
|
10 |
|
11 |
|
12 |
def get_response(status: int, start_time: float, request_id: str, response_body: Dict = None) -> str:
|
|
|
33 |
|
34 |
response = {
|
35 |
"statusCode": status,
|
36 |
+
"header": {"Content-Type": ContentTypes.APPLICATION_JSON},
|
37 |
"body": dumps(response_body),
|
38 |
"isBase64Encoded": False
|
39 |
}
|
|
|
153 |
|
154 |
|
155 |
def get_url_tile(source_type: str):
|
156 |
+
from samgis.utilities.constants import DEFAULT_TMS_NAME, DEFAULT_TMS_NAME_SHORT
|
157 |
|
158 |
if source_type.lower() == DEFAULT_TMS_NAME_SHORT:
|
159 |
return providers.query_name(DEFAULT_TMS_NAME)
|
{src β samgis}/io/tms2geotiff.py
RENAMED
@@ -2,10 +2,10 @@ import os
|
|
2 |
from numpy import ndarray
|
3 |
from xyzservices import TileProvider
|
4 |
|
5 |
-
from
|
6 |
-
from
|
7 |
-
|
8 |
-
from
|
9 |
|
10 |
bool_use_cache = int(os.getenv("BOOL_USE_CACHE", BOOL_USE_CACHE))
|
11 |
n_connection = int(os.getenv("N_CONNECTION", N_CONNECTION))
|
@@ -48,8 +48,8 @@ def download_extent(w: float, s: float, e: float, n: float, zoom: int or str = z
|
|
48 |
parsed request input
|
49 |
"""
|
50 |
try:
|
51 |
-
from
|
52 |
-
from
|
53 |
|
54 |
app_logger.info(f"connection number:{n_connections}, type:{type(n_connections)}.")
|
55 |
app_logger.info(f"zoom:{zoom}, type:{type(zoom)}.")
|
|
|
2 |
from numpy import ndarray
|
3 |
from xyzservices import TileProvider
|
4 |
|
5 |
+
from samgis import app_logger
|
6 |
+
from samgis.utilities.constants import (OUTPUT_CRS_STRING, DRIVER_RASTERIO_GTIFF, N_MAX_RETRIES, N_CONNECTION, N_WAIT,
|
7 |
+
ZOOM_AUTO, BOOL_USE_CACHE)
|
8 |
+
from samgis.utilities.type_hints import tuple_ndarray_transform, tuple_float
|
9 |
|
10 |
bool_use_cache = int(os.getenv("BOOL_USE_CACHE", BOOL_USE_CACHE))
|
11 |
n_connection = int(os.getenv("N_CONNECTION", N_CONNECTION))
|
|
|
48 |
parsed request input
|
49 |
"""
|
50 |
try:
|
51 |
+
from samgis import contextily_tile
|
52 |
+
from samgis.io.coordinates_pixel_conversion import _from4326_to3857
|
53 |
|
54 |
app_logger.info(f"connection number:{n_connections}, type:{type(n_connections)}.")
|
55 |
app_logger.info(f"zoom:{zoom}, type:{type(zoom)}.")
|
{src β samgis}/prediction_api/__init__.py
RENAMED
File without changes
|
{src β samgis}/prediction_api/predictors.py
RENAMED
@@ -1,12 +1,12 @@
|
|
1 |
"""functions using machine learning instance model(s)"""
|
2 |
from numpy import array as np_array, uint8, zeros, ndarray
|
3 |
|
4 |
-
from
|
5 |
-
from
|
6 |
-
from
|
7 |
-
from
|
8 |
-
from
|
9 |
-
from
|
10 |
|
11 |
models_dict = {"fastsam": {"instance": None}}
|
12 |
|
|
|
1 |
"""functions using machine learning instance model(s)"""
|
2 |
from numpy import array as np_array, uint8, zeros, ndarray
|
3 |
|
4 |
+
from samgis import app_logger, MODEL_FOLDER
|
5 |
+
from samgis.io.geo_helpers import get_vectorized_raster_as_geojson
|
6 |
+
from samgis.io.tms2geotiff import download_extent
|
7 |
+
from samgis.prediction_api.sam_onnx import SegmentAnythingONNX
|
8 |
+
from samgis.utilities.constants import MODEL_ENCODER_NAME, MODEL_DECODER_NAME, DEFAULT_TMS
|
9 |
+
from samgis.utilities.type_hints import llist_float, dict_str_int, list_dict, tuple_ndarr_int, PIL_Image
|
10 |
|
11 |
models_dict = {"fastsam": {"instance": None}}
|
12 |
|
{src β samgis}/prediction_api/sam_onnx.py
RENAMED
@@ -28,7 +28,7 @@ from numpy import array as np_array, concatenate, float32, linalg, matmul, ndarr
|
|
28 |
from cv2 import INTER_LINEAR, warpAffine
|
29 |
from onnxruntime import get_available_providers, InferenceSession
|
30 |
|
31 |
-
from
|
32 |
|
33 |
|
34 |
class SegmentAnythingONNX:
|
|
|
28 |
from cv2 import INTER_LINEAR, warpAffine
|
29 |
from onnxruntime import get_available_providers, InferenceSession
|
30 |
|
31 |
+
from samgis import app_logger
|
32 |
|
33 |
|
34 |
class SegmentAnythingONNX:
|
{src β samgis}/utilities/__init__.py
RENAMED
File without changes
|
{src β samgis}/utilities/constants.py
RENAMED
File without changes
|
{src β samgis}/utilities/serialize.py
RENAMED
@@ -1,8 +1,8 @@
|
|
1 |
"""Serialize objects"""
|
2 |
from typing import Mapping
|
3 |
|
4 |
-
from
|
5 |
-
from
|
6 |
|
7 |
|
8 |
def serialize(obj: any, include_none: bool = False):
|
|
|
1 |
"""Serialize objects"""
|
2 |
from typing import Mapping
|
3 |
|
4 |
+
from samgis import app_logger
|
5 |
+
from samgis.utilities.type_hints import dict_str, dict_str_any
|
6 |
|
7 |
|
8 |
def serialize(obj: any, include_none: bool = False):
|
{src β samgis}/utilities/type_hints.py
RENAMED
@@ -7,7 +7,7 @@ from affine import Affine
|
|
7 |
from numpy import ndarray
|
8 |
from pydantic import BaseModel
|
9 |
|
10 |
-
from
|
11 |
|
12 |
|
13 |
dict_str_int = dict[str, int]
|
@@ -31,6 +31,13 @@ class LatLngDict(BaseModel):
|
|
31 |
lng: float
|
32 |
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
class PromptPointType(str, Enum):
|
35 |
"""Segment Anything: validation point prompt type"""
|
36 |
point = "point"
|
|
|
7 |
from numpy import ndarray
|
8 |
from pydantic import BaseModel
|
9 |
|
10 |
+
from samgis.utilities.constants import DEFAULT_TMS
|
11 |
|
12 |
|
13 |
dict_str_int = dict[str, int]
|
|
|
31 |
lng: float
|
32 |
|
33 |
|
34 |
+
class ContentTypes(str, Enum):
|
35 |
+
"""Segment Anything: validation point prompt type"""
|
36 |
+
APPLICATION_JSON = "application/json"
|
37 |
+
TEXT_PLAIN = "text/plain"
|
38 |
+
TEXT_HTML = "text/html"
|
39 |
+
|
40 |
+
|
41 |
class PromptPointType(str, Enum):
|
42 |
"""Segment Anything: validation point prompt type"""
|
43 |
point = "point"
|
{src β samgis}/utilities/utilities.py
RENAMED
@@ -1,6 +1,6 @@
|
|
1 |
"""Various utilities (logger, time benchmark, args dump, numerical and stats info)"""
|
2 |
-
from
|
3 |
-
from
|
4 |
|
5 |
|
6 |
def _prepare_base64_input(sb):
|
|
|
1 |
"""Various utilities (logger, time benchmark, args dump, numerical and stats info)"""
|
2 |
+
from samgis import app_logger
|
3 |
+
from samgis.utilities.serialize import serialize
|
4 |
|
5 |
|
6 |
def _prepare_base64_input(sb):
|
scripts/lambda-entrypoint.sh
CHANGED
@@ -1,7 +1,17 @@
|
|
1 |
#!/bin/sh
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
|
4 |
-
exec /usr/local/bin/aws-lambda-rie
|
5 |
else
|
6 |
-
exec
|
7 |
fi
|
|
|
1 |
#!/bin/sh
|
2 |
|
3 |
+
# default value for PYTHONBIN=/usr/local/bin/python
|
4 |
+
# but it change because of poetry that it uses a virtualenv installed within the LAMBDA_TASK_ROOT=/var/task
|
5 |
+
|
6 |
+
echo "python installation path and version:"
|
7 |
+
which python
|
8 |
+
python --version
|
9 |
+
|
10 |
+
echo "lambda-entrypoint.sh: PYTHONPATH ${PYTHONPATH} ..."
|
11 |
+
echo "lambda-entrypoint.sh: PATH ${PATH} ..."
|
12 |
+
|
13 |
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
|
14 |
+
exec /usr/local/bin/aws-lambda-rie python -m awslambdaric "$@"
|
15 |
else
|
16 |
+
exec python -m awslambdaric "$@"
|
17 |
fi
|
src/__init__.py
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
"""Get machine learning predictions from geodata raster images"""
|
2 |
-
from aws_lambda_powertools import Logger
|
3 |
-
# not used here but contextily_tile is imported in src.io.tms2geotiff
|
4 |
-
from contextily import tile as contextily_tile
|
5 |
-
from pathlib import Path
|
6 |
-
|
7 |
-
from src.utilities.constants import SERVICE_NAME
|
8 |
-
|
9 |
-
|
10 |
-
PROJECT_ROOT_FOLDER = Path(globals().get("__file__", "./_")).absolute().parent.parent
|
11 |
-
MODEL_FOLDER = Path(PROJECT_ROOT_FOLDER / "machine_learning_models")
|
12 |
-
app_logger = Logger(service=SERVICE_NAME)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Logs
|
2 |
+
logs
|
3 |
+
*.log
|
4 |
+
npm-debug.log*
|
5 |
+
yarn-debug.log*
|
6 |
+
yarn-error.log*
|
7 |
+
pnpm-debug.log*
|
8 |
+
lerna-debug.log*
|
9 |
+
|
10 |
+
node_modules
|
11 |
+
.DS_Store
|
12 |
+
dist
|
13 |
+
dist-ssr
|
14 |
+
coverage
|
15 |
+
*.local
|
16 |
+
|
17 |
+
tmp*/*
|
18 |
+
/cypress/videos/
|
19 |
+
/cypress/screenshots/
|
20 |
+
vite.config.ts.*
|
21 |
+
|
22 |
+
# Editor directories and files
|
23 |
+
.vscode/*
|
24 |
+
!.vscode/extensions.json
|
25 |
+
.idea
|
26 |
+
*.suo
|
27 |
+
*.ntvs*
|
28 |
+
*.njsproj
|
29 |
+
*.sln
|
30 |
+
*.sw?
|
31 |
+
|
32 |
+
test-results/
|
33 |
+
playwright-report/
|
34 |
+
|
35 |
+
.env*
|
36 |
+
|
37 |
+
# cloudflare workers
|
38 |
+
.wrangler
|
static/.prettierrc.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"$schema": "https://json.schemastore.org/prettierrc",
|
3 |
+
"semi": false,
|
4 |
+
"tabWidth": 2,
|
5 |
+
"singleQuote": true,
|
6 |
+
"printWidth": 100,
|
7 |
+
"trailingComma": "none"
|
8 |
+
}
|
static/LICENSE
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Apache License
|
2 |
+
Version 2.0, January 2004
|
3 |
+
http://www.apache.org/licenses/
|
4 |
+
|
5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6 |
+
|
7 |
+
1. Definitions.
|
8 |
+
|
9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
11 |
+
|
12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13 |
+
the copyright owner that is granting the License.
|
14 |
+
|
15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
16 |
+
other entities that control, are controlled by, or are under common
|
17 |
+
control with that entity. For the purposes of this definition,
|
18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
19 |
+
direction or management of such entity, whether by contract or
|
20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22 |
+
|
23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24 |
+
exercising permissions granted by this License.
|
25 |
+
|
26 |
+
"Source" form shall mean the preferred form for making modifications,
|
27 |
+
including but not limited to software source code, documentation
|
28 |
+
source, and configuration files.
|
29 |
+
|
30 |
+
"Object" form shall mean any form resulting from mechanical
|
31 |
+
transformation or translation of a Source form, including but
|
32 |
+
not limited to compiled object code, generated documentation,
|
33 |
+
and conversions to other media types.
|
34 |
+
|
35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
36 |
+
Object form, made available under the License, as indicated by a
|
37 |
+
copyright notice that is included in or attached to the work
|
38 |
+
(an example is provided in the Appendix below).
|
39 |
+
|
40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41 |
+
form, that is based on (or derived from) the Work and for which the
|
42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
44 |
+
of this License, Derivative Works shall not include works that remain
|
45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46 |
+
the Work and Derivative Works thereof.
|
47 |
+
|
48 |
+
"Contribution" shall mean any work of authorship, including
|
49 |
+
the original version of the Work and any modifications or additions
|
50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
54 |
+
means any form of electronic, verbal, or written communication sent
|
55 |
+
to the Licensor or its representatives, including but not limited to
|
56 |
+
communication on electronic mailing lists, source code control systems,
|
57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
59 |
+
excluding communication that is conspicuously marked or otherwise
|
60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
61 |
+
|
62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
64 |
+
subsequently incorporated within the Work.
|
65 |
+
|
66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
71 |
+
Work and such Derivative Works in Source or Object form.
|
72 |
+
|
73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76 |
+
(except as stated in this section) patent license to make, have made,
|
77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78 |
+
where such license applies only to those patent claims licensable
|
79 |
+
by such Contributor that are necessarily infringed by their
|
80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
82 |
+
institute patent litigation against any entity (including a
|
83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84 |
+
or a Contribution incorporated within the Work constitutes direct
|
85 |
+
or contributory patent infringement, then any patent licenses
|
86 |
+
granted to You under this License for that Work shall terminate
|
87 |
+
as of the date such litigation is filed.
|
88 |
+
|
89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
90 |
+
Work or Derivative Works thereof in any medium, with or without
|
91 |
+
modifications, and in Source or Object form, provided that You
|
92 |
+
meet the following conditions:
|
93 |
+
|
94 |
+
(a) You must give any other recipients of the Work or
|
95 |
+
Derivative Works a copy of this License; and
|
96 |
+
|
97 |
+
(b) You must cause any modified files to carry prominent notices
|
98 |
+
stating that You changed the files; and
|
99 |
+
|
100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
101 |
+
that You distribute, all copyright, patent, trademark, and
|
102 |
+
attribution notices from the Source form of the Work,
|
103 |
+
excluding those notices that do not pertain to any part of
|
104 |
+
the Derivative Works; and
|
105 |
+
|
106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107 |
+
distribution, then any Derivative Works that You distribute must
|
108 |
+
include a readable copy of the attribution notices contained
|
109 |
+
within such NOTICE file, excluding those notices that do not
|
110 |
+
pertain to any part of the Derivative Works, in at least one
|
111 |
+
of the following places: within a NOTICE text file distributed
|
112 |
+
as part of the Derivative Works; within the Source form or
|
113 |
+
documentation, if provided along with the Derivative Works; or,
|
114 |
+
within a display generated by the Derivative Works, if and
|
115 |
+
wherever such third-party notices normally appear. The contents
|
116 |
+
of the NOTICE file are for informational purposes only and
|
117 |
+
do not modify the License. You may add Your own attribution
|
118 |
+
notices within Derivative Works that You distribute, alongside
|
119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
120 |
+
that such additional attribution notices cannot be construed
|
121 |
+
as modifying the License.
|
122 |
+
|
123 |
+
You may add Your own copyright statement to Your modifications and
|
124 |
+
may provide additional or different license terms and conditions
|
125 |
+
for use, reproduction, or distribution of Your modifications, or
|
126 |
+
for any such Derivative Works as a whole, provided Your use,
|
127 |
+
reproduction, and distribution of the Work otherwise complies with
|
128 |
+
the conditions stated in this License.
|
129 |
+
|
130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
132 |
+
by You to the Licensor shall be under the terms and conditions of
|
133 |
+
this License, without any additional terms or conditions.
|
134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135 |
+
the terms of any separate license agreement you may have executed
|
136 |
+
with Licensor regarding such Contributions.
|
137 |
+
|
138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
140 |
+
except as required for reasonable and customary use in describing the
|
141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
142 |
+
|
143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144 |
+
agreed to in writing, Licensor provides the Work (and each
|
145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147 |
+
implied, including, without limitation, any warranties or conditions
|
148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150 |
+
appropriateness of using or redistributing the Work and assume any
|
151 |
+
risks associated with Your exercise of permissions under this License.
|
152 |
+
|
153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
154 |
+
whether in tort (including negligence), contract, or otherwise,
|
155 |
+
unless required by applicable law (such as deliberate and grossly
|
156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157 |
+
liable to You for damages, including any direct, indirect, special,
|
158 |
+
incidental, or consequential damages of any character arising as a
|
159 |
+
result of this License or out of the use or inability to use the
|
160 |
+
Work (including but not limited to damages for loss of goodwill,
|
161 |
+
work stoppage, computer failure or malfunction, or any and all
|
162 |
+
other commercial damages or losses), even if such Contributor
|
163 |
+
has been advised of the possibility of such damages.
|
164 |
+
|
165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168 |
+
or other liability obligations and/or rights consistent with this
|
169 |
+
License. However, in accepting such obligations, You may act only
|
170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171 |
+
of any other Contributor, and only if You agree to indemnify,
|
172 |
+
defend, and hold each Contributor harmless for any liability
|
173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
174 |
+
of your accepting any such warranty or additional liability.
|
175 |
+
|
176 |
+
END OF TERMS AND CONDITIONS
|
static/NOTICE
ADDED
The diff for this file is too large to render.
See raw diff
|
|
static/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# ml-tornidor
|
2 |
+
|
3 |
+
## Local development
|
4 |
+
|
5 |
+
Since I use Cloudflare pages as hosting for this project there are some required steps to do before it's possible to start a local development environment. This project needs to wrap the node commands with the `npx wrangler [...]` utility to emulate a Cloudflare Worker function. Because this worker function is under auth which use some env variables I to write these env variables inline. Every time I changed or added needed some variables I also needed to update the `npx wrangler` command. To avoid this I prepared a js script, executed by [Deno](https://deno.land/), that read the env variables from the `.env` file composing the command:
|
6 |
+
|
7 |
+
1. prepare the .env file copying the template.env file
|
8 |
+
2. run the local environment using the command `pnpm dev` or `deno run -A runner.js`
|
9 |
+
|
10 |
+
In case of new or updated packages Deno installs the dependencies at the first execution. Do it with a execution without the `npx wrangler` wrapper:
|
11 |
+
|
12 |
+
```bash
|
13 |
+
deno run -A --node-modules-dir npm:vite
|
14 |
+
```
|
15 |
+
|
16 |
+
In case of problem:
|
17 |
+
|
18 |
+
1. try executing again the command `deno run -A --node-modules-dir npm:vite`
|
19 |
+
|
20 |
+
If this don't solve the problems try to
|
21 |
+
|
22 |
+
1. delete the node_modules folder
|
23 |
+
2. reinstall the npm packages with `pnpm install`
|
24 |
+
3. Run again the local development server, this time with the standard command
|
25 |
+
|
26 |
+
Before to commit try also to build using
|
27 |
+
|
28 |
+
```bash
|
29 |
+
pnpm build
|
30 |
+
```
|
31 |
+
|
32 |
+
Then run the preview (change the example variables):
|
33 |
+
|
34 |
+
```bash
|
35 |
+
npx wrangler pages dev --binding VITE_AUTH0_DOMAIN="example-auth0.eu.auth0.com" API_URL="https://example-aws.execute-api.eu-west-1.amazonaws.com/localhost/lambda-ml-fastsam-api" VITE_AUTH0_AUDIENCE="http://localhost-ml-lambda/" API_DOMAIN=example-aws.execute-api.eu-west-1.amazonaws.com CORS_ALLOWED_DOMAIN=http://localhost:8788 VITE_SATELLITE_NAME="tile-provider.image-type" -- pnpm preview
|
36 |
+
```
|
static/env.d.ts
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
/// <reference types="vite/client" />
|
static/index.html
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<link href="output.css" rel="stylesheet" type="text/css">
|
7 |
+
<link href="dist/output.css" rel="stylesheet" type="text/css">
|
8 |
+
<link rel="icon" href="/favicon.ico" sizes="32x32">
|
9 |
+
<link rel="icon" href="/icon.svg" type="image/svg+xml">
|
10 |
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png"><!-- 180Γ180 -->
|
11 |
+
<link rel="manifest" href="/manifest.webmanifest">
|
12 |
+
<title>ML on GIS</title>
|
13 |
+
</head>
|
14 |
+
<body>
|
15 |
+
<div id="root"></div>
|
16 |
+
<script type="module" src="/src/main.ts"></script>
|
17 |
+
</body>
|
18 |
+
</html>
|