alessandro trinca tornidor commited on
Commit
bb6e1c0
1 Parent(s): 7c49edb

feat: use everywhere a single app_logger instance defined in samgis_lisa_on_zero.__init__

Browse files
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import json
2
- import logging
3
  import os
4
  import pathlib
5
  from typing import Callable, NoReturn
@@ -15,13 +14,11 @@ from fastapi.templating import Jinja2Templates
15
  from lisa_on_cuda.utils import app_helpers, frontend_builder, create_folders_and_variables_if_not_exists, session_logger
16
  from pydantic import ValidationError
17
 
18
- from samgis_lisa_on_zero import PROJECT_ROOT_FOLDER, WORKDIR
19
  from samgis_lisa_on_zero.utilities.constants import GRADIO_EXAMPLE_BODY, GRADIO_EXAMPLES_TEXT_LIST, GRADIO_MARKDOWN
20
  from samgis_lisa_on_zero.utilities.type_hints import StringPromptApiRequestBody
21
 
22
 
23
- loglevel = os.getenv('LOGLEVEL', 'INFO').upper()
24
- session_logger.change_logging(loglevel)
25
  VITE_INDEX_URL = os.getenv("VITE_INDEX_URL", "/")
26
  VITE_SAMGIS_URL = os.getenv("VITE_SAMGIS_URL", "/samgis")
27
  VITE_LISA_URL = os.getenv("VITE_LISA_URL", "/lisa")
@@ -33,7 +30,7 @@ app = FastAPI(title=FASTAPI_TITLE, version="1.0")
33
  @spaces.GPU
34
  @session_logger.set_uuid_logging
35
  def gpu_initialization() -> None:
36
- logging.info("GPU initialization...")
37
 
38
 
39
  def get_example_complete(example_text):
@@ -73,13 +70,13 @@ def handle_exception_response(exception: Exception) -> NoReturn:
73
  project_root_folder_content = subprocess.run(
74
  f"ls -l {PROJECT_ROOT_FOLDER}/", shell=True, universal_newlines=True, stdout=subprocess.PIPE
75
  )
76
- logging.error(f"project_root folder 'ls -l' command output: {project_root_folder_content.stdout}.")
77
  workdir_folder_content = subprocess.run(
78
  f"ls -l {WORKDIR}/", shell=True, universal_newlines=True, stdout=subprocess.PIPE
79
  )
80
- logging.error(f"workdir folder 'ls -l' command stdout: {workdir_folder_content.stdout}.")
81
- logging.error(f"workdir folder 'ls -l' command stderr: {workdir_folder_content.stderr}.")
82
- logging.error(f"inference error:{exception}.")
83
  raise HTTPException(
84
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Internal server error on inference"
85
  )
@@ -97,13 +94,13 @@ def health() -> JSONResponse:
97
  lisa_on_cuda_version = importlib.metadata.version('lisa-on-cuda')
98
  samgis_lisa_on_cuda_version = importlib.metadata.version('samgis-lisa-on-zero')
99
  except PackageNotFoundError as pe:
100
- logging.error(f"pe:{pe}.")
101
 
102
  msg = "still alive, "
103
  msg += f"""version:{samgis_lisa_on_cuda_version}, core version:{core_version},"""
104
  msg += f"""lisa-on-cuda version:{lisa_on_cuda_version},"""
105
 
106
- logging.info(msg)
107
  return JSONResponse(status_code=200, content={"msg": "still alive..."})
108
 
109
 
@@ -113,39 +110,39 @@ def infer_lisa_gradio(request_input: StringPromptApiRequestBody) -> str:
113
  from samgis_lisa_on_zero.prediction_api import lisa
114
  from samgis_lisa_on_zero.utilities.constants import LISA_INFERENCE_FN
115
 
116
- logging.info("starting lisa inference request...")
117
 
118
  try:
119
  import time
120
 
121
  time_start_run = time.time()
122
  body_request = get_parsed_bbox_points_with_string_prompt(request_input)
123
- logging.info(f"lisa body_request:{body_request}.")
124
  try:
125
  source = body_request["source"]
126
  source_name = body_request["source_name"]
127
- logging.debug(f"body_request:type(source):{type(source)}, source:{source}.")
128
- logging.debug(f"body_request:type(source_name):{type(source_name)}, source_name:{source_name}.")
129
- logging.debug(f"lisa module:{lisa}.")
130
  gpu_initialization()
131
  output = lisa.lisa_predict(
132
  bbox=body_request["bbox"], prompt=body_request["prompt"], zoom=body_request["zoom"],
133
  source=source, source_name=source_name, inference_function_name_key=LISA_INFERENCE_FN
134
  )
135
  duration_run = time.time() - time_start_run
136
- logging.info(f"duration_run:{duration_run}.")
137
  body = {
138
  "duration_run": duration_run,
139
  "output": output
140
  }
141
  dumped = json.dumps(body)
142
- logging.info(f"json.dumps(body) type:{type(dumped)}, len:{len(dumped)}.")
143
- logging.debug(f"complete json.dumps(body):{dumped}.")
144
  return dumped
145
  except Exception as inference_exception:
146
  handle_exception_response(inference_exception)
147
  except ValidationError as va1:
148
- logging.error(f"validation error: {str(va1)}.")
149
  raise ValidationError("Unprocessable Entity")
150
 
151
 
@@ -153,20 +150,20 @@ def infer_lisa_gradio(request_input: StringPromptApiRequestBody) -> str:
153
  @app.post("/infer_lisa")
154
  def infer_lisa(request_input: StringPromptApiRequestBody) -> JSONResponse:
155
  dumped = infer_lisa_gradio(request_input=request_input)
156
- logging.info(f"json.dumps(body) type:{type(dumped)}, len:{len(dumped)}.")
157
- logging.debug(f"complete json.dumps(body):{dumped}.")
158
  return JSONResponse(status_code=200, content={"body": dumped})
159
 
160
 
161
  @app.exception_handler(RequestValidationError)
162
  @session_logger.set_uuid_logging
163
  def request_validation_exception_handler(request: Request, exc: RequestValidationError) -> JSONResponse:
164
- logging.error(f"exception errors: {exc.errors()}.")
165
- logging.error(f"exception body: {exc.body}.")
166
  headers = request.headers.items()
167
- logging.error(f'request header: {dict(headers)}.')
168
  params = request.query_params.items()
169
- logging.error(f'request query params: {dict(params)}.')
170
  return JSONResponse(
171
  status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
172
  content={"msg": "Error - Unprocessable Entity"}
@@ -176,11 +173,11 @@ def request_validation_exception_handler(request: Request, exc: RequestValidatio
176
  @app.exception_handler(HTTPException)
177
  @session_logger.set_uuid_logging
178
  def http_exception_handler(request: Request, exc: HTTPException) -> JSONResponse:
179
- logging.error(f"exception: {str(exc)}.")
180
  headers = request.headers.items()
181
- logging.error(f'request header: {dict(headers)}.')
182
  params = request.query_params.items()
183
- logging.error(f'request query params: {dict(params)}.')
184
  return JSONResponse(
185
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
186
  content={"msg": "Error - Internal Server Error"}
@@ -188,21 +185,21 @@ def http_exception_handler(request: Request, exc: HTTPException) -> JSONResponse
188
 
189
 
190
  write_tmp_on_disk = os.getenv("WRITE_TMP_ON_DISK", "")
191
- logging.info(f"write_tmp_on_disk:{write_tmp_on_disk}.")
192
  if bool(write_tmp_on_disk):
193
  try:
194
  path_write_tmp_on_disk = pathlib.Path(write_tmp_on_disk)
195
  try:
196
  pathlib.Path.unlink(path_write_tmp_on_disk, missing_ok=True)
197
  except (IsADirectoryError, PermissionError, OSError) as err:
198
- logging.error(f"{err} while removing old write_tmp_on_disk:{write_tmp_on_disk}.")
199
- logging.error(f"is file?{path_write_tmp_on_disk.is_file()}.")
200
- logging.error(f"is symlink?{path_write_tmp_on_disk.is_symlink()}.")
201
- logging.error(f"is folder?{path_write_tmp_on_disk.is_dir()}.")
202
  os.makedirs(write_tmp_on_disk, exist_ok=True)
203
  app.mount("/vis_output", StaticFiles(directory=write_tmp_on_disk), name="vis_output")
204
  except RuntimeError as runtime_error:
205
- logging.error(f"{runtime_error} while loading the folder write_tmp_on_disk:{write_tmp_on_disk}...")
206
  raise runtime_error
207
  templates = Jinja2Templates(directory=WORKDIR / "static")
208
 
@@ -225,7 +222,7 @@ frontend_builder.build_frontend(
225
  )
226
  create_folders_and_variables_if_not_exists.folders_creation()
227
 
228
- logging.info("build_frontend ok!")
229
 
230
  templates = Jinja2Templates(directory="templates")
231
 
@@ -258,20 +255,18 @@ async def index() -> FileResponse:
258
  return FileResponse(path=static_dist_folder / "index.html", media_type="text/html")
259
 
260
 
261
- app_helpers.logging.info(f"creating gradio interface...")
262
  io = get_gradio_interface_geojson(infer_lisa_gradio)
263
- app_helpers.logging.info(
264
  f"gradio interface created, mounting gradio app on url {VITE_GRADIO_URL} within FastAPI...")
265
  app = gr.mount_gradio_app(app, io, path=VITE_GRADIO_URL)
266
- app_helpers.logging.info("mounted gradio app within fastapi")
267
 
268
 
269
  if __name__ == '__main__':
270
  try:
271
  uvicorn.run(host="0.0.0.0", port=7860, app=app)
272
  except Exception as ex:
273
- import logging
274
-
275
- logging.error(f"fastapi/gradio application {FASTAPI_TITLE}, exception:{ex}.")
276
  print(f"fastapi/gradio application {FASTAPI_TITLE}, exception:{ex}.")
277
  raise ex
 
1
  import json
 
2
  import os
3
  import pathlib
4
  from typing import Callable, NoReturn
 
14
  from lisa_on_cuda.utils import app_helpers, frontend_builder, create_folders_and_variables_if_not_exists, session_logger
15
  from pydantic import ValidationError
16
 
17
+ from samgis_lisa_on_zero import PROJECT_ROOT_FOLDER, WORKDIR, app_logger
18
  from samgis_lisa_on_zero.utilities.constants import GRADIO_EXAMPLE_BODY, GRADIO_EXAMPLES_TEXT_LIST, GRADIO_MARKDOWN
19
  from samgis_lisa_on_zero.utilities.type_hints import StringPromptApiRequestBody
20
 
21
 
 
 
22
  VITE_INDEX_URL = os.getenv("VITE_INDEX_URL", "/")
23
  VITE_SAMGIS_URL = os.getenv("VITE_SAMGIS_URL", "/samgis")
24
  VITE_LISA_URL = os.getenv("VITE_LISA_URL", "/lisa")
 
30
  @spaces.GPU
31
  @session_logger.set_uuid_logging
32
  def gpu_initialization() -> None:
33
+ app_logger.info("GPU initialization...")
34
 
35
 
36
  def get_example_complete(example_text):
 
70
  project_root_folder_content = subprocess.run(
71
  f"ls -l {PROJECT_ROOT_FOLDER}/", shell=True, universal_newlines=True, stdout=subprocess.PIPE
72
  )
73
+ app_logger.error(f"project_root folder 'ls -l' command output: {project_root_folder_content.stdout}.")
74
  workdir_folder_content = subprocess.run(
75
  f"ls -l {WORKDIR}/", shell=True, universal_newlines=True, stdout=subprocess.PIPE
76
  )
77
+ app_logger.error(f"workdir folder 'ls -l' command stdout: {workdir_folder_content.stdout}.")
78
+ app_logger.error(f"workdir folder 'ls -l' command stderr: {workdir_folder_content.stderr}.")
79
+ app_logger.error(f"inference error:{exception}.")
80
  raise HTTPException(
81
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="Internal server error on inference"
82
  )
 
94
  lisa_on_cuda_version = importlib.metadata.version('lisa-on-cuda')
95
  samgis_lisa_on_cuda_version = importlib.metadata.version('samgis-lisa-on-zero')
96
  except PackageNotFoundError as pe:
97
+ app_logger.error(f"pe:{pe}.")
98
 
99
  msg = "still alive, "
100
  msg += f"""version:{samgis_lisa_on_cuda_version}, core version:{core_version},"""
101
  msg += f"""lisa-on-cuda version:{lisa_on_cuda_version},"""
102
 
103
+ app_logger.info(msg)
104
  return JSONResponse(status_code=200, content={"msg": "still alive..."})
105
 
106
 
 
110
  from samgis_lisa_on_zero.prediction_api import lisa
111
  from samgis_lisa_on_zero.utilities.constants import LISA_INFERENCE_FN
112
 
113
+ app_logger.info("starting lisa inference request...")
114
 
115
  try:
116
  import time
117
 
118
  time_start_run = time.time()
119
  body_request = get_parsed_bbox_points_with_string_prompt(request_input)
120
+ app_logger.info(f"lisa body_request:{body_request}.")
121
  try:
122
  source = body_request["source"]
123
  source_name = body_request["source_name"]
124
+ app_logger.debug(f"body_request:type(source):{type(source)}, source:{source}.")
125
+ app_logger.debug(f"body_request:type(source_name):{type(source_name)}, source_name:{source_name}.")
126
+ app_logger.debug(f"lisa module:{lisa}.")
127
  gpu_initialization()
128
  output = lisa.lisa_predict(
129
  bbox=body_request["bbox"], prompt=body_request["prompt"], zoom=body_request["zoom"],
130
  source=source, source_name=source_name, inference_function_name_key=LISA_INFERENCE_FN
131
  )
132
  duration_run = time.time() - time_start_run
133
+ app_logger.info(f"duration_run:{duration_run}.")
134
  body = {
135
  "duration_run": duration_run,
136
  "output": output
137
  }
138
  dumped = json.dumps(body)
139
+ app_logger.info(f"json.dumps(body) type:{type(dumped)}, len:{len(dumped)}.")
140
+ app_logger.debug(f"complete json.dumps(body):{dumped}.")
141
  return dumped
142
  except Exception as inference_exception:
143
  handle_exception_response(inference_exception)
144
  except ValidationError as va1:
145
+ app_logger.error(f"validation error: {str(va1)}.")
146
  raise ValidationError("Unprocessable Entity")
147
 
148
 
 
150
  @app.post("/infer_lisa")
151
  def infer_lisa(request_input: StringPromptApiRequestBody) -> JSONResponse:
152
  dumped = infer_lisa_gradio(request_input=request_input)
153
+ app_logger.info(f"json.dumps(body) type:{type(dumped)}, len:{len(dumped)}.")
154
+ app_logger.debug(f"complete json.dumps(body):{dumped}.")
155
  return JSONResponse(status_code=200, content={"body": dumped})
156
 
157
 
158
  @app.exception_handler(RequestValidationError)
159
  @session_logger.set_uuid_logging
160
  def request_validation_exception_handler(request: Request, exc: RequestValidationError) -> JSONResponse:
161
+ app_logger.error(f"exception errors: {exc.errors()}.")
162
+ app_logger.error(f"exception body: {exc.body}.")
163
  headers = request.headers.items()
164
+ app_logger.error(f'request header: {dict(headers)}.')
165
  params = request.query_params.items()
166
+ app_logger.error(f'request query params: {dict(params)}.')
167
  return JSONResponse(
168
  status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
169
  content={"msg": "Error - Unprocessable Entity"}
 
173
  @app.exception_handler(HTTPException)
174
  @session_logger.set_uuid_logging
175
  def http_exception_handler(request: Request, exc: HTTPException) -> JSONResponse:
176
+ app_logger.error(f"exception: {str(exc)}.")
177
  headers = request.headers.items()
178
+ app_logger.error(f'request header: {dict(headers)}.')
179
  params = request.query_params.items()
180
+ app_logger.error(f'request query params: {dict(params)}.')
181
  return JSONResponse(
182
  status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
183
  content={"msg": "Error - Internal Server Error"}
 
185
 
186
 
187
  write_tmp_on_disk = os.getenv("WRITE_TMP_ON_DISK", "")
188
+ app_logger.info(f"write_tmp_on_disk:{write_tmp_on_disk}.")
189
  if bool(write_tmp_on_disk):
190
  try:
191
  path_write_tmp_on_disk = pathlib.Path(write_tmp_on_disk)
192
  try:
193
  pathlib.Path.unlink(path_write_tmp_on_disk, missing_ok=True)
194
  except (IsADirectoryError, PermissionError, OSError) as err:
195
+ app_logger.error(f"{err} while removing old write_tmp_on_disk:{write_tmp_on_disk}.")
196
+ app_logger.error(f"is file?{path_write_tmp_on_disk.is_file()}.")
197
+ app_logger.error(f"is symlink?{path_write_tmp_on_disk.is_symlink()}.")
198
+ app_logger.error(f"is folder?{path_write_tmp_on_disk.is_dir()}.")
199
  os.makedirs(write_tmp_on_disk, exist_ok=True)
200
  app.mount("/vis_output", StaticFiles(directory=write_tmp_on_disk), name="vis_output")
201
  except RuntimeError as runtime_error:
202
+ app_logger.error(f"{runtime_error} while loading the folder write_tmp_on_disk:{write_tmp_on_disk}...")
203
  raise runtime_error
204
  templates = Jinja2Templates(directory=WORKDIR / "static")
205
 
 
222
  )
223
  create_folders_and_variables_if_not_exists.folders_creation()
224
 
225
+ app_logger.info("build_frontend ok!")
226
 
227
  templates = Jinja2Templates(directory="templates")
228
 
 
255
  return FileResponse(path=static_dist_folder / "index.html", media_type="text/html")
256
 
257
 
258
+ app_helpers.app_logger.info(f"creating gradio interface...")
259
  io = get_gradio_interface_geojson(infer_lisa_gradio)
260
+ app_helpers.app_logger.info(
261
  f"gradio interface created, mounting gradio app on url {VITE_GRADIO_URL} within FastAPI...")
262
  app = gr.mount_gradio_app(app, io, path=VITE_GRADIO_URL)
263
+ app_helpers.app_logger.info("mounted gradio app within fastapi")
264
 
265
 
266
  if __name__ == '__main__':
267
  try:
268
  uvicorn.run(host="0.0.0.0", port=7860, app=app)
269
  except Exception as ex:
270
+ app_logger.error(f"fastapi/gradio application {FASTAPI_TITLE}, exception:{ex}.")
 
 
271
  print(f"fastapi/gradio application {FASTAPI_TITLE}, exception:{ex}.")
272
  raise ex
samgis_lisa_on_zero/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
  """Get machine learning predictions from geodata raster images"""
 
2
  import os
3
 
4
  # not used here but contextily_tile is imported in samgis_lisa_on_zero.io_package.tms2geotiff
@@ -6,7 +7,6 @@ from contextily import tile as contextily_tile
6
  from pathlib import Path
7
 
8
  from lisa_on_cuda.utils import session_logger
9
-
10
  from samgis_lisa_on_zero.utilities.constants import SERVICE_NAME
11
 
12
 
@@ -15,5 +15,7 @@ PROJECT_ROOT_FOLDER = Path(os.getenv("PROJECT_ROOT_FOLDER", ROOT))
15
  WORKDIR = Path(os.getenv("WORKDIR", ROOT))
16
  MODEL_FOLDER_PROJECT_ROOT_FOLDER = Path(PROJECT_ROOT_FOLDER / "machine_learning_models")
17
  MODEL_FOLDER = Path(os.getenv("MODEL_FOLDER", MODEL_FOLDER_PROJECT_ROOT_FOLDER))
 
18
  loglevel = os.getenv('LOGLEVEL', 'INFO').upper()
19
  session_logger.change_logging(loglevel)
 
 
1
  """Get machine learning predictions from geodata raster images"""
2
+ import logging
3
  import os
4
 
5
  # not used here but contextily_tile is imported in samgis_lisa_on_zero.io_package.tms2geotiff
 
7
  from pathlib import Path
8
 
9
  from lisa_on_cuda.utils import session_logger
 
10
  from samgis_lisa_on_zero.utilities.constants import SERVICE_NAME
11
 
12
 
 
15
  WORKDIR = Path(os.getenv("WORKDIR", ROOT))
16
  MODEL_FOLDER_PROJECT_ROOT_FOLDER = Path(PROJECT_ROOT_FOLDER / "machine_learning_models")
17
  MODEL_FOLDER = Path(os.getenv("MODEL_FOLDER", MODEL_FOLDER_PROJECT_ROOT_FOLDER))
18
+
19
  loglevel = os.getenv('LOGLEVEL', 'INFO').upper()
20
  session_logger.change_logging(loglevel)
21
+ app_logger = logging.getLogger(__name__)
samgis_lisa_on_zero/io_package/coordinates_pixel_conversion.py CHANGED
@@ -1,16 +1,12 @@
1
  """functions useful to convert to/from latitude-longitude coordinates to pixel image coordinates"""
2
- import logging
3
-
4
  from lisa_on_cuda.utils import session_logger
5
  from samgis_core.utilities.type_hints import TupleFloat, TupleFloatAny
 
6
  from samgis_lisa_on_zero.utilities.constants import TILE_SIZE, EARTH_EQUATORIAL_RADIUS
7
  from samgis_lisa_on_zero.utilities.type_hints import ImagePixelCoordinates
8
  from samgis_lisa_on_zero.utilities.type_hints import LatLngDict
9
 
10
 
11
- app_logger = logging.getLogger(__name__)
12
-
13
-
14
  @session_logger.set_uuid_logging
15
  def _get_latlng2pixel_projection(latlng: LatLngDict) -> ImagePixelCoordinates:
16
  from math import log, pi, sin
 
1
  """functions useful to convert to/from latitude-longitude coordinates to pixel image coordinates"""
 
 
2
  from lisa_on_cuda.utils import session_logger
3
  from samgis_core.utilities.type_hints import TupleFloat, TupleFloatAny
4
+ from samgis_lisa_on_zero import app_logger
5
  from samgis_lisa_on_zero.utilities.constants import TILE_SIZE, EARTH_EQUATORIAL_RADIUS
6
  from samgis_lisa_on_zero.utilities.type_hints import ImagePixelCoordinates
7
  from samgis_lisa_on_zero.utilities.type_hints import LatLngDict
8
 
9
 
 
 
 
10
  @session_logger.set_uuid_logging
11
  def _get_latlng2pixel_projection(latlng: LatLngDict) -> ImagePixelCoordinates:
12
  from math import log, pi, sin
samgis_lisa_on_zero/io_package/geo_helpers.py CHANGED
@@ -1,14 +1,11 @@
1
  """handle geo-referenced raster images"""
2
- import logging
3
 
4
  from affine import Affine
 
5
  from numpy import ndarray as np_ndarray
6
 
7
- from lisa_on_cuda.utils import session_logger
8
  from samgis_core.utilities.type_hints import ListFloat, TupleFloat, DictStrInt
9
-
10
-
11
- app_logger = logging.getLogger(__name__)
12
 
13
 
14
  @session_logger.set_uuid_logging
 
1
  """handle geo-referenced raster images"""
 
2
 
3
  from affine import Affine
4
+ from lisa_on_cuda.utils import session_logger
5
  from numpy import ndarray as np_ndarray
6
 
 
7
  from samgis_core.utilities.type_hints import ListFloat, TupleFloat, DictStrInt
8
+ from samgis_lisa_on_zero import app_logger
 
 
9
 
10
 
11
  @session_logger.set_uuid_logging
samgis_lisa_on_zero/io_package/raster_helpers.py CHANGED
@@ -9,8 +9,7 @@ from lisa_on_cuda.utils import session_logger
9
  from samgis_lisa_on_zero.utilities.constants import OUTPUT_CRS_STRING
10
  from samgis_lisa_on_zero.utilities.type_hints import XYZTerrainProvidersNames
11
 
12
-
13
- app_logger = logging.getLogger(__name__)
14
 
15
 
16
  def get_nextzen_terrain_rgb_formula(red: ndarray, green: ndarray, blue: ndarray) -> ndarray:
 
9
  from samgis_lisa_on_zero.utilities.constants import OUTPUT_CRS_STRING
10
  from samgis_lisa_on_zero.utilities.type_hints import XYZTerrainProvidersNames
11
 
12
+ from samgis_lisa_on_zero import app_logger
 
13
 
14
 
15
  def get_nextzen_terrain_rgb_formula(red: ndarray, green: ndarray, blue: ndarray) -> ndarray:
samgis_lisa_on_zero/io_package/tms2geotiff.py CHANGED
@@ -1,18 +1,17 @@
1
- import logging
2
  import os
3
 
 
4
  from numpy import ndarray
5
  from samgis_core.utilities.type_hints import TupleFloat
6
  from xyzservices import TileProvider
7
 
8
- from lisa_on_cuda.utils import session_logger
9
  from samgis_lisa_on_zero.utilities.constants import (OUTPUT_CRS_STRING, DRIVER_RASTERIO_GTIFF, N_MAX_RETRIES,
10
  N_CONNECTION, N_WAIT,
11
  ZOOM_AUTO, BOOL_USE_CACHE)
12
  from samgis_lisa_on_zero.utilities.type_hints import tuple_ndarray_transform
13
 
14
 
15
- app_logger = logging.getLogger(__name__)
16
  bool_use_cache = int(os.getenv("BOOL_USE_CACHE", BOOL_USE_CACHE))
17
  n_connection = int(os.getenv("N_CONNECTION", N_CONNECTION))
18
  n_max_retries = int(os.getenv("N_MAX_RETRIES", N_MAX_RETRIES))
 
 
1
  import os
2
 
3
+ from lisa_on_cuda.utils import session_logger
4
  from numpy import ndarray
5
  from samgis_core.utilities.type_hints import TupleFloat
6
  from xyzservices import TileProvider
7
 
8
+ from samgis_lisa_on_zero import app_logger
9
  from samgis_lisa_on_zero.utilities.constants import (OUTPUT_CRS_STRING, DRIVER_RASTERIO_GTIFF, N_MAX_RETRIES,
10
  N_CONNECTION, N_WAIT,
11
  ZOOM_AUTO, BOOL_USE_CACHE)
12
  from samgis_lisa_on_zero.utilities.type_hints import tuple_ndarray_transform
13
 
14
 
 
15
  bool_use_cache = int(os.getenv("BOOL_USE_CACHE", BOOL_USE_CACHE))
16
  n_connection = int(os.getenv("N_CONNECTION", N_CONNECTION))
17
  n_max_retries = int(os.getenv("N_MAX_RETRIES", N_MAX_RETRIES))
samgis_lisa_on_zero/io_package/wrappers_helpers.py CHANGED
@@ -1,20 +1,17 @@
1
  """lambda helper functions"""
2
- import logging
3
  from typing import Dict
4
 
5
- from xyzservices import providers, TileProvider
6
-
7
  from lisa_on_cuda.utils import session_logger
8
  from lisa_on_cuda.utils.app_helpers import get_cleaned_input
 
 
 
9
  from samgis_lisa_on_zero.io_package.coordinates_pixel_conversion import get_latlng_to_pixel_coordinates
10
  from samgis_lisa_on_zero.utilities.constants import COMPLETE_URL_TILES_MAPBOX, COMPLETE_URL_TILES_NEXTZEN
11
  from samgis_lisa_on_zero.utilities.type_hints import (
12
  ApiRequestBody, XYZTerrainProvidersNames, XYZDefaultProvidersNames, StringPromptApiRequestBody)
13
 
14
 
15
- app_logger = logging.getLogger(__name__)
16
-
17
-
18
  @session_logger.set_uuid_logging
19
  def get_parsed_bbox_points_with_string_prompt(request_input: StringPromptApiRequestBody) -> Dict:
20
  """
 
1
  """lambda helper functions"""
 
2
  from typing import Dict
3
 
 
 
4
  from lisa_on_cuda.utils import session_logger
5
  from lisa_on_cuda.utils.app_helpers import get_cleaned_input
6
+ from xyzservices import providers, TileProvider
7
+
8
+ from samgis_lisa_on_zero import app_logger
9
  from samgis_lisa_on_zero.io_package.coordinates_pixel_conversion import get_latlng_to_pixel_coordinates
10
  from samgis_lisa_on_zero.utilities.constants import COMPLETE_URL_TILES_MAPBOX, COMPLETE_URL_TILES_NEXTZEN
11
  from samgis_lisa_on_zero.utilities.type_hints import (
12
  ApiRequestBody, XYZTerrainProvidersNames, XYZDefaultProvidersNames, StringPromptApiRequestBody)
13
 
14
 
 
 
 
15
  @session_logger.set_uuid_logging
16
  def get_parsed_bbox_points_with_string_prompt(request_input: StringPromptApiRequestBody) -> Dict:
17
  """
samgis_lisa_on_zero/prediction_api/lisa.py CHANGED
@@ -1,18 +1,16 @@
1
- import logging
2
  from datetime import datetime
3
 
4
  from lisa_on_cuda.utils import session_logger
5
  from samgis_core.utilities.type_hints import LlistFloat, DictStrInt
6
  from spaces import GPU as SPACES_GPU
7
 
 
8
  from samgis_lisa_on_zero.io_package.geo_helpers import get_vectorized_raster_as_geojson
9
  from samgis_lisa_on_zero.io_package.raster_helpers import write_raster_png, write_raster_tiff
10
  from samgis_lisa_on_zero.io_package.tms2geotiff import download_extent
11
  from samgis_lisa_on_zero.utilities.constants import DEFAULT_URL_TILES, LISA_INFERENCE_FN
12
 
13
-
14
  msg_write_tmp_on_disk = "found option to write images and geojson output..."
15
- app_logger = logging.getLogger(__name__)
16
 
17
 
18
  @session_logger.set_uuid_logging
 
 
1
  from datetime import datetime
2
 
3
  from lisa_on_cuda.utils import session_logger
4
  from samgis_core.utilities.type_hints import LlistFloat, DictStrInt
5
  from spaces import GPU as SPACES_GPU
6
 
7
+ from samgis_lisa_on_zero import app_logger
8
  from samgis_lisa_on_zero.io_package.geo_helpers import get_vectorized_raster_as_geojson
9
  from samgis_lisa_on_zero.io_package.raster_helpers import write_raster_png, write_raster_tiff
10
  from samgis_lisa_on_zero.io_package.tms2geotiff import download_extent
11
  from samgis_lisa_on_zero.utilities.constants import DEFAULT_URL_TILES, LISA_INFERENCE_FN
12
 
 
13
  msg_write_tmp_on_disk = "found option to write images and geojson output..."
 
14
 
15
 
16
  @session_logger.set_uuid_logging
samgis_lisa_on_zero/prediction_api/predictors.py CHANGED
@@ -1,5 +1,4 @@
1
  """functions using machine learning instance model(s)"""
2
- import logging
3
 
4
  from lisa_on_cuda.utils import session_logger
5
  from samgis_core.prediction_api import sam_onnx2, sam_onnx_inference
@@ -7,6 +6,7 @@ from samgis_core.utilities.constants import MODEL_ENCODER_NAME, MODEL_DECODER_NA
7
  from samgis_core.utilities.type_hints import LlistFloat, DictStrInt, ListDict
8
 
9
  from samgis_lisa_on_zero import MODEL_FOLDER
 
10
  from samgis_lisa_on_zero.io_package.geo_helpers import get_vectorized_raster_as_geojson
11
  from samgis_lisa_on_zero.io_package.raster_helpers import get_raster_terrain_rgb_like, get_rgb_prediction_image
12
  from samgis_lisa_on_zero.io_package.tms2geotiff import download_extent
@@ -14,8 +14,6 @@ from samgis_lisa_on_zero.io_package.wrappers_helpers import check_source_type_is
14
  from samgis_lisa_on_zero.prediction_api.global_models import models_dict, embedding_dict
15
  from samgis_lisa_on_zero.utilities.constants import DEFAULT_URL_TILES, SLOPE_CELLSIZE
16
 
17
- app_logger = logging.getLogger(__name__)
18
-
19
 
20
  @session_logger.set_uuid_logging
21
  def samexporter_predict(
 
1
  """functions using machine learning instance model(s)"""
 
2
 
3
  from lisa_on_cuda.utils import session_logger
4
  from samgis_core.prediction_api import sam_onnx2, sam_onnx_inference
 
6
  from samgis_core.utilities.type_hints import LlistFloat, DictStrInt, ListDict
7
 
8
  from samgis_lisa_on_zero import MODEL_FOLDER
9
+ from samgis_lisa_on_zero import app_logger
10
  from samgis_lisa_on_zero.io_package.geo_helpers import get_vectorized_raster_as_geojson
11
  from samgis_lisa_on_zero.io_package.raster_helpers import get_raster_terrain_rgb_like, get_rgb_prediction_image
12
  from samgis_lisa_on_zero.io_package.tms2geotiff import download_extent
 
14
  from samgis_lisa_on_zero.prediction_api.global_models import models_dict, embedding_dict
15
  from samgis_lisa_on_zero.utilities.constants import DEFAULT_URL_TILES, SLOPE_CELLSIZE
16
 
 
 
17
 
18
  @session_logger.set_uuid_logging
19
  def samexporter_predict(